Skip to content

Commit 14f2b3b

Browse files
dhanuarfBnyro
authored andcommitted
fix: subscriptions button reset its state when scrolling
Fix subscriptions button in `SubscriptionsBottomSheet`'s channel list reset its state on scroll when the channel is unsubscribed.
1 parent b4b95e6 commit 14f2b3b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

app/src/main/java/com/github/libretube/ui/adapters/SubscriptionChannelAdapter.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import com.github.libretube.ui.viewholders.SubscriptionChannelViewHolder
2020
class 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
}

0 commit comments

Comments
 (0)