mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
fix: observe livedata once in onViewCreated (#6955)
This commit is contained in:
parent
aef23e26e5
commit
eb7df283eb
@ -54,6 +54,15 @@ class HomeFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
with(homeViewModel) {
|
||||
trending.observe(viewLifecycleOwner, ::showTrending)
|
||||
feed.observe(viewLifecycleOwner, ::showFeed)
|
||||
bookmarks.observe(viewLifecycleOwner, ::showBookmarks)
|
||||
playlists.observe(viewLifecycleOwner, ::showPlaylists)
|
||||
continueWatching.observe(viewLifecycleOwner, ::showContinueWatching)
|
||||
isLoading.observe(viewLifecycleOwner, ::updateLoading)
|
||||
}
|
||||
|
||||
binding.featuredTV.setOnClickListener {
|
||||
findNavController().navigate(R.id.subscriptionsFragment)
|
||||
}
|
||||
@ -94,7 +103,6 @@ class HomeFragment : Fragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
observeChanges()
|
||||
|
||||
// Avoid re-fetching when re-entering the screen if it was loaded successfully
|
||||
if (homeViewModel.loadedSuccessfully.value == false) {
|
||||
@ -102,33 +110,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeChanges() {
|
||||
with(homeViewModel) {
|
||||
trending.observe(viewLifecycleOwner, ::showTrending)
|
||||
feed.observe(viewLifecycleOwner, ::showFeed)
|
||||
bookmarks.observe(viewLifecycleOwner, ::showBookmarks)
|
||||
playlists.observe(viewLifecycleOwner, ::showPlaylists)
|
||||
continueWatching.observe(viewLifecycleOwner, ::showContinueWatching)
|
||||
isLoading.observe(viewLifecycleOwner, ::updateLoading)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
stopObservingChanges()
|
||||
}
|
||||
|
||||
private fun stopObservingChanges() {
|
||||
with(homeViewModel) {
|
||||
trending.removeObserver(::showTrending)
|
||||
feed.removeObserver(::showFeed)
|
||||
bookmarks.removeObserver(::showBookmarks)
|
||||
playlists.removeObserver(::showPlaylists)
|
||||
continueWatching.removeObserver(::showContinueWatching)
|
||||
isLoading.removeObserver(::updateLoading)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
|
Loading…
x
Reference in New Issue
Block a user