From d534389c82c7a0a21c6edbd498be18e8e7c85bee Mon Sep 17 00:00:00 2001 From: Krunal Patel Date: Wed, 7 Dec 2022 15:53:04 +0530 Subject: [PATCH] Fix crash on opening deleted local playlist Upadte playlist view on content change. --- .../github/libretube/ui/dialogs/DeletePlaylistDialog.kt | 1 + .../com/github/libretube/ui/fragments/LibraryFragment.kt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt index cf7dae196..a374c5e81 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt @@ -40,6 +40,7 @@ class DeletePlaylistDialog( DatabaseHolder.Database.localPlaylistsDao().deletePlaylistById(playlistId) DatabaseHolder.Database.localPlaylistsDao().deletePlaylistItemsByPlaylistId(playlistId) } + onSuccess.invoke() return } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt index d266180db..a37490b82 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt @@ -129,12 +129,14 @@ class LibraryFragment : BaseFragment() { // listen for playlists to become deleted playlistsAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { - override fun onChanged() { - binding.nothingHere.visibility = if (playlistsAdapter.itemCount == 0) View.VISIBLE else View.GONE - super.onChanged() + override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { + binding.nothingHere.visibility = + if (playlistsAdapter.itemCount == 0) View.VISIBLE else View.GONE + super.onItemRangeRemoved(positionStart, itemCount) } }) + binding.nothingHere.visibility = View.GONE binding.playlistRecView.adapter = playlistsAdapter } else { runOnUiThread {