Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also disable the clear history button here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I don't think so, since the clear button removes all items, and not just the visible ones. I guess it should rather be disabled, if the overall history is empty and not just the filtered one?

binding.watchHistoryRecView.isVisible = history.isNotEmpty()

watchHistoryAdapter.submitList(history)
}
Expand All @@ -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) {
Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions app/src/main/res/layout/fragment_watch_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading