Glimpse: Media: Add a MediaStore parser function helper
Change-Id: I3e9438b4bc7f92975037fc7182684a9987ff776e
This commit is contained in:
parent
da0b39e3bf
commit
4bbb71c891
|
@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue