feat: show subscribed channels count in subscriptions fragment

This commit is contained in:
Bnyro 2023-08-06 11:34:17 +02:00
parent c253a4e415
commit 179c283b8e
2 changed files with 11 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SubscriptionGroup import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.extensions.dpToPx import com.github.libretube.extensions.dpToPx
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.adapters.LegacySubscriptionAdapter import com.github.libretube.ui.adapters.LegacySubscriptionAdapter
@ -210,10 +211,10 @@ class SubscriptionsFragment : Fragment() {
} }
private fun showFeed() { private fun showFeed() {
if (viewModel.videoFeed.value == null) return val videoFeed = viewModel.videoFeed.value ?: return
binding.subRefresh.isRefreshing = false binding.subRefresh.isRefreshing = false
val feed = viewModel.videoFeed.value!! val feed = videoFeed
.filter { streamItem -> .filter { streamItem ->
// filter for selected channel groups // filter for selected channel groups
if (selectedFilterGroup == 0) { if (selectedFilterGroup == 0) {
@ -287,8 +288,9 @@ class SubscriptionsFragment : Fragment() {
PreferenceHelper.updateLastFeedWatchedTime() PreferenceHelper.updateLastFeedWatchedTime()
} }
@SuppressLint("SetTextI18n")
private fun showSubscriptions() { private fun showSubscriptions() {
if (viewModel.subscriptions.value == null) return val subscriptions = viewModel.subscriptions.value ?: return
val legacySubscriptions = PreferenceHelper.getBoolean( val legacySubscriptions = PreferenceHelper.getBoolean(
PreferenceKeys.LEGACY_SUBSCRIPTIONS, PreferenceKeys.LEGACY_SUBSCRIPTIONS,
@ -303,10 +305,10 @@ class SubscriptionsFragment : Fragment() {
"4" "4"
).toInt() ).toInt()
) )
binding.subChannels.adapter = LegacySubscriptionAdapter(viewModel.subscriptions.value!!) binding.subChannels.adapter = LegacySubscriptionAdapter(subscriptions)
} else { } else {
binding.subChannels.layoutManager = LinearLayoutManager(context) binding.subChannels.layoutManager = LinearLayoutManager(context)
binding.subChannels.adapter = SubscriptionChannelAdapter(viewModel.subscriptions.value!!.toMutableList()) binding.subChannels.adapter = SubscriptionChannelAdapter(subscriptions.toMutableList())
} }
binding.subRefresh.isRefreshing = false binding.subRefresh.isRefreshing = false
@ -316,5 +318,8 @@ class SubscriptionsFragment : Fragment() {
val notLoaded = viewModel.subscriptions.value.isNullOrEmpty() val notLoaded = viewModel.subscriptions.value.isNullOrEmpty()
binding.subChannelsContainer.isGone = notLoaded binding.subChannelsContainer.isGone = notLoaded
binding.emptyFeed.isVisible = notLoaded binding.emptyFeed.isVisible = notLoaded
val subCount = subscriptions.size.toLong().formatShort()
binding.toggleSubsText.text = "${getString(R.string.subscriptions)} ($subCount)"
} }
} }

View File

@ -67,6 +67,7 @@
app:cardCornerRadius="18dp"> app:cardCornerRadius="18dp">
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/toggle_subs_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_margin="8dp"