Use MimeTypes object instead of hard-coded strings.

This commit is contained in:
Benoit Marty 2023-11-27 21:55:39 +01:00 committed by Benoit Marty
parent 9059126b2e
commit 1df3817808
14 changed files with 37 additions and 24 deletions

View file

@ -16,6 +16,7 @@
package io.element.android.features.messages.impl.voicemessages.composer
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.mediaplayer.api.MediaPlayer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@ -41,7 +42,7 @@ class VoiceMessageComposerPlayer @Inject constructor(
private val coroutineScope: CoroutineScope,
) {
companion object {
const val MIME_TYPE = "audio/ogg"
const val MIME_TYPE = MimeTypes.Ogg
}
private var mediaPath: String? = null

View file

@ -17,6 +17,7 @@
package io.element.android.features.messages.impl.voicemessages.timeline
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.di.RoomScope
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.media.MediaSource
@ -196,7 +197,7 @@ class DefaultVoiceMessagePlayer(
mediaPlayer.setMedia(
uri = mediaFile.path,
mediaId = eventId.value,
mimeType = "audio/ogg", // Files in the voice cache have no extension so we need to set the mime type manually.
mimeType = MimeTypes.Ogg, // Files in the voice cache have no extension so we need to set the mime type manually.
startPositionMs = if (state.isEnded) 0L else state.currentPosition,
)
}

View file

@ -147,7 +147,7 @@ class TimelineItemContentMessageFactoryTest {
blurHash = null,
height = null,
width = null,
mimeType = "application/octet-stream",
mimeType = MimeTypes.OctetStream,
formattedFileSize = "0 Bytes",
fileExtension = "",
)
@ -210,7 +210,7 @@ class TimelineItemContentMessageFactoryTest {
body = "body",
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = "application/octet-stream",
mimeType = MimeTypes.OctetStream,
formattedFileSize = "0 Bytes",
fileExtension = "",
)
@ -259,7 +259,7 @@ class TimelineItemContentMessageFactoryTest {
body = "body",
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = "application/octet-stream",
mimeType = MimeTypes.OctetStream,
waveform = emptyList<Float>().toImmutableList()
)
assertThat(result).isEqualTo(expected)
@ -316,7 +316,7 @@ class TimelineItemContentMessageFactoryTest {
body = "body",
duration = Duration.ZERO,
mediaSource = MediaSource(url = "url", json = null),
mimeType = "application/octet-stream",
mimeType = MimeTypes.OctetStream,
formattedFileSize = "0 Bytes",
fileExtension = ""
)
@ -337,7 +337,7 @@ class TimelineItemContentMessageFactoryTest {
thumbnailSource = null,
formattedFileSize = "0 Bytes",
fileExtension = "",
mimeType = "application/octet-stream",
mimeType = MimeTypes.OctetStream,
blurhash = null,
width = null,
height = null,
@ -402,7 +402,7 @@ class TimelineItemContentMessageFactoryTest {
thumbnailSource = null,
formattedFileSize = "0 Bytes",
fileExtension = "",
mimeType = "application/octet-stream"
mimeType = MimeTypes.OctetStream
)
assertThat(result).isEqualTo(expected)
}

View file

@ -17,6 +17,7 @@
package io.element.android.features.messages.impl.voicemessages.timeline
import com.google.common.truth.Truth
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
import io.element.android.libraries.matrix.api.media.MediaSource
import io.element.android.libraries.matrix.test.media.FakeMediaLoader
@ -143,7 +144,7 @@ private fun createDefaultVoiceMessageMediaRepo(
url = mxcUri,
json = null
),
mimeType = "audio/ogg",
mimeType = MimeTypes.Ogg,
body = "someBody.ogg"
)

View file

@ -19,6 +19,7 @@ package io.element.android.features.messages.impl.voicemessages.timeline
import app.cash.turbine.TurbineTestContext
import app.cash.turbine.test
import com.google.common.truth.Truth
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.media.MediaSource
import io.element.android.libraries.matrix.test.AN_EVENT_ID
@ -287,7 +288,7 @@ private fun createDefaultVoiceMessagePlayer(
url = MXC_URI,
json = null
),
mimeType = "audio/ogg",
mimeType = MimeTypes.Ogg,
body = "someBody.ogg"
)

View file

@ -17,6 +17,7 @@
package io.element.android.features.messages.impl.voicemessages.timeline
import com.google.common.truth.Truth
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem
import io.element.android.libraries.matrix.api.timeline.item.TimelineItemDebugInfo
@ -37,7 +38,7 @@ class RedactedVoiceMessageManagerTest {
@Test
fun `redacted event - no playing related media`() = runTest {
val mediaPlayer = FakeMediaPlayer().apply {
setMedia(uri = "someUri", mediaId = AN_EVENT_ID.value, mimeType = "audio/ogg")
setMedia(uri = "someUri", mediaId = AN_EVENT_ID.value, mimeType = MimeTypes.Ogg)
play()
}
val manager = aDefaultRedactedVoiceMessageManager(mediaPlayer = mediaPlayer)
@ -54,7 +55,7 @@ class RedactedVoiceMessageManagerTest {
@Test
fun `redacted event - playing related media is paused`() = runTest {
val mediaPlayer = FakeMediaPlayer().apply {
setMedia(uri = "someUri", mediaId = AN_EVENT_ID.value, mimeType = "audio/ogg")
setMedia(uri = "someUri", mediaId = AN_EVENT_ID.value, mimeType = MimeTypes.Ogg)
play()
}
val manager = aDefaultRedactedVoiceMessageManager(mediaPlayer = mediaPlayer)