File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
app/src/main/java/com/github/libretube/ui/adapters Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ import com.github.libretube.ui.viewholders.SubscriptionChannelViewHolder
2020class SubscriptionChannelAdapter :
2121 ListAdapter <Subscription , SubscriptionChannelViewHolder >(DiffUtilItemCallback ()) {
2222
23+ // Track recently unsubscribed channels to preserve their unsubscribed state when
24+ // [onBindViewHolder] is re-called on these channels while scrolling the [RecyclerView]
25+ private val recentlyUnsubscribedList = mutableListOf<String >()
26+
2327 override fun onCreateViewHolder (
2428 parent : ViewGroup ,
2529 viewType : Int
@@ -51,14 +55,21 @@ class SubscriptionChannelAdapter :
5155 true
5256 }
5357
58+ val channelId = subscription.url.toID()
59+ val isRecentlyUnsubscribed = recentlyUnsubscribedList.any { it == channelId }
5460 subscriptionSubscribe.setupSubscriptionButton(
55- subscription.url.toID() ,
61+ channelId ,
5662 subscription.name,
5763 subscription.avatar,
5864 subscription.verified,
5965 notificationBell,
60- true
61- )
66+ ! isRecentlyUnsubscribed
67+ ) { isSubscribed ->
68+ when (isSubscribed) {
69+ true -> if (isRecentlyUnsubscribed) recentlyUnsubscribedList.remove(channelId)
70+ false -> if (! isRecentlyUnsubscribed) recentlyUnsubscribedList.add(channelId)
71+ }
72+ }
6273 }
6374 }
6475}
You can’t perform that action at this time.
0 commit comments