[Android] VideogridFragment: Move observer in the Fragment
Geoffrey Métais
git at videolan.org
Fri Jun 28 16:21:02 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 28 16:18:42 2019 +0200| [f240566da0f8d69bc4ccf36be64dc0b150482663] | committer: Geoffrey Métais
VideogridFragment: Move observer in the Fragment
> https://code.videolan.org/videolan/vlc-android/commit/f240566da0f8d69bc4ccf36be64dc0b150482663
---
.../src/org/videolan/vlc/gui/video/VideoGridFragment.kt | 15 ++++++++++++---
.../src/org/videolan/vlc/gui/video/VideoListAdapter.kt | 6 +++---
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
index e79be8d35..bf10036c3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -96,8 +96,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
}
}
- private val handler = VideoGridFragmentHandler(WeakReference(this))
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!::videoListAdapter.isInitialized) {
@@ -109,6 +107,7 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
else arguments?.getParcelable(KEY_FOLDER)
viewModel = getViewModel(folder)
viewModel.provider.pagedList.observe(this, this)
+ AbstractMedialibrary.lastThumb.observe(this, thumbObs)
}
}
@@ -175,7 +174,6 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
override fun onDestroy() {
super.onDestroy()
gridItemDecoration = null
- videoListAdapter.release()
}
override fun onChanged(list: PagedList<AbstractMediaWrapper>?) {
@@ -377,4 +375,15 @@ class VideoGridFragment : MediaBrowserFragment<VideosViewModel>(), SwipeRefreshL
CTX_ADD_TO_PLAYLIST -> UiTools.addToPlaylist(requireActivity(), media.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
}
}
+
+ private val handler = VideoGridFragmentHandler(WeakReference(this))
+
+ private val thumbObs = Observer<AbstractMediaWrapper> { media ->
+ if (!::videoListAdapter.isInitialized) return at Observer
+ val position = viewModel.provider.pagedList.value?.indexOf(media) ?: return at Observer
+ videoListAdapter.getItem(position)?.run {
+ artworkURL = media.artworkURL
+ videoListAdapter.notifyItemChanged(position)
+ }
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
index 1ee386122..6b7f6ad0a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
@@ -20,6 +20,7 @@
package org.videolan.vlc.gui.video
+import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
@@ -126,9 +127,7 @@ class VideoListAdapter internal constructor(
override fun getItem(position: Int) = if (isPositionValid(position)) super.getItem(position) else null
- private fun isPositionValid(position: Int): Boolean {
- return position in 0..(itemCount - 1)
- }
+ private fun isPositionValid(position: Int) = position in 0 until itemCount
// operator fun contains(mw: AbstractMediaWrapper): Boolean {
// return getDataset().indexOf(mw) !== -1
@@ -223,6 +222,7 @@ class VideoListAdapter internal constructor(
return oldItem === newItem || oldItem.type == newItem.type && oldItem.equals(newItem)
}
+ @SuppressLint("DiffUtilEquals")
override fun areContentsTheSame(oldItem: AbstractMediaWrapper, newItem: AbstractMediaWrapper): Boolean {
return oldItem === newItem || (oldItem.displayTime == newItem.displayTime
&& TextUtils.equals(oldItem.artworkMrl, newItem.artworkMrl)
More information about the Android
mailing list