[Android] Video: properly compare folders and groups

Geoffrey Métais git at videolan.org
Tue Oct 8 09:28:12 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct  7 18:17:43 2019 +0200| [858fad50ac61da5222de9cec29ceec37412e2ad7] | committer: Geoffrey Métais

Video: properly compare folders and groups

This fixes a visual glitch on refresh

> https://code.videolan.org/videolan/vlc-android/commit/858fad50ac61da5222de9cec29ceec37412e2ad7
---

 .../org/videolan/vlc/gui/video/VideoGridFragment.kt   |  7 ++-----
 .../org/videolan/vlc/gui/video/VideoListAdapter.kt    | 19 ++++++++++---------
 2 files changed, 12 insertions(+), 14 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 3337b5edc..01fbdb704 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.kt
@@ -28,7 +28,6 @@ import android.os.Handler
 import android.os.Message
 import android.util.Log
 import android.view.*
-import androidx.annotation.MainThread
 import androidx.appcompat.app.AppCompatActivity
 import androidx.appcompat.view.ActionMode
 import androidx.fragment.app.FragmentActivity
@@ -36,7 +35,6 @@ import androidx.lifecycle.Observer
 import androidx.paging.PagedList
 import androidx.recyclerview.widget.RecyclerView
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-import kotlinx.android.synthetic.main.vlc_login_dialog.*
 import kotlinx.coroutines.*
 import kotlinx.coroutines.channels.actor
 import org.videolan.medialibrary.interfaces.AbstractMedialibrary
@@ -61,12 +59,11 @@ import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.media.getAll
-import org.videolan.vlc.providers.medialibrary.FoldersProvider
-import org.videolan.vlc.providers.medialibrary.VideoGroupsProvider
 import org.videolan.vlc.providers.medialibrary.VideosProvider
 import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.*
-import org.videolan.vlc.viewmodels.mobile.*
+import org.videolan.vlc.viewmodels.mobile.VideoGroupingType
+import org.videolan.vlc.viewmodels.mobile.VideosViewModel
 import org.videolan.vlc.viewmodels.mobile.getViewModel
 import java.lang.ref.WeakReference
 import java.util.*
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 5a744828f..dc7128b79 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.kt
@@ -48,7 +48,6 @@ import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.medialibrary.interfaces.media.AbstractFolder
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.medialibrary.interfaces.media.AbstractVideoGroup
-import org.videolan.medialibrary.media.Folder
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.tools.MultiSelectAdapter
 import org.videolan.tools.MultiSelectHelper
@@ -244,19 +243,21 @@ class VideoListAdapter internal constructor(
     }
 
     private object VideoItemDiffCallback : DiffUtil.ItemCallback<MediaLibraryItem>() {
-        override fun areItemsTheSame(oldItem: MediaLibraryItem, newItem: MediaLibraryItem): Boolean {
-            return if (oldItem is AbstractMediaWrapper && newItem is AbstractMediaWrapper)
+        override fun areItemsTheSame(oldItem: MediaLibraryItem, newItem: MediaLibraryItem) = when {
+            oldItem is AbstractMediaWrapper && newItem is AbstractMediaWrapper -> {
                 oldItem === newItem || oldItem.type == newItem.type && oldItem.equals(newItem)
-            else oldItem === newItem || oldItem.itemType == newItem.itemType && oldItem.equals(newItem)
+            }
+            else -> oldItem === newItem || oldItem.itemType == newItem.itemType && oldItem.equals(newItem)
         }
 
         @SuppressLint("DiffUtilEquals")
         override fun areContentsTheSame(oldItem: MediaLibraryItem, newItem: MediaLibraryItem): Boolean {
-            return if (oldItem is AbstractMediaWrapper && newItem is AbstractMediaWrapper) oldItem === newItem || (oldItem.displayTime == newItem.displayTime
-                    && TextUtils.equals(oldItem.artworkMrl, newItem.artworkMrl)
-                    && oldItem.seen == newItem.seen)
-            else if (oldItem is Folder && newItem is Folder) return oldItem === newItem || (oldItem.title == newItem.title && oldItem.artworkMrl == newItem.artworkMrl)
-            else false
+            return if (oldItem is AbstractMediaWrapper && newItem is AbstractMediaWrapper) {
+                oldItem === newItem || (oldItem.displayTime == newItem.displayTime
+                        && TextUtils.equals(oldItem.artworkMrl, newItem.artworkMrl)
+                        && oldItem.seen == newItem.seen)
+            } //else if (oldItem is Folder && newItem is Folder) return oldItem === newItem || (oldItem.title == newItem.title && oldItem.artworkMrl == newItem.artworkMrl)
+            else oldItem.itemType == MediaLibraryItem.TYPE_FOLDER || oldItem.itemType == MediaLibraryItem.TYPE_VIDEO_GROUP
         }
 
         override fun getChangePayload(oldItem: MediaLibraryItem, newItem: MediaLibraryItem) = when {



More information about the Android mailing list