[Android] Fix ClassCastException

Nicolas Pomepuy git at videolan.org
Thu Jul 15 11:23:53 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul 13 11:08:17 2021 +0200| [eca904f86f1d9e2d81402b35330afa387c101d88] | committer: Nicolas Pomepuy

Fix ClassCastException

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

 .../src/org/videolan/vlc/util/ModelsHelper.kt           | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 9c35c7504..c49f09999 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -8,6 +8,7 @@ import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.medialibrary.interfaces.Medialibrary.*
 import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.medialibrary.interfaces.media.VideoGroup
 import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.util.*
@@ -140,13 +141,15 @@ object ModelsHelper {
             }
         }
         SORT_LASTMODIFICATIONDATE -> {
-            val timestamp = (item as MediaWrapper).lastModified
-            val category = getTimeCategory(timestamp)
-            if (aboveItem == null) getTimeCategoryString(context, category)
-            else {
-                val prevCat = getTimeCategory((aboveItem as MediaWrapper).lastModified)
-                if (prevCat != category) getTimeCategoryString(context, category) else null
-            }
+            if (item is MediaWrapper) {
+                val timestamp = (item as? MediaWrapper)?.lastModified ?: 0
+                val category = getTimeCategory(timestamp)
+                if (aboveItem == null) getTimeCategoryString(context, category)
+                else {
+                    val prevCat = getTimeCategory((aboveItem as? MediaWrapper)?.lastModified ?: -1)
+                    if (prevCat != category) getTimeCategoryString(context, category) else null
+                }
+            } else null
         }
         SORT_ARTIST -> {
             val artist = (item as? MediaWrapper)?.artist ?: (item as? Album)?.albumArtist ?: ""



More information about the Android mailing list