From 179c283b8efe0e60f0b9a2e6bc629e8c02eb367a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 6 Aug 2023 11:34:17 +0200 Subject: [PATCH] feat: show subscribed channels count in subscriptions fragment --- .../ui/fragments/SubscriptionsFragment.kt | 15 ++++++++++----- .../main/res/layout/fragment_subscriptions.xml | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index abc5d22f3..64ea7e50b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -23,6 +23,7 @@ import com.github.libretube.db.DatabaseHelper import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.obj.SubscriptionGroup import com.github.libretube.extensions.dpToPx +import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.toID import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.ui.adapters.LegacySubscriptionAdapter @@ -210,10 +211,10 @@ class SubscriptionsFragment : Fragment() { } private fun showFeed() { - if (viewModel.videoFeed.value == null) return + val videoFeed = viewModel.videoFeed.value ?: return binding.subRefresh.isRefreshing = false - val feed = viewModel.videoFeed.value!! + val feed = videoFeed .filter { streamItem -> // filter for selected channel groups if (selectedFilterGroup == 0) { @@ -287,8 +288,9 @@ class SubscriptionsFragment : Fragment() { PreferenceHelper.updateLastFeedWatchedTime() } + @SuppressLint("SetTextI18n") private fun showSubscriptions() { - if (viewModel.subscriptions.value == null) return + val subscriptions = viewModel.subscriptions.value ?: return val legacySubscriptions = PreferenceHelper.getBoolean( PreferenceKeys.LEGACY_SUBSCRIPTIONS, @@ -303,10 +305,10 @@ class SubscriptionsFragment : Fragment() { "4" ).toInt() ) - binding.subChannels.adapter = LegacySubscriptionAdapter(viewModel.subscriptions.value!!) + binding.subChannels.adapter = LegacySubscriptionAdapter(subscriptions) } else { binding.subChannels.layoutManager = LinearLayoutManager(context) - binding.subChannels.adapter = SubscriptionChannelAdapter(viewModel.subscriptions.value!!.toMutableList()) + binding.subChannels.adapter = SubscriptionChannelAdapter(subscriptions.toMutableList()) } binding.subRefresh.isRefreshing = false @@ -316,5 +318,8 @@ class SubscriptionsFragment : Fragment() { val notLoaded = viewModel.subscriptions.value.isNullOrEmpty() binding.subChannelsContainer.isGone = notLoaded binding.emptyFeed.isVisible = notLoaded + + val subCount = subscriptions.size.toLong().formatShort() + binding.toggleSubsText.text = "${getString(R.string.subscriptions)} ($subCount)" } } diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index 4ea08a922..399ba9db4 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -67,6 +67,7 @@ app:cardCornerRadius="18dp">