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 4973b22ca..b60326b08 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 @@ -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) { 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 dccb4237a..000000000 --- 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 diff --git a/app/src/main/res/layout/fragment_watch_history.xml b/app/src/main/res/layout/fragment_watch_history.xml index 69aac96aa..2efec9a40 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">