Merge pull request #3517 from Bnyro/master

Fix crashes caused by view bindings
This commit is contained in:
Bnyro 2023-04-10 13:32:17 +02:00 committed by GitHub
commit f24ef883c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -132,6 +132,7 @@ class HomeFragment : Fragment() {
val bookmarkedPlaylists = withContext(Dispatchers.IO) {
DatabaseHolder.Database.playlistBookmarkDao().getAll()
}.takeIf { it.isNotEmpty() } ?: return
val binding = _binding ?: return
makeVisible(binding.bookmarksTV, binding.bookmarksRV)
binding.bookmarksRV.layoutManager = LinearLayoutManager(
@ -151,6 +152,7 @@ class HomeFragment : Fragment() {
PlaylistsHelper.getPlaylists().take(20)
}
}.getOrNull()?.takeIf { it.isNotEmpty() } ?: return
val binding = _binding ?: return
makeVisible(binding.playlistsRV, binding.playlistsTV)
binding.playlistsRV.layoutManager = LinearLayoutManager(context)

View File

@ -33,6 +33,7 @@ class WatchHistoryFragment : Fragment() {
private var _binding: FragmentWatchHistoryBinding? = null
private val binding get() = _binding!!
private val handler = Handler(Looper.getMainLooper())
private val playerViewModel: PlayerViewModel by activityViewModels()
private var isLoading = false
@ -49,7 +50,7 @@ class WatchHistoryFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
playerViewModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
binding.watchHistoryRecView.updatePadding(
_binding?.watchHistoryRecView?.updatePadding(
bottom = if (it) (64).dpToPx().toInt() else 0
)
}
@ -148,7 +149,8 @@ class WatchHistoryFragment : Fragment() {
})
// add a listener for scroll end, delay needed to prevent loading new ones the first time
Handler(Looper.getMainLooper()).postDelayed(200) {
handler.postDelayed(200) {
if (_binding == null) return@postDelayed
binding.historyScrollView.viewTreeObserver.addOnScrollChangedListener {
if (_binding?.historyScrollView?.canScrollVertically(1) == false &&
!isLoading