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
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
@ -30,7 +31,7 @@ class SubscriptionChannelAdapter(
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
val subscription = subscriptions[position]
var subscribed = true
var isSubscribed = true
holder.binding.apply {
subscriptionChannelName.text = subscription.name
@ -43,15 +44,17 @@ class SubscriptionChannelAdapter(
}
subscriptionSubscribe.setOnClickListener {
val channelId = subscription.url!!.toID()
if (subscribed) {
if (isSubscribed) {
SubscriptionHelper.handleUnsubscribe(root.context, channelId, subscription.name ?: "") {
subscriptionSubscribe.text = root.context.getString(R.string.subscribe)
subscribed = false
notificationBell.visibility = View.GONE
isSubscribed = false
}
} else {
SubscriptionHelper.subscribe(channelId)
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) }
if (isSubscribed == false) binding.notificationBell.visibility = View.GONE
binding.channelSubscribe.setOnClickListener {
if (isSubscribed == true) {
SubscriptionHelper.handleUnsubscribe(requireContext(), channelId!!, channelName) {
isSubscribed = false
binding.channelSubscribe.text = getString(R.string.subscribe)
binding.notificationBell.visibility = View.GONE
}
} else {
SubscriptionHelper.subscribe(channelId!!)
isSubscribed = true
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_height="wrap_content"
android:layout_gravity="start"
android:maxLines="1"
android:text="@string/app_name"
android:textSize="12sp" />
</LinearLayout>
<com.google.android.material.button.MaterialButton
style="@style/ElevatedIconButton"
android:id="@+id/channel_share"
style="@style/ElevatedIconButton"
app:icon="@drawable/ic_share"
tools:targetApi="m" />