Merge pull request #2134 from Kruna1Pate1/fix/watch-history

Fix watch history deletion
This commit is contained in:
Bnyro 2022-11-28 16:15:57 +01:00 committed by GitHub
commit 494bd083d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -21,8 +21,9 @@ class WatchHistoryAdapter(
RecyclerView.Adapter<WatchHistoryViewHolder>() { RecyclerView.Adapter<WatchHistoryViewHolder>() {
fun removeFromWatchHistory(position: Int) { fun removeFromWatchHistory(position: Int) {
val history = watchHistory[position]
query { query {
DatabaseHolder.Database.watchHistoryDao().delete(watchHistory[position]) DatabaseHolder.Database.watchHistoryDao().delete(history)
} }
watchHistory.removeAt(position) watchHistory.removeAt(position)
notifyItemRemoved(position) notifyItemRemoved(position)

View File

@ -89,7 +89,7 @@ class WatchHistoryFragment : BaseFragment() {
// observe changes // observe changes
watchHistoryAdapter.registerAdapterDataObserver(object : watchHistoryAdapter.registerAdapterDataObserver(object :
RecyclerView.AdapterDataObserver() { RecyclerView.AdapterDataObserver() {
override fun onChanged() { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
if (watchHistoryAdapter.itemCount == 0) { if (watchHistoryAdapter.itemCount == 0) {
binding.watchHistoryRecView.visibility = View.GONE binding.watchHistoryRecView.visibility = View.GONE
binding.historyEmpty.visibility = View.VISIBLE binding.historyEmpty.visibility = View.VISIBLE