From f76da904474645ff6eb66af3837ac8109aaf56d5 Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Mon, 28 Nov 2022 20:12:00 +0530 Subject: [PATCH 1/2] Fix wrong history deleted because of different thread --- .../com/github/libretube/ui/adapters/WatchHistoryAdapter.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt index efbb50faa..1c3aa6c4e 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt @@ -21,8 +21,9 @@ class WatchHistoryAdapter( RecyclerView.Adapter() { fun removeFromWatchHistory(position: Int) { + val history = watchHistory[position] query { - DatabaseHolder.Database.watchHistoryDao().delete(watchHistory[position]) + DatabaseHolder.Database.watchHistoryDao().delete(history) } watchHistory.removeAt(position) notifyItemRemoved(position) From 7d878476d164c7bb1c850e5b8d0b64e372e10714 Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Mon, 28 Nov 2022 20:21:00 +0530 Subject: [PATCH 2/2] Fix empty history view when all history is removed `onChanged()` is trigered when `notifyDataSetChanged()` is called. Since `notifyItemRemoved(Int)` is used override `onItemRangeRemoved()`. --- .../com/github/libretube/ui/fragments/WatchHistoryFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69a06d390..a74fed717 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 @@ -89,7 +89,7 @@ class WatchHistoryFragment : BaseFragment() { // observe changes watchHistoryAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { - override fun onChanged() { + override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { if (watchHistoryAdapter.itemCount == 0) { binding.watchHistoryRecView.visibility = View.GONE binding.historyEmpty.visibility = View.VISIBLE