hide when not subscribed

This commit is contained in:
Bnyro 2022-11-06 11:30:38 +01:00
parent 861e319aeb
commit d18e0dfc1f
3 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package com.github.libretube.ui.adapters package com.github.libretube.ui.adapters
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
@ -30,7 +31,7 @@ class SubscriptionChannelAdapter(
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) { override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
val subscription = subscriptions[position] val subscription = subscriptions[position]
var subscribed = true var isSubscribed = true
holder.binding.apply { holder.binding.apply {
subscriptionChannelName.text = subscription.name subscriptionChannelName.text = subscription.name
@ -43,15 +44,17 @@ class SubscriptionChannelAdapter(
} }
subscriptionSubscribe.setOnClickListener { subscriptionSubscribe.setOnClickListener {
val channelId = subscription.url!!.toID() val channelId = subscription.url!!.toID()
if (subscribed) { if (isSubscribed) {
SubscriptionHelper.handleUnsubscribe(root.context, channelId, subscription.name ?: "") { SubscriptionHelper.handleUnsubscribe(root.context, channelId, subscription.name ?: "") {
subscriptionSubscribe.text = root.context.getString(R.string.subscribe) subscriptionSubscribe.text = root.context.getString(R.string.subscribe)
subscribed = false notificationBell.visibility = View.GONE
isSubscribed = false
} }
} else { } else {
SubscriptionHelper.subscribe(channelId) SubscriptionHelper.subscribe(channelId)
subscriptionSubscribe.text = root.context.getString(R.string.unsubscribe) subscriptionSubscribe.text = root.context.getString(R.string.unsubscribe)
subscribed = true notificationBell.visibility = View.VISIBLE
isSubscribed = true
} }
} }
} }

View File

@ -130,17 +130,20 @@ class ChannelFragment : BaseFragment() {
} }
channelId?.let { binding.notificationBell.setupNotificationBell(it) } channelId?.let { binding.notificationBell.setupNotificationBell(it) }
if (isSubscribed == false) binding.notificationBell.visibility = View.GONE
binding.channelSubscribe.setOnClickListener { binding.channelSubscribe.setOnClickListener {
if (isSubscribed == true) { if (isSubscribed == true) {
SubscriptionHelper.handleUnsubscribe(requireContext(), channelId!!, channelName) { SubscriptionHelper.handleUnsubscribe(requireContext(), channelId!!, channelName) {
isSubscribed = false isSubscribed = false
binding.channelSubscribe.text = getString(R.string.subscribe) binding.channelSubscribe.text = getString(R.string.subscribe)
binding.notificationBell.visibility = View.GONE
} }
} else { } else {
SubscriptionHelper.subscribe(channelId!!) SubscriptionHelper.subscribe(channelId!!)
isSubscribed = true isSubscribed = true
binding.channelSubscribe.text = getString(R.string.unsubscribe) binding.channelSubscribe.text = getString(R.string.unsubscribe)
binding.notificationBell.visibility = View.VISIBLE
} }
} }

View File

@ -63,14 +63,15 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start" android:layout_gravity="start"
android:maxLines="1"
android:text="@string/app_name" android:text="@string/app_name"
android:textSize="12sp" /> android:textSize="12sp" />
</LinearLayout> </LinearLayout>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/ElevatedIconButton"
android:id="@+id/channel_share" android:id="@+id/channel_share"
style="@style/ElevatedIconButton"
app:icon="@drawable/ic_share" app:icon="@drawable/ic_share"
tools:targetApi="m" /> tools:targetApi="m" />