Glimpse: MediaUri -> UriMedia
Change-Id: I6f66656be8e4feedd6a4b13b41ecf14259717219
diff --git a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
index 755fc82..6a47c12 100644
--- a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
@@ -48,7 +48,7 @@
import org.lineageos.glimpse.ext.*
import org.lineageos.glimpse.models.Media
import org.lineageos.glimpse.models.MediaType
-import org.lineageos.glimpse.models.MediaUri
+import org.lineageos.glimpse.models.UriMedia
import org.lineageos.glimpse.recyclerview.MediaViewerAdapter
import org.lineageos.glimpse.ui.MediaInfoBottomSheetDialog
import org.lineageos.glimpse.utils.MediaStoreBuckets
@@ -133,7 +133,7 @@
private var media: Media? = null
private var albumId: Int? = MediaStoreBuckets.MEDIA_STORE_BUCKET_PLACEHOLDER.id
private var additionalMedias: Array<Media>? = null
- private var mediaUri: MediaUri? = null
+ private var uriMedia: UriMedia? = null
private var secure = false
private var lastTrashedMedia: Media? = null
@@ -143,7 +143,7 @@
* Check if we're showing a static set of medias.
*/
private val readOnly
- get() = mediaUri != null || additionalMedias != null || albumId == null || secure
+ get() = uriMedia != null || additionalMedias != null || albumId == null || secure
// Contracts
private val deleteUriContract =
@@ -225,7 +225,7 @@
this@ViewActivity.model.mediaPosition = position
- mediaUri?.also {
+ uriMedia?.also {
updateExoPlayer(it.mediaType, it.uri)
} ?: run {
val media = mediaViewerAdapter.getItemAtPosition(position)
@@ -267,7 +267,7 @@
// Attach the adapter to the view pager
viewPager.adapter = mediaViewerAdapter
- mediaUri?.also {
+ uriMedia?.also {
initData(it)
} ?: additionalMedias?.also { additionalMedias ->
val medias = media?.let {
@@ -359,7 +359,7 @@
shareButton.setOnClickListener {
startActivity(
Intent.createChooser(
- mediaUri?.let {
+ uriMedia?.let {
buildShareIntent(it)
} ?: buildShareIntent(
mediaViewerAdapter.getItemAtPosition(viewPager.currentItem)
@@ -467,8 +467,8 @@
onPageChangeCallback.onPageSelected(mediaPosition)
}
- private fun initData(mediaUri: MediaUri) {
- mediaViewerAdapter.mediaUri = mediaUri
+ private fun initData(uriMedia: UriMedia) {
+ mediaViewerAdapter.uriMedia = uriMedia
// We have a single element
val mediaPosition = 0
@@ -486,7 +486,7 @@
private fun updateUI() {
// Set UI elements visibility based on initial arguments
val readOnly = readOnly
- val shouldShowMediaButtons = mediaUri == null
+ val shouldShowMediaButtons = uriMedia == null
dateTextView.isVisible = shouldShowMediaButtons
timeTextView.isVisible = shouldShowMediaButtons
@@ -620,7 +620,7 @@
}
updateArguments(
- mediaUri = MediaUri(uri, uriType, dataType),
+ uriMedia = UriMedia(uri, uriType, dataType),
secure = secure,
)
@@ -660,20 +660,20 @@
* @param media The first media to show
* @param albumId Album ID, if null [additionalMedias] will be used
* @param additionalMedias The additional medias to show alongside [media]
- * @param mediaUri The [MediaUri] to show
+ * @param uriMedia The [UriMedia] to show
* @param secure Whether this should be considered a secure session
*/
private fun updateArguments(
media: Media? = null,
albumId: Int? = null,
additionalMedias: Array<Media>? = null,
- mediaUri: MediaUri? = null,
+ uriMedia: UriMedia? = null,
secure: Boolean = false,
) {
this.media = media
this.albumId = albumId
this.additionalMedias = additionalMedias
- this.mediaUri = mediaUri
+ this.uriMedia = uriMedia
this.secure = secure
}
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 260209f..12107c2 100644
--- a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt
@@ -9,7 +9,7 @@
import org.lineageos.glimpse.models.Media
import org.lineageos.glimpse.models.MediaType.IMAGE
import org.lineageos.glimpse.models.MediaType.VIDEO
-import org.lineageos.glimpse.models.MediaUri
+import org.lineageos.glimpse.models.UriMedia
fun buildShareIntent(vararg medias: Media) = Intent().apply {
assert(medias.isNotEmpty()) { "No media" }
@@ -38,12 +38,12 @@
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
-fun buildShareIntent(vararg mediaUris: MediaUri) = Intent().apply {
- assert(mediaUris.isNotEmpty()) { "No media uri" }
+fun buildShareIntent(vararg uriMedias: UriMedia) = Intent().apply {
+ assert(uriMedias.isNotEmpty()) { "No media uri" }
- if (mediaUris.size == 1) {
+ if (uriMedias.size == 1) {
action = Intent.ACTION_SEND
- mediaUris[0].let {
+ uriMedias[0].let {
putExtra(Intent.EXTRA_STREAM, it.uri)
type = it.mimeType
}
@@ -51,11 +51,11 @@
action = Intent.ACTION_SEND_MULTIPLE
putParcelableArrayListExtra(
Intent.EXTRA_STREAM,
- mediaUris.map { it.uri }.toCollection(ArrayList())
+ uriMedias.map { it.uri }.toCollection(ArrayList())
)
type = when {
- mediaUris.all { it.mediaType == IMAGE } -> "image/*"
- mediaUris.all { it.mediaType == VIDEO } -> "video/*"
+ uriMedias.all { it.mediaType == IMAGE } -> "image/*"
+ uriMedias.all { it.mediaType == VIDEO } -> "video/*"
else -> {
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "video/*"))
"*/*"
diff --git a/app/src/main/java/org/lineageos/glimpse/models/MediaUri.kt b/app/src/main/java/org/lineageos/glimpse/models/UriMedia.kt
similarity index 77%
rename from app/src/main/java/org/lineageos/glimpse/models/MediaUri.kt
rename to app/src/main/java/org/lineageos/glimpse/models/UriMedia.kt
index 8262264..6f1a173 100644
--- a/app/src/main/java/org/lineageos/glimpse/models/MediaUri.kt
+++ b/app/src/main/java/org/lineageos/glimpse/models/UriMedia.kt
@@ -13,11 +13,11 @@
import org.lineageos.glimpse.ext.readSerializable
import kotlin.reflect.safeCast
-data class MediaUri(
+data class UriMedia(
val uri: Uri,
val mediaType: MediaType,
val mimeType: String,
-) : Comparable<MediaUri>, Parcelable {
+) : Comparable<UriMedia>, Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(Uri::class)!!,
parcel.readSerializable(MediaType::class)!!,
@@ -40,20 +40,20 @@
}
override fun equals(other: Any?): Boolean {
- val obj = MediaUri::class.safeCast(other) ?: return false
+ val obj = UriMedia::class.safeCast(other) ?: return false
return compareTo(obj) == 0
}
- override fun compareTo(other: MediaUri) = compareValuesBy(
+ override fun compareTo(other: UriMedia) = compareValuesBy(
this, other,
{ it.uri },
{ it.mediaType },
{ it.mimeType },
)
- companion object CREATOR : Creator<MediaUri> {
- override fun createFromParcel(parcel: Parcel) = MediaUri(parcel)
+ companion object CREATOR : Creator<UriMedia> {
+ override fun createFromParcel(parcel: Parcel) = UriMedia(parcel)
- override fun newArray(size: Int) = arrayOfNulls<MediaUri>(size)
+ override fun newArray(size: Int) = arrayOfNulls<UriMedia>(size)
}
}
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 4679f57..55f5cbb 100644
--- a/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/MediaViewerAdapter.kt
@@ -21,7 +21,7 @@
import org.lineageos.glimpse.ext.fade
import org.lineageos.glimpse.models.Media
import org.lineageos.glimpse.models.MediaType
-import org.lineageos.glimpse.models.MediaUri
+import org.lineageos.glimpse.models.UriMedia
import org.lineageos.glimpse.viewmodels.MediaViewerUIViewModel
import org.lineageos.glimpse.viewmodels.MediaViewerViewModel
@@ -43,7 +43,7 @@
}
}
- var mediaUri: MediaUri? = null
+ var uriMedia: UriMedia? = null
set(value) {
if (value == field) {
return
@@ -60,9 +60,9 @@
setHasStableIds(true)
}
- override fun getItemCount() = mediaUri?.let { 1 } ?: data.size
+ override fun getItemCount() = uriMedia?.let { 1 } ?: data.size
- override fun getItemId(position: Int) = mediaUri?.let { 0 } ?: data[position].id
+ override fun getItemId(position: Int) = uriMedia?.let { 0 } ?: data[position].id
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = MediaViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.media_view, parent, false),
@@ -70,7 +70,7 @@
)
override fun onBindViewHolder(holder: MediaViewHolder, position: Int) {
- mediaUri?.let {
+ uriMedia?.let {
holder.bind(it, position)
} ?: holder.bind(data[position], position)
}
@@ -87,7 +87,7 @@
holder.onViewDetachedFromWindow()
}
- fun getItemAtPosition(position: Int) = mediaUri?.let {
+ fun getItemAtPosition(position: Int) = uriMedia?.let {
throw Exception("Called while Uri is used")
} ?: data[position]
@@ -104,12 +104,12 @@
private val playerView = view.findViewById<PlayerView>(R.id.playerView)
private var media: Media? = null
- private var mediaUri: MediaUri? = null
+ private var uriMedia: UriMedia? = null
private var position = -1
@androidx.media3.common.util.UnstableApi
private val mediaPositionObserver: (Int) -> Unit = { currentPosition: Int ->
- val isNowVideoPlayer = mediaUri?.let { it.mediaType == MediaType.VIDEO }
+ val isNowVideoPlayer = uriMedia?.let { it.mediaType == MediaType.VIDEO }
?: (currentPosition == position && media?.mediaType == MediaType.VIDEO)
imageView.isVisible = !isNowVideoPlayer
@@ -145,7 +145,7 @@
@androidx.media3.common.util.UnstableApi
private val fullscreenModeObserver = { fullscreenMode: Boolean ->
- if ((mediaUri?.mediaType ?: media?.mediaType) == MediaType.VIDEO) {
+ if ((uriMedia?.mediaType ?: media?.mediaType) == MediaType.VIDEO) {
playerControlView.fade(!fullscreenMode)
}
}
@@ -168,10 +168,10 @@
}
}
- fun bind(mediaUri: MediaUri, position: Int) {
- this.mediaUri = mediaUri
+ fun bind(uriMedia: UriMedia, position: Int) {
+ this.uriMedia = uriMedia
this.position = position
- imageView.load(mediaUri.uri)
+ imageView.load(uriMedia.uri)
}
@androidx.media3.common.util.UnstableApi