From 4f7d28ee0e890974148ab706118748b3fb924680 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 5 Oct 2022 21:55:53 +0200 Subject: [PATCH] fix crashes when removing recview items --- .../java/com/github/libretube/ui/adapters/DownloadsAdapter.kt | 1 + .../java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt | 1 + .../com/github/libretube/ui/adapters/SearchHistoryAdapter.kt | 4 ++-- .../com/github/libretube/ui/adapters/WatchHistoryAdapter.kt | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt index 1bafddb5b..bb4e851e7 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt @@ -66,6 +66,7 @@ class DownloadsAdapter( files.removeAt(position) notifyItemRemoved(position) + notifyItemRangeChanged(position, itemCount) } } } diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt index 819d5600f..65aeb5a95 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistsAdapter.kt @@ -104,6 +104,7 @@ class PlaylistsAdapter( playlists.removeAt(position) activity.runOnUiThread { notifyItemRemoved(position) + notifyItemRangeChanged(position, itemCount) } } } catch (e: Exception) { diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt index e6fff4d31..f7ef52edc 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchHistoryAdapter.kt @@ -32,14 +32,14 @@ class SearchHistoryAdapter( historyText.text = historyQuery deleteHistory.setOnClickListener { - val itemIndex = historyList.indexOf(historyQuery) historyList -= historyQuery query { Database.searchHistoryDao().delete( SearchHistoryItem(query = historyQuery) ) } - notifyItemRemoved(itemIndex) + notifyItemRemoved(position) + notifyItemRangeChanged(position, itemCount) } root.setOnClickListener { 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 1fcd4c3d4..d6287289b 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 @@ -24,6 +24,7 @@ class WatchHistoryAdapter( DatabaseHelper.removeFromWatchHistory(position) watchHistory.removeAt(position) notifyItemRemoved(position) + notifyItemRangeChanged(position, itemCount) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchHistoryViewHolder {