From f3eab0484bc34adb2a1249e99f5b558ee5fcacb3 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 28 Dec 2022 16:46:57 +0100 Subject: [PATCH 1/2] Add shorts filter to the feed --- .../ui/fragments/SubscriptionsFragment.kt | 53 ++++++++++++------- .../res/layout/fragment_subscriptions.xml | 37 +++++++++---- app/src/main/res/values/array.xml | 6 +++ 3 files changed, 67 insertions(+), 29 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 5536fec9c..27bed0a4d 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 @@ -26,7 +26,8 @@ class SubscriptionsFragment : BaseFragment() { private val viewModel: SubscriptionsViewModel by activityViewModels() private var subscriptionAdapter: VideosAdapter? = null - private var sortOrder = 0 + private var selectedSortOrder = 0 + private var selectedFilter = 0 override fun onCreateView( inflater: LayoutInflater, @@ -82,7 +83,27 @@ class SubscriptionsFragment : BaseFragment() { } binding.sortTV.setOnClickListener { - showSortDialog() + val sortOptions = resources.getStringArray(R.array.sortOptions) + + BaseBottomSheet().apply { + setSimpleItems(sortOptions.toList()) { index -> + binding.sortTV.text = sortOptions[index] + selectedSortOrder = index + showFeed() + } + }.show(childFragmentManager) + } + + binding.filterTV.setOnClickListener { + val filterOptions = resources.getStringArray(R.array.filterOptions) + + BaseBottomSheet().apply { + setSimpleItems(filterOptions.toList()) { index -> + binding.filterTV.text = filterOptions[index] + selectedFilter = index + showFeed() + } + }.show(childFragmentManager) } binding.toggleSubs.visibility = View.VISIBLE @@ -117,27 +138,21 @@ class SubscriptionsFragment : BaseFragment() { } } - private fun showSortDialog() { - val sortOptions = resources.getStringArray(R.array.sortOptions) - - val bottomSheet = BaseBottomSheet().apply { - setSimpleItems(sortOptions.toList()) { index -> - binding.sortTV.text = sortOptions[index] - sortOrder = index - showFeed() - } - } - - bottomSheet.show(childFragmentManager, null) - } - private fun showFeed() { if (viewModel.videoFeed.value == null) return binding.subRefresh.isRefreshing = false - val feed = viewModel.videoFeed.value!! + val feed = viewModel.videoFeed.value!!.filter { + // apply the selected filter + when (selectedFilter) { + 0 -> true + 1 -> !it.isShort + 2 -> it.isShort + else -> throw IllegalArgumentException() + } + } // sort the feed - val sortedFeed = when (sortOrder) { + val sortedFeed = when (selectedSortOrder) { 0 -> feed 1 -> feed.reversed() 2 -> feed.sortedBy { it.views }.reversed() @@ -148,7 +163,7 @@ class SubscriptionsFragment : BaseFragment() { }.toMutableList() // add an "all caught up item" - if (sortOrder == 0) { + if (selectedSortOrder == 0) { val lastCheckedFeedTime = PreferenceHelper.getLastCheckedFeedTime() val caughtUpIndex = feed.indexOfFirst { (it.uploaded ?: 0L) / 1000 < lastCheckedFeedTime diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index fd3d594a9..8dddbdbb0 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -114,17 +114,34 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_marginBottom="5dp"> + + + + + + @string/channel_name_za + + @string/all + @string/videos + @string/yt_shorts + + @string/network_all @string/network_wifi From 8b39c9924da5b3509f4d62cdc51664f91c2b5865 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 28 Dec 2022 16:49:24 +0100 Subject: [PATCH 2/2] Increase the start padding of the filter text view --- app/src/main/res/layout/fragment_subscriptions.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index 8dddbdbb0..94ed78fbd 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -124,6 +124,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="start" + android:layout_marginStart="5dp" android:drawablePadding="5dp" android:paddingHorizontal="10dp" android:text="@string/all"