Skip to content

Commit 53a76d2

Browse files
authored
fix(WatchHistory): always show filter bar (libre-tube#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
1 parent 9140b61 commit 53a76d2

3 files changed

Lines changed: 16 additions & 28 deletions

File tree

app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import com.github.libretube.ui.models.WatchHistoryModel
3131
import com.github.libretube.ui.sheets.BaseBottomSheet
3232
import com.github.libretube.util.PlayingQueue
3333
import com.google.android.material.dialog.MaterialAlertDialogBuilder
34+
import kotlinx.coroutines.CoroutineScope
3435
import kotlinx.coroutines.Dispatchers
3536
import kotlinx.coroutines.launch
37+
import kotlinx.coroutines.withContext
3638

3739
class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watch_history) {
3840
private var _binding: FragmentWatchHistoryBinding? = null
@@ -67,7 +69,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
6769
RecyclerView.AdapterDataObserver() {
6870
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
6971
if (watchHistoryAdapter.itemCount == 0) {
70-
binding.historyContainer.isGone = true
72+
binding.watchHistoryRecView.isGone = true
7173
binding.historyEmpty.isVisible = true
7274
}
7375
}
@@ -98,7 +100,7 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
98100
selected[index] = newValue
99101
}
100102
.setPositiveButton(R.string.okay) { _, _ ->
101-
binding.historyContainer.isGone = true
103+
binding.watchHistoryRecView.isGone = true
102104
binding.historyEmpty.isVisible = true
103105
lifecycleScope.launch(Dispatchers.IO) {
104106
Database.withTransaction {
@@ -149,7 +151,8 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
149151

150152
viewModel.filteredWatchHistory.observe(viewLifecycleOwner) { history ->
151153
binding.historyEmpty.isGone = history.isNotEmpty()
152-
binding.historyContainer.isVisible = history.isNotEmpty()
154+
binding.playAll.isEnabled = history.isNotEmpty()
155+
binding.watchHistoryRecView.isVisible = history.isNotEmpty()
153156

154157
watchHistoryAdapter.submitList(history)
155158
}
@@ -163,6 +166,15 @@ class WatchHistoryFragment : DynamicLayoutManagerFragment(R.layout.fragment_watc
163166
if (NavBarHelper.getStartFragmentId(requireContext()) != R.id.watchHistoryFragment) {
164167
setupFragmentAnimation(binding.root)
165168
}
169+
170+
CoroutineScope(Dispatchers.IO).launch {
171+
val hasItems = Database.watchHistoryDao().getSize() != 0
172+
173+
withContext(Dispatchers.Main) {
174+
binding.clear.isEnabled = hasItems
175+
}
176+
}
177+
166178
}
167179

168180
override fun onConfigurationChanged(newConfig: Configuration) {

app/src/main/java/com/github/libretube/ui/models/sources/WatchHistoryPagingSource.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/src/main/res/layout/fragment_watch_history.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
</LinearLayout>
3030

3131
<androidx.coordinatorlayout.widget.CoordinatorLayout
32-
android:id="@+id/historyContainer"
3332
android:layout_width="match_parent"
3433
android:layout_height="wrap_content"
35-
android:scrollbars="vertical"
36-
android:visibility="gone">
34+
android:scrollbars="vertical">
3735

3836
<com.google.android.material.appbar.AppBarLayout
3937
android:id="@+id/watch_history_app_bar"

0 commit comments

Comments
 (0)