Commit f240566d authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

VideogridFragment: Move observer in the Fragment

parent 9a4e7844
......@@ -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@Observer
val position = viewModel.provider.pagedList.value?.indexOf(media) ?: return@Observer
videoListAdapter.getItem(position)?.run {
artworkURL = media.artworkURL
videoListAdapter.notifyItemChanged(position)
}
}
}
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment