Glimpse: Add display name to Media

Change-Id: Icf723d459cc9899788e8852d04272b58f87d8445
This commit is contained in:
Sebastiano Barezzi 2023-08-07 01:24:50 +02:00
parent 1baef233ff
commit b2d54069e4
No known key found for this signature in database
GPG Key ID: 763BD3AE91A7A13F
4 changed files with 12 additions and 0 deletions

View File

@ -53,6 +53,7 @@ class AlbumsFlow(private val context: Context) : QueryFlow<Album>() {
it?.use {
val idIndex = it.getColumnIndex(MediaStore.Files.FileColumns._ID)
val bucketIdIndex = it.getColumnIndex(MediaStore.Files.FileColumns.BUCKET_ID)
val displayNameIndex = it.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
val isFavoriteIndex =
it.getColumnIndex(MediaStore.Files.FileColumns.IS_FAVORITE)
val isTrashedIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_TRASHED)
@ -84,6 +85,7 @@ class AlbumsFlow(private val context: Context) : QueryFlow<Album>() {
album.size += 1
} ?: run {
val id = it.getLong(idIndex)
val displayName = it.getString(displayNameIndex)
val isFavorite = it.getInt(isFavoriteIndex)
val isTrashed = it.getInt(isTrashedIndex)
val mediaType = it.getInt(mediaTypeIndex)
@ -107,6 +109,7 @@ class AlbumsFlow(private val context: Context) : QueryFlow<Album>() {
Media.fromMediaStore(
id,
bucketId,
displayName,
isFavorite,
isTrashed,
mediaType,

View File

@ -74,6 +74,7 @@ class MediaFlow(private val context: Context, private val bucketId: Int?) : Quer
override fun flowData() = flowCursor().mapEachRow {
val idIndex = it.getColumnIndex(MediaStore.Files.FileColumns._ID)
val displayNameIndex = it.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
val isFavoriteIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_FAVORITE)
val isTrashedIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_TRASHED)
val mediaTypeIndex = it.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE)
@ -83,6 +84,7 @@ class MediaFlow(private val context: Context, private val bucketId: Int?) : Quer
val id = it.getLong(idIndex)
val buckedId = it.getInt(bucketIdIndex)
val displayName = it.getString(displayNameIndex)
val isFavorite = it.getInt(isFavoriteIndex)
val isTrashed = it.getInt(isTrashedIndex)
val mediaType = it.getInt(mediaTypeIndex)
@ -92,6 +94,7 @@ class MediaFlow(private val context: Context, private val bucketId: Int?) : Quer
Media.fromMediaStore(
id,
buckedId,
displayName,
isFavorite,
isTrashed,
mediaType,

View File

@ -17,6 +17,7 @@ import kotlin.reflect.safeCast
data class Media(
val id: Long,
val bucketId: Int,
val displayName: String,
val isFavorite: Boolean,
val isTrashed: Boolean,
val mediaType: MediaType,
@ -28,6 +29,7 @@ data class Media(
constructor(parcel: Parcel) : this(
parcel.readLong(),
parcel.readInt(),
parcel.readString()!!,
parcel.readInt() == 1,
parcel.readInt() == 1,
when (parcel.readInt()) {
@ -62,6 +64,7 @@ data class Media(
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeLong(id)
dest.writeInt(bucketId)
dest.writeString(displayName)
dest.writeInt(if (isFavorite) 1 else 0)
dest.writeInt(if (isTrashed) 1 else 0)
dest.writeInt(mediaType.ordinal)
@ -93,6 +96,7 @@ data class Media(
fun fromMediaStore(
id: Long,
bucketId: Int,
displayName: String,
isFavorite: Int,
isTrashed: Int,
mediaType: Int,
@ -101,6 +105,7 @@ data class Media(
) = Media(
id,
bucketId,
displayName,
isFavorite == 1,
isTrashed == 1,
MediaType.fromMediaStoreValue(mediaType),

View File

@ -13,6 +13,7 @@ object MediaQuery {
val MediaProjection = arrayOf(
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.BUCKET_ID,
MediaStore.Files.FileColumns.DISPLAY_NAME,
MediaStore.Files.FileColumns.IS_FAVORITE,
MediaStore.Files.FileColumns.IS_TRASHED,
MediaStore.Files.FileColumns.MEDIA_TYPE,