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

View File

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

View File

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

View File

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