fix(WatchHistory): always show filter bar (#7258)

* 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.

* feat(WatchHistory): disable 'Play all' if history is empty

* feat(WatchHistory): disable clear button, if history is empty
This commit is contained in:
FineFindus 2025-03-31 16:30:22 +02:00 committed by GitHub
parent 9140b6133c
commit 53a76d2bc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 28 deletions

View File

@ -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
@ -67,7 +69,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 +100,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 +151,8 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
viewModel.filteredWatchHistory.observe(viewLifecycleOwner) { history ->
binding.historyEmpty.isGone = history.isNotEmpty()
binding.historyContainer.isVisible = history.isNotEmpty()
binding.playAll.isEnabled = history.isNotEmpty()
binding.watchHistoryRecView.isVisible = history.isNotEmpty()
watchHistoryAdapter.submitList(history)
}
@ -163,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) {

View File

@ -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<Int, WatchHistoryItem>() {
override fun getRefreshKey(state: PagingState<Int, WatchHistoryItem>) = null
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, WatchHistoryItem> {
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)
}
}

View File

@ -29,11 +29,9 @@
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/historyContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:visibility="gone">
android:scrollbars="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/watch_history_app_bar"