From 4bbb71c891792d79b729abbe450443a38508cffe Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Sun, 6 Aug 2023 01:10:22 +0200 Subject: [PATCH] Glimpse: Media: Add a MediaStore parser function helper Change-Id: I3e9438b4bc7f92975037fc7182684a9987ff776e --- .../main/java/org/lineageos/glimpse/models/Media.kt | 12 ++++++++++++ .../glimpse/thumbnail/MediaViewerAdapter.kt | 9 ++++----- .../lineageos/glimpse/thumbnail/ThumbnailAdapter.kt | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/lineageos/glimpse/models/Media.kt b/app/src/main/java/org/lineageos/glimpse/models/Media.kt index 77bc36c..a607649 100644 --- a/app/src/main/java/org/lineageos/glimpse/models/Media.kt +++ b/app/src/main/java/org/lineageos/glimpse/models/Media.kt @@ -55,5 +55,17 @@ data class Media( override fun createFromParcel(parcel: Parcel) = Media(parcel) override fun newArray(size: Int) = arrayOfNulls(size) + + fun fromMediaStore( + id: Long, + isFavorite: Int, + mediaType: Int, + dateAdded: Long, + ) = Media( + id, + isFavorite == 1, + MediaType.fromMediaStoreValue(mediaType), + Date(dateAdded * 1000), + ) } } diff --git a/app/src/main/java/org/lineageos/glimpse/thumbnail/MediaViewerAdapter.kt b/app/src/main/java/org/lineageos/glimpse/thumbnail/MediaViewerAdapter.kt index 89e3877..f51f520 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/MediaViewerAdapter.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/MediaViewerAdapter.kt @@ -20,7 +20,6 @@ import coil.load import org.lineageos.glimpse.R import org.lineageos.glimpse.models.Media import org.lineageos.glimpse.models.MediaType -import java.util.Date class MediaViewerAdapter( private val exoPlayer: ExoPlayer, @@ -62,15 +61,15 @@ class MediaViewerAdapter( cursor.moveToPosition(position) val id = cursor.getLong(idIndex) - val isFavorite = cursor.getInt(isFavoriteIndex) == 1 + val isFavorite = cursor.getInt(isFavoriteIndex) val mediaType = cursor.getInt(mediaTypeIndex) val dateAdded = cursor.getLong(dateAddedIndex) - return Media( + return Media.fromMediaStore( id, isFavorite, - MediaType.fromMediaStoreValue(mediaType), - Date(dateAdded * 1000) + mediaType, + dateAdded, ) } diff --git a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt index 5f2e718..74d94a0 100644 --- a/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt +++ b/app/src/main/java/org/lineageos/glimpse/thumbnail/ThumbnailAdapter.kt @@ -155,15 +155,15 @@ class ThumbnailAdapter( cursor.moveToPosition(position) val id = cursor.getLong(idIndex) - val isFavorite = cursor.getInt(isFavoriteIndex) == 1 + val isFavorite = cursor.getInt(isFavoriteIndex) val mediaType = cursor.getInt(mediaTypeIndex) val dateAdded = cursor.getLong(dateAddedIndex) - return Media( + return Media.fromMediaStore( id, isFavorite, - MediaType.fromMediaStoreValue(mediaType), - Date(dateAdded * 1000) + mediaType, + dateAdded, ) }