Glimpse: Add bucket ID to Media

Change-Id: I0f94f8444ac11a65a68e7913f29c3208a03c315c
This commit is contained in:
Luca Stefani 2023-08-08 22:48:04 +02:00
parent 5dfb70cebe
commit f3869838c4
4 changed files with 14 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import java.util.Date
data class Media(
val id: Long,
val bucketId: Int,
val isFavorite: Boolean,
val isTrashed: Boolean,
val mediaType: MediaType,
@ -25,6 +26,7 @@ data class Media(
constructor(parcel: Parcel) : this(
parcel.readLong(),
parcel.readInt(),
parcel.readInt() == 1,
parcel.readInt() == 1,
when (parcel.readInt()) {
@ -40,6 +42,7 @@ data class Media(
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeLong(id)
dest.writeInt(bucketId)
dest.writeInt(if (isFavorite) 1 else 0)
dest.writeInt(if (isTrashed) 1 else 0)
dest.writeInt(mediaType.ordinal)
@ -70,6 +73,7 @@ data class Media(
fun fromMediaStore(
id: Long,
bucketId: Int,
isFavorite: Int,
isTrashed: Int,
mediaType: Int,
@ -77,6 +81,7 @@ data class Media(
dateAdded: Long,
) = Media(
id,
bucketId,
isFavorite == 1,
isTrashed == 1,
MediaType.fromMediaStoreValue(mediaType),

View File

@ -10,6 +10,7 @@ import android.provider.MediaStore
object MediaQuery {
val MediaProjection = arrayOf(
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.BUCKET_ID,
MediaStore.Files.FileColumns.IS_FAVORITE,
MediaStore.Files.FileColumns.IS_TRASHED,
MediaStore.Files.FileColumns.MEDIA_TYPE,

View File

@ -28,6 +28,7 @@ class MediaViewerAdapter(
) : BaseCursorAdapter<MediaViewerAdapter.MediaViewHolder>() {
// Cursor indexes
private var idIndex = -1
private var bucketIdIndex = -1
private var isFavoriteIndex = -1
private var isTrashedIndex = -1
private var mediaTypeIndex = -1
@ -64,6 +65,7 @@ class MediaViewerAdapter(
cursor?.let {
idIndex = it.getColumnIndex(MediaStore.Files.FileColumns._ID)
bucketIdIndex = it.getColumnIndex(MediaStore.Files.FileColumns.BUCKET_ID)
isFavoriteIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_FAVORITE)
isTrashedIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_TRASHED)
mediaTypeIndex = it.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE)
@ -78,6 +80,7 @@ class MediaViewerAdapter(
cursor.moveToPosition(position)
val id = cursor.getLong(idIndex)
val bucketId = cursor.getInt(bucketIdIndex)
val isFavorite = cursor.getInt(isFavoriteIndex)
val isTrashed = cursor.getInt(isTrashedIndex)
val mediaType = cursor.getInt(mediaTypeIndex)
@ -86,6 +89,7 @@ class MediaViewerAdapter(
return Media.fromMediaStore(
id,
bucketId,
isFavorite,
isTrashed,
mediaType,

View File

@ -31,6 +31,7 @@ class ThumbnailAdapter(
// Cursor indexes
private var idIndex = -1
private var bucketIdIndex = -1
private var isFavoriteIndex = -1
private var isTrashedIndex = -1
private var mediaTypeIndex = -1
@ -127,6 +128,7 @@ class ThumbnailAdapter(
cursor?.let {
idIndex = it.getColumnIndex(MediaStore.Files.FileColumns._ID)
bucketIdIndex = it.getColumnIndex(MediaStore.Files.FileColumns.BUCKET_ID)
isFavoriteIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_FAVORITE)
isTrashedIndex = it.getColumnIndex(MediaStore.Files.FileColumns.IS_TRASHED)
mediaTypeIndex = it.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE)
@ -154,6 +156,7 @@ class ThumbnailAdapter(
cursor.moveToPosition(position)
val id = cursor.getLong(idIndex)
val bucketId = cursor.getInt(bucketIdIndex)
val isFavorite = cursor.getInt(isFavoriteIndex)
val isTrashed = cursor.getInt(isTrashedIndex)
val mediaType = cursor.getInt(mediaTypeIndex)
@ -162,6 +165,7 @@ class ThumbnailAdapter(
return Media.fromMediaStore(
id,
bucketId,
isFavorite,
isTrashed,
mediaType,