Twelve: Extract MIME type display name outside now playing view model
Change-Id: Ibdd10681d2eed508238a3ccf6f14ae839af74384
diff --git a/app/src/main/java/org/lineageos/twelve/utils/MimeUtils.kt b/app/src/main/java/org/lineageos/twelve/utils/MimeUtils.kt
new file mode 100644
index 0000000..30c534c
--- /dev/null
+++ b/app/src/main/java/org/lineageos/twelve/utils/MimeUtils.kt
@@ -0,0 +1,18 @@
+/*
+ * SPDX-FileCopyrightText: 2024 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.twelve.utils
+
+import androidx.media3.common.MimeTypes
+import androidx.media3.common.util.UnstableApi
+
+object MimeUtils {
+ @androidx.annotation.OptIn(UnstableApi::class)
+ fun mimeTypeToDisplayName(mimeType: String) = MimeTypes.normalizeMimeType(mimeType).let {
+ it.takeIf { it.contains('/') }
+ ?.substringAfterLast('/')
+ ?.uppercase()
+ }
+}
diff --git a/app/src/main/java/org/lineageos/twelve/viewmodels/NowPlayingViewModel.kt b/app/src/main/java/org/lineageos/twelve/viewmodels/NowPlayingViewModel.kt
index 74927aa..d882028 100644
--- a/app/src/main/java/org/lineageos/twelve/viewmodels/NowPlayingViewModel.kt
+++ b/app/src/main/java/org/lineageos/twelve/viewmodels/NowPlayingViewModel.kt
@@ -10,7 +10,6 @@
import androidx.lifecycle.viewModelScope
import androidx.media3.common.C
import androidx.media3.common.MediaMetadata
-import androidx.media3.common.MimeTypes
import androidx.media3.common.util.UnstableApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -47,6 +46,7 @@
import org.lineageos.twelve.models.RepeatMode
import org.lineageos.twelve.models.RequestStatus
import org.lineageos.twelve.models.Thumbnail
+import org.lineageos.twelve.utils.MimeUtils
open class NowPlayingViewModel(application: Application) : TwelveViewModel(application) {
enum class PlaybackSpeed(val value: Float) {
@@ -221,11 +221,7 @@
val displayFileType = mimeType
.mapLatest { mimeType ->
mimeType?.let {
- MimeTypes.normalizeMimeType(it)
- }?.let {
- it.takeIf { it.contains('/') }
- ?.substringAfterLast('/')
- ?.uppercase()
+ MimeUtils.mimeTypeToDisplayName(it)
}
}
.flowOn(Dispatchers.IO)