From 451320b7de30d12b24a62a0a5a382de73d97e83f Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 14 Apr 2023 11:01:45 +0200 Subject: [PATCH] Fix crash in library fragment due to view bindings --- .../github/libretube/ui/fragments/LibraryFragment.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 6b2fb9e89..33a31c617 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 @@ -107,6 +107,8 @@ class LibraryFragment : Fragment() { DatabaseHolder.Database.playlistBookmarkDao().getAll() } + val binding = _binding ?: return@launch + binding.bookmarksCV.isVisible = bookmarks.isNotEmpty() if (bookmarks.isNotEmpty()) { binding.bookmarksRecView.adapter = PlaylistBookmarkAdapter(bookmarks) @@ -134,9 +136,11 @@ class LibraryFragment : Fragment() { Log.e(TAG(), e.toString()) Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() return@repeatOnLifecycle - } finally { - binding.playlistRefresh.isRefreshing = false } + + val binding = _binding ?: return@repeatOnLifecycle + binding.playlistRefresh.isRefreshing = false + if (playlists.isNotEmpty()) { playlists = when ( PreferenceHelper.getString(PreferenceKeys.PLAYLISTS_ORDER, "recent") @@ -157,7 +161,7 @@ class LibraryFragment : Fragment() { playlistsAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { - binding.nothingHere.isVisible = playlistsAdapter.itemCount == 0 + _binding?.nothingHere?.isVisible = playlistsAdapter.itemCount == 0 super.onItemRangeRemoved(positionStart, itemCount) } })