Glimpse: Media: Add a MediaStore parser function helper

Change-Id: I3e9438b4bc7f92975037fc7182684a9987ff776e
This commit is contained in:
Sebastiano Barezzi 2023-08-06 01:10:22 +02:00
parent da0b39e3bf
commit 4bbb71c891
No known key found for this signature in database
GPG Key ID: 763BD3AE91A7A13F
3 changed files with 20 additions and 9 deletions

View File

@ -55,5 +55,17 @@ data class Media(
override fun createFromParcel(parcel: Parcel) = Media(parcel)
override fun newArray(size: Int) = arrayOfNulls<Media>(size)
fun fromMediaStore(
id: Long,
isFavorite: Int,
mediaType: Int,
dateAdded: Long,
) = Media(
id,
isFavorite == 1,
MediaType.fromMediaStoreValue(mediaType),
Date(dateAdded * 1000),
)
}
}

View File

@ -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,
)
}

View File

@ -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,
)
}