From 1bfe2871d8c58d1684d2fee264d6cd1ae3251c4d Mon Sep 17 00:00:00 2001 From: FineFindus Date: Mon, 31 Mar 2025 15:17:16 +0200 Subject: [PATCH 1/3] fix(WatchHistory): always show filter bar Fixes an issue, where the users could get soft-locked, by selecting a filter, which had no items, leading to the filter bar being hidden, and thus making the user unable to deselect the filter. This is fixed, by only hiding recyclerView/No items views. --- .../github/libretube/ui/fragments/WatchHistoryFragment.kt | 6 +++--- app/src/main/res/layout/fragment_watch_history.xml | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index 4973b22ca1..089dd68883 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -67,7 +67,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc RecyclerView.AdapterDataObserver() { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { if (watchHistoryAdapter.itemCount == 0) { - binding.historyContainer.isGone = true + binding.watchHistoryRecView.isGone = true binding.historyEmpty.isVisible = true } } @@ -98,7 +98,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc selected[index] = newValue } .setPositiveButton(R.string.okay) { _, _ -> - binding.historyContainer.isGone = true + binding.watchHistoryRecView.isGone = true binding.historyEmpty.isVisible = true lifecycleScope.launch(Dispatchers.IO) { Database.withTransaction { @@ -149,7 +149,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc viewModel.filteredWatchHistory.observe(viewLifecycleOwner) { history -> binding.historyEmpty.isGone = history.isNotEmpty() - binding.historyContainer.isVisible = history.isNotEmpty() + binding.watchHistoryRecView.isVisible = history.isNotEmpty() watchHistoryAdapter.submitList(history) } diff --git a/app/src/main/res/layout/fragment_watch_history.xml b/app/src/main/res/layout/fragment_watch_history.xml index 69aac96aae..2efec9a40b 100644 --- a/app/src/main/res/layout/fragment_watch_history.xml +++ b/app/src/main/res/layout/fragment_watch_history.xml @@ -29,11 +29,9 @@ + android:scrollbars="vertical"> Date: Mon, 31 Mar 2025 15:24:44 +0200 Subject: [PATCH 2/3] feat(WatchHistory): disable 'Play all' if history is empty --- .../com/github/libretube/ui/fragments/WatchHistoryFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index 089dd68883..bf7814452f 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -149,6 +149,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc viewModel.filteredWatchHistory.observe(viewLifecycleOwner) { history -> binding.historyEmpty.isGone = history.isNotEmpty() + binding.playAll.isEnabled = history.isNotEmpty() binding.watchHistoryRecView.isVisible = history.isNotEmpty() watchHistoryAdapter.submitList(history) From 981b0371e711dc51665c9e28262e897f54cf0fd3 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Mon, 31 Mar 2025 16:13:41 +0200 Subject: [PATCH 3/3] feat(WatchHistory): disable clear button, if history is empty --- .../ui/fragments/WatchHistoryFragment.kt | 11 ++++++++++ .../sources/WatchHistoryPagingSource.kt | 22 ------------------- 2 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 app/src/main/java/com/github/libretube/ui/models/sources/WatchHistoryPagingSource.kt diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index bf7814452f..b60326b08b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -31,8 +31,10 @@ import com.github.libretube.ui.models.WatchHistoryModel import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.util.PlayingQueue import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watch_history) { private var _binding: FragmentWatchHistoryBinding? = null @@ -164,6 +166,15 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc if (NavBarHelper.getStartFragmentId(requireContext()) != R.id.watchHistoryFragment) { setupFragmentAnimation(binding.root) } + + CoroutineScope(Dispatchers.IO).launch { + val hasItems = Database.watchHistoryDao().getSize() != 0 + + withContext(Dispatchers.Main) { + binding.clear.isEnabled = hasItems + } + } + } override fun onConfigurationChanged(newConfig: Configuration) { diff --git a/app/src/main/java/com/github/libretube/ui/models/sources/WatchHistoryPagingSource.kt b/app/src/main/java/com/github/libretube/ui/models/sources/WatchHistoryPagingSource.kt deleted file mode 100644 index dccb4237a8..0000000000 --- a/app/src/main/java/com/github/libretube/ui/models/sources/WatchHistoryPagingSource.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.libretube.ui.models.sources - -import androidx.paging.PagingSource -import androidx.paging.PagingState -import com.github.libretube.db.DatabaseHelper -import com.github.libretube.db.obj.WatchHistoryItem -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext - -class WatchHistoryPagingSource( - private val shouldIncludeItemPredicate: suspend (WatchHistoryItem) -> Boolean -): PagingSource() { - override fun getRefreshKey(state: PagingState) = null - - override suspend fun load(params: LoadParams): LoadResult { - val newHistory = withContext(Dispatchers.IO) { - DatabaseHelper.getWatchHistoryPage( params.key ?: 0, params.loadSize) - }.filter { shouldIncludeItemPredicate(it) } - - return LoadResult.Page(newHistory, params.key ?: 0, params.key?.plus(1) ?: 0) - } -} \ No newline at end of file