[Android] Fix VideoGridFragment and VideoListAdapter leaks
Nicolas Pomepuy
git at videolan.org
Thu Sep 7 08:21:02 UTC 2023
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul 25 13:44:25 2023 +0200| [970a9981f7ba0e6d7efd5eae8028794034362ad7] | committer: Nicolas Pomepuy
Fix VideoGridFragment and VideoListAdapter leaks
> https://code.videolan.org/videolan/vlc-android/commit/970a9981f7ba0e6d7efd5eae8028794034362ad7
---
.../src/org/videolan/vlc/gui/video/VideoGridFragment.kt | 7 +++++--
.../src/org/videolan/vlc/gui/video/VideoListAdapter.kt | 14 ++------------
2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index 6bf84dac06..f876af9879 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -140,7 +140,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
videoListAdapter.showFilename.set(viewModel.groupingType == VideoGroupingType.NONE && viewModel.provider.sort == Medialibrary.SORT_FILENAME)
lifecycleScope.launch {
waitForML()
- viewModel.provider.pagedList.observe(requireActivity()) {
+ viewModel.provider.pagedList.observe(this at VideoGridFragment) {
@Suppress("UNCHECKED_CAST")
(it as? PagedList<MediaLibraryItem>)?.let { pagedList -> videoListAdapter.submitList(pagedList) }
updateEmptyView()
@@ -149,6 +149,9 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
setFabPlayVisibility(true)
}
}
+ EventTools.getInstance().lastThumb.observe(this) {
+ videoListAdapter.updateThumb(it)
+ }
}
override fun onPrepareOptionsMenu(menu: Menu) {
@@ -288,8 +291,8 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
override fun onDestroy() {
super.onDestroy()
- videoListAdapter.release()
gridItemDecoration = null
+ swipeRefreshLayout.setOnRefreshListener(null)
if (::dataObserver.isInitialized) videoListAdapter.unregisterAdapterDataObserver(dataObserver)
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
index b1e408fb70..6e0c092616 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
@@ -33,12 +33,10 @@ import androidx.databinding.BindingAdapter
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableBoolean
import androidx.databinding.ViewDataBinding
-import androidx.lifecycle.Observer
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
-import org.videolan.medialibrary.EventTools
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.media.Folder
import org.videolan.medialibrary.interfaces.media.MediaWrapper
@@ -66,22 +64,14 @@ class VideoListAdapter(private var isSeenMediaMarkerVisible: Boolean
val multiSelectHelper = MultiSelectHelper(this, UPDATE_SELECTION)
- private val thumbObs = Observer<MediaWrapper> { media ->
- val position = currentList?.snapshot()?.indexOf(media) ?: return at Observer
+ fun updateThumb(media:MediaWrapper) {
+ val position = currentList?.snapshot()?.indexOf(media) ?: return
(getItem(position) as? MediaWrapper)?.run {
artworkURL = media.artworkURL
notifyItemChanged(position)
}
}
- init {
- EventTools.getInstance().lastThumb.observeForever(thumbObs)
- }
-
- fun release() {
- EventTools.getInstance().lastThumb.removeObserver(thumbObs)
- }
-
val all: List<MediaLibraryItem>
get() = currentList?.snapshot() ?: emptyList()
More information about the Android
mailing list