Glimpse: Media -> MediaStoreMedia

Change-Id: Iad4b12bc1f6ce10fe6cbe6ce5fee2a93060a345d
diff --git a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
index 6a47c12..44d3547 100644
--- a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
@@ -46,7 +46,7 @@
 import okhttp3.OkHttpClient
 import okhttp3.Request
 import org.lineageos.glimpse.ext.*
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.models.MediaType
 import org.lineageos.glimpse.models.UriMedia
 import org.lineageos.glimpse.recyclerview.MediaViewerAdapter
@@ -130,13 +130,13 @@
     private val httpClient = OkHttpClient()
 
     // Media
-    private var media: Media? = null
+    private var media: MediaStoreMedia? = null
     private var albumId: Int? = MediaStoreBuckets.MEDIA_STORE_BUCKET_PLACEHOLDER.id
-    private var additionalMedias: Array<Media>? = null
+    private var additionalMedias: Array<MediaStoreMedia>? = null
     private var uriMedia: UriMedia? = null
     private var secure = false
 
-    private var lastTrashedMedia: Media? = null
+    private var lastTrashedMedia: MediaStoreMedia? = null
     private var undoTrashSnackbar: Snackbar? = null
 
     /**
@@ -448,7 +448,7 @@
         updateSheetsHeight()
     }
 
-    private fun initData(data: List<Media>) {
+    private fun initData(data: List<MediaStoreMedia>) {
         mediaViewerAdapter.data = data.toTypedArray()
 
         // If we already have a position, keep that, else get one from
@@ -525,7 +525,7 @@
         }
     }
 
-    private fun trashMedia(media: Media, trash: Boolean = !media.isTrashed) {
+    private fun trashMedia(media: MediaStoreMedia, trash: Boolean = !media.isTrashed) {
         if (trash) {
             lastTrashedMedia = media
         }
@@ -664,9 +664,9 @@
      * @param secure Whether this should be considered a secure session
      */
     private fun updateArguments(
-        media: Media? = null,
+        media: MediaStoreMedia? = null,
         albumId: Int? = null,
-        additionalMedias: Array<Media>? = null,
+        additionalMedias: Array<MediaStoreMedia>? = null,
         uriMedia: UriMedia? = null,
         secure: Boolean = false,
     ) {
@@ -678,7 +678,7 @@
     }
 
     /**
-     * Given a [MediaStore] [Uri], parse its information and get a [Media] object.
+     * Given a [MediaStore] [Uri], parse its information and get a [MediaStoreMedia] object.
      * Must not be executed on main thread.
      * @param uri The [MediaStore] [Uri]
      */
@@ -736,7 +736,7 @@
             val height = it.getInt(heightIndex)
             val orientation = it.getInt(orientationIndex)
 
-            Media.fromMediaStore(
+            MediaStoreMedia.fromMediaStore(
                 id,
                 bucketId,
                 displayName,
diff --git a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt
index 12107c2..be1851b 100644
--- a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt
@@ -6,12 +6,12 @@
 package org.lineageos.glimpse.ext
 
 import android.content.Intent
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.models.MediaType.IMAGE
 import org.lineageos.glimpse.models.MediaType.VIDEO
 import org.lineageos.glimpse.models.UriMedia
 
-fun buildShareIntent(vararg medias: Media) = Intent().apply {
+fun buildShareIntent(vararg medias: MediaStoreMedia) = Intent().apply {
     assert(medias.isNotEmpty()) { "No media" }
 
     if (medias.size == 1) {
@@ -64,7 +64,7 @@
     }
 }
 
-fun buildEditIntent(media: Media) = Intent().apply {
+fun buildEditIntent(media: MediaStoreMedia) = Intent().apply {
     action = Intent.ACTION_EDIT
     setDataAndType(media.uri, media.mimeType)
     flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
diff --git a/app/src/main/java/org/lineageos/glimpse/flow/AlbumsFlow.kt b/app/src/main/java/org/lineageos/glimpse/flow/AlbumsFlow.kt
index 51226f5..abed8e7 100644
--- a/app/src/main/java/org/lineageos/glimpse/flow/AlbumsFlow.kt
+++ b/app/src/main/java/org/lineageos/glimpse/flow/AlbumsFlow.kt
@@ -17,7 +17,7 @@
 import org.lineageos.glimpse.R
 import org.lineageos.glimpse.ext.queryFlow
 import org.lineageos.glimpse.models.Album
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.query.*
 import org.lineageos.glimpse.utils.MediaStoreBuckets
 
@@ -118,7 +118,7 @@
 
                                     else -> bucketDisplayName ?: Build.MODEL
                                 },
-                                Media.fromMediaStore(
+                                MediaStoreMedia.fromMediaStore(
                                     id,
                                     bucketId,
                                     displayName,
diff --git a/app/src/main/java/org/lineageos/glimpse/flow/MediaFlow.kt b/app/src/main/java/org/lineageos/glimpse/flow/MediaFlow.kt
index 5cefed6..db75169 100644
--- a/app/src/main/java/org/lineageos/glimpse/flow/MediaFlow.kt
+++ b/app/src/main/java/org/lineageos/glimpse/flow/MediaFlow.kt
@@ -13,11 +13,11 @@
 import androidx.core.os.bundleOf
 import kotlinx.coroutines.flow.Flow
 import org.lineageos.glimpse.ext.*
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.query.*
 import org.lineageos.glimpse.utils.MediaStoreBuckets
 
-class MediaFlow(private val context: Context, private val bucketId: Int) : QueryFlow<Media>() {
+class MediaFlow(private val context: Context, private val bucketId: Int) : QueryFlow<MediaStoreMedia>() {
     init {
         assert(bucketId != MediaStoreBuckets.MEDIA_STORE_BUCKET_PLACEHOLDER.id) {
             "MEDIA_STORE_BUCKET_PLACEHOLDER found"
@@ -107,7 +107,7 @@
         val height = it.getInt(indexCache[i++])
         val orientation = it.getInt(indexCache[i++])
 
-        Media.fromMediaStore(
+        MediaStoreMedia.fromMediaStore(
             id,
             bucketId,
             displayName,
diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
index 369ef2d..8f1f90e 100644
--- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
@@ -47,7 +47,7 @@
 import org.lineageos.glimpse.ViewActivity
 import org.lineageos.glimpse.ext.*
 import org.lineageos.glimpse.models.Album
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.recyclerview.ThumbnailAdapter
 import org.lineageos.glimpse.recyclerview.ThumbnailItemDetailsLookup
 import org.lineageos.glimpse.recyclerview.ThumbnailLayoutManager
@@ -111,9 +111,9 @@
     }
 
     // Selection
-    private var selectionTracker: SelectionTracker<Media>? = null
+    private var selectionTracker: SelectionTracker<MediaStoreMedia>? = null
 
-    private val selectionTrackerObserver = object : SelectionTracker.SelectionObserver<Media>() {
+    private val selectionTrackerObserver = object : SelectionTracker.SelectionObserver<MediaStoreMedia>() {
         override fun onSelectionChanged() {
             super.onSelectionChanged()
 
@@ -240,7 +240,7 @@
     }
 
     // Contracts
-    private var lastProcessedSelection: Array<out Media>? = null
+    private var lastProcessedSelection: Array<out MediaStoreMedia>? = null
     private var undoTrashSnackbar: Snackbar? = null
 
     private val deleteForeverContract =
@@ -351,7 +351,7 @@
             recyclerView,
             thumbnailAdapter.itemKeyProvider,
             ThumbnailItemDetailsLookup(recyclerView),
-            StorageStrategy.createParcelableStorage(Media::class.java),
+            StorageStrategy.createParcelableStorage(MediaStoreMedia::class.java),
         ).withSelectionPredicate(
             SelectionPredicates.createSelectAnything()
         ).build().also {
@@ -400,7 +400,7 @@
         actionMode = null
     }
 
-    private fun trashMedias(trash: Boolean, vararg medias: Media) {
+    private fun trashMedias(trash: Boolean, vararg medias: MediaStoreMedia) {
         lastProcessedSelection = medias
 
         val contract = when (trash) {
diff --git a/app/src/main/java/org/lineageos/glimpse/models/Album.kt b/app/src/main/java/org/lineageos/glimpse/models/Album.kt
index b32cf34..f4ca7ce 100644
--- a/app/src/main/java/org/lineageos/glimpse/models/Album.kt
+++ b/app/src/main/java/org/lineageos/glimpse/models/Album.kt
@@ -16,13 +16,13 @@
 data class Album(
     val id: Int,
     val name: String,
-    val thumbnail: Media,
+    val thumbnail: MediaStoreMedia,
     var size: Int = 0,
 ) : Comparable<Album>, Parcelable {
     constructor(parcel: Parcel) : this(
         parcel.readInt(),
         parcel.readString()!!,
-        parcel.readParcelable(Media::class)!!,
+        parcel.readParcelable(MediaStoreMedia::class)!!,
         parcel.readInt()
     )
 
diff --git a/app/src/main/java/org/lineageos/glimpse/models/Media.kt b/app/src/main/java/org/lineageos/glimpse/models/MediaStoreMedia.kt
similarity index 85%
rename from app/src/main/java/org/lineageos/glimpse/models/Media.kt
rename to app/src/main/java/org/lineageos/glimpse/models/MediaStoreMedia.kt
index 9da877c..5b4d4d1 100644
--- a/app/src/main/java/org/lineageos/glimpse/models/Media.kt
+++ b/app/src/main/java/org/lineageos/glimpse/models/MediaStoreMedia.kt
@@ -12,7 +12,7 @@
 import java.util.Date
 import kotlin.reflect.safeCast
 
-data class Media(
+data class MediaStoreMedia(
     val id: Long,
     val bucketId: Int,
     val displayName: String,
@@ -25,7 +25,7 @@
     val width: Int,
     val height: Int,
     val orientation: Int,
-) : Comparable<Media>, Parcelable {
+) : Comparable<MediaStoreMedia>, Parcelable {
     val uri = ContentUris.withAppendedId(mediaType.externalContentUri, id)
 
     constructor(parcel: Parcel) : this(
@@ -44,13 +44,13 @@
     )
 
     override fun equals(other: Any?): Boolean {
-        val obj = Media::class.safeCast(other) ?: return false
+        val obj = MediaStoreMedia::class.safeCast(other) ?: return false
         return compareTo(obj) == 0
     }
 
     override fun hashCode() = id.hashCode()
 
-    override fun compareTo(other: Media) = compareValuesBy(
+    override fun compareTo(other: MediaStoreMedia) = compareValuesBy(
         this, other,
         { it.id },
         { it.bucketId },
@@ -82,10 +82,10 @@
         dest.writeInt(orientation)
     }
 
-    companion object CREATOR : Parcelable.Creator<Media> {
-        override fun createFromParcel(parcel: Parcel) = Media(parcel)
+    companion object CREATOR : Parcelable.Creator<MediaStoreMedia> {
+        override fun createFromParcel(parcel: Parcel) = MediaStoreMedia(parcel)
 
-        override fun newArray(size: Int) = arrayOfNulls<Media>(size)
+        override fun newArray(size: Int) = arrayOfNulls<MediaStoreMedia>(size)
 
         fun fromMediaStore(
             id: Long,
@@ -100,7 +100,7 @@
             width: Int,
             height: Int,
             orientation: Int,
-        ) = Media(
+        ) = MediaStoreMedia(
             id,
             bucketId,
             displayName,
diff --git a/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt b/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt
index 55f5cbb..6968daa 100644
--- a/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt
@@ -19,7 +19,7 @@
 import coil.load
 import org.lineageos.glimpse.R
 import org.lineageos.glimpse.ext.fade
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.models.MediaType
 import org.lineageos.glimpse.models.UriMedia
 import org.lineageos.glimpse.viewmodels.MediaViewerUIViewModel
@@ -30,7 +30,7 @@
     private val mediaViewerViewModel: MediaViewerViewModel,
     private val mediaViewerUIViewModel: MediaViewerUIViewModel,
 ) : RecyclerView.Adapter<MediaViewerAdapter.MediaViewHolder>() {
-    var data: Array<Media> = arrayOf()
+    var data: Array<MediaStoreMedia> = arrayOf()
         set(value) {
             if (value.contentEquals(field)) {
                 return
@@ -103,7 +103,7 @@
         private val playerControlView = view.findViewById<PlayerControlView>(R.id.exo_controller)
         private val playerView = view.findViewById<PlayerView>(R.id.playerView)
 
-        private var media: Media? = null
+        private var media: MediaStoreMedia? = null
         private var uriMedia: UriMedia? = null
         private var position = -1
 
@@ -159,7 +159,7 @@
             }
         }
 
-        fun bind(media: Media, position: Int) {
+        fun bind(media: MediaStoreMedia, position: Int) {
             this.media = media
             this.position = position
             imageView.load(media.uri) {
diff --git a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
index 0f92fd4..62c38ef 100644
--- a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailAdapter.kt
@@ -25,7 +25,7 @@
 import androidx.recyclerview.widget.RecyclerView
 import coil.load
 import org.lineageos.glimpse.R
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.models.MediaType
 import org.lineageos.glimpse.viewmodels.AlbumViewerViewModel
 import org.lineageos.glimpse.viewmodels.AlbumViewerViewModel.DataType
@@ -34,19 +34,19 @@
 
 class ThumbnailAdapter(
     private val model: AlbumViewerViewModel,
-    private val onItemSelected: (media: Media) -> Unit,
+    private val onItemSelected: (media: MediaStoreMedia) -> Unit,
 ) : ListAdapter<DataType, RecyclerView.ViewHolder>(DATA_TYPE_COMPARATOR) {
     // We store a reverse lookup list for performance reasons
-    private var mediaToIndex: Map<Media, Int>? = null
+    private var mediaToIndex: Map<MediaStoreMedia, Int>? = null
 
-    var selectionTracker: SelectionTracker<Media>? = null
+    var selectionTracker: SelectionTracker<MediaStoreMedia>? = null
 
-    val itemKeyProvider = object : ItemKeyProvider<Media>(SCOPE_CACHED) {
+    val itemKeyProvider = object : ItemKeyProvider<MediaStoreMedia>(SCOPE_CACHED) {
         override fun getKey(position: Int) = getItem(position).let {
             DataType.Thumbnail::class.safeCast(it)?.media
         }
 
-        override fun getPosition(key: Media) = mediaToIndex?.get(key) ?: -1
+        override fun getPosition(key: MediaStoreMedia) = mediaToIndex?.get(key) ?: -1
     }
 
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
@@ -93,7 +93,7 @@
             return
         }
 
-        val dataTypeToIndex = mutableMapOf<Media, Int>()
+        val dataTypeToIndex = mutableMapOf<MediaStoreMedia, Int>()
         for (i in currentList.indices) {
             DataType.Thumbnail::class.safeCast(currentList[i])?.let {
                 dataTypeToIndex[it.media] = i
@@ -144,7 +144,7 @@
     class ThumbnailViewHolder(
         private val view: View,
         private val model: AlbumViewerViewModel,
-        private val onItemSelected: (media: Media) -> Unit,
+        private val onItemSelected: (media: MediaStoreMedia) -> Unit,
     ) : RecyclerView.ViewHolder(view) {
         // Views
         private val selectionCheckedImageView =
@@ -154,14 +154,14 @@
             itemView.findViewById<ImageView>(R.id.videoOverlayImageView)!!
         private val thumbnailImageView = itemView.findViewById<ImageView>(R.id.thumbnailImageView)!!
 
-        private lateinit var media: Media
+        private lateinit var media: MediaStoreMedia
         private var isSelected = false
 
         private val inSelectionModeObserver = Observer { inSelectionMode: Boolean ->
             selectionCheckedImageView.isVisible = inSelectionMode
         }
 
-        val itemDetails = object : ItemDetailsLookup.ItemDetails<Media>() {
+        val itemDetails = object : ItemDetailsLookup.ItemDetails<MediaStoreMedia>() {
             override fun getPosition() = bindingAdapterPosition
             override fun getSelectionKey() = media
         }
@@ -176,7 +176,7 @@
             model.inSelectionMode.removeObserver(inSelectionModeObserver)
         }
 
-        fun bind(media: Media, isSelected: Boolean = false) {
+        fun bind(media: MediaStoreMedia, isSelected: Boolean = false) {
             this.media = media
             this.isSelected = isSelected
 
diff --git a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailItemDetailsLookup.kt b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailItemDetailsLookup.kt
index e4c541a..36cae72 100644
--- a/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailItemDetailsLookup.kt
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/ThumbnailItemDetailsLookup.kt
@@ -8,12 +8,12 @@
 import android.view.MotionEvent
 import androidx.recyclerview.selection.ItemDetailsLookup
 import androidx.recyclerview.widget.RecyclerView
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import kotlin.reflect.safeCast
 
 class ThumbnailItemDetailsLookup(
     private val recyclerView: RecyclerView,
-) : ItemDetailsLookup<Media>() {
+) : ItemDetailsLookup<MediaStoreMedia>() {
     override fun getItemDetails(e: MotionEvent) =
         recyclerView.findChildViewUnder(e.x, e.y)?.let { childView ->
             recyclerView.getChildViewHolder(childView)?.let { viewHolder ->
diff --git a/app/src/main/java/org/lineageos/glimpse/ui/MediaInfoBottomSheetDialog.kt b/app/src/main/java/org/lineageos/glimpse/ui/MediaInfoBottomSheetDialog.kt
index d6ce610..e374a54 100644
--- a/app/src/main/java/org/lineageos/glimpse/ui/MediaInfoBottomSheetDialog.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ui/MediaInfoBottomSheetDialog.kt
@@ -28,14 +28,14 @@
 import kotlinx.coroutines.launch
 import org.lineageos.glimpse.R
 import org.lineageos.glimpse.ext.*
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.models.MediaType
 import java.text.SimpleDateFormat
 import java.util.Locale
 
 class MediaInfoBottomSheetDialog(
     context: Context,
-    media: Media,
+    media: MediaStoreMedia,
     callbacks: Callbacks,
     secure: Boolean = false,
 ) : BottomSheetDialog(context) {
@@ -202,7 +202,7 @@
     }
 
     class Callbacks(private val activity: AppCompatActivity) {
-        private lateinit var editDescriptionMedia: Media
+        private lateinit var editDescriptionMedia: MediaStoreMedia
         private lateinit var editDescriptionDescription: String
 
         private val editDescriptionCallback = activity.registerForActivityResult(
@@ -213,7 +213,7 @@
             }
         }
 
-        fun onEditDescription(media: Media, description: String = "") {
+        fun onEditDescription(media: MediaStoreMedia, description: String = "") {
             editDescriptionMedia = media
             editDescriptionDescription = description
 
@@ -224,7 +224,7 @@
             )
         }
 
-        private fun editDescription(media: Media, description: String) {
+        private fun editDescription(media: MediaStoreMedia, description: String) {
             val contentResolver = activity.contentResolver
 
             contentResolver.openFileDescriptor(
diff --git a/app/src/main/java/org/lineageos/glimpse/viewmodels/AlbumViewerViewModel.kt b/app/src/main/java/org/lineageos/glimpse/viewmodels/AlbumViewerViewModel.kt
index be6e912..e3d2913 100644
--- a/app/src/main/java/org/lineageos/glimpse/viewmodels/AlbumViewerViewModel.kt
+++ b/app/src/main/java/org/lineageos/glimpse/viewmodels/AlbumViewerViewModel.kt
@@ -17,7 +17,7 @@
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.stateIn
 import org.lineageos.glimpse.ext.*
-import org.lineageos.glimpse.models.Media
+import org.lineageos.glimpse.models.MediaStoreMedia
 import org.lineageos.glimpse.recyclerview.ThumbnailAdapter
 import org.lineageos.glimpse.repository.MediaRepository
 import org.lineageos.glimpse.utils.MediaStoreBuckets
@@ -74,7 +74,7 @@
     val inSelectionMode = MutableLiveData(false)
 
     sealed class DataType(val viewType: Int) {
-        class Thumbnail(val media: Media) : DataType(ThumbnailAdapter.ViewTypes.THUMBNAIL.ordinal) {
+        class Thumbnail(val media: MediaStoreMedia) : DataType(ThumbnailAdapter.ViewTypes.THUMBNAIL.ordinal) {
             override fun equals(other: Any?) = media == other
             override fun hashCode() = media.hashCode()
         }