Use MimeTypes object instead of hard-coded strings.
This commit is contained in:
parent
9059126b2e
commit
1df3817808
14 changed files with 37 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import androidx.annotation.ChecksSdkIntAtLeast
|
|||
import androidx.annotation.RequiresApi
|
||||
import io.element.android.libraries.androidutils.R
|
||||
import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
|
||||
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
|
||||
fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
|
|
@ -125,7 +126,7 @@ fun Context.startSharePlainTextIntent(
|
|||
noActivityFoundMessage: String = getString(R.string.error_no_compatible_app_found),
|
||||
) {
|
||||
val share = Intent(Intent.ACTION_SEND)
|
||||
share.type = "text/plain"
|
||||
share.type = MimeTypes.PlainText
|
||||
share.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
|
||||
// Add data to the intent, the receiving app will decide what to do with it.
|
||||
share.putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.element.android.libraries.mediaupload.api
|
|||
|
||||
import android.net.Uri
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
|
||||
import io.element.android.libraries.mediaupload.test.FakeMediaPreProcessor
|
||||
|
|
@ -39,7 +40,7 @@ class MediaSenderTests {
|
|||
val sender = aMediaSender(preProcessor)
|
||||
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
sender.sendMedia(uri = uri, mimeType = "image/jpeg", compressIfPossible = true)
|
||||
sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg, compressIfPossible = true)
|
||||
|
||||
assertThat(preProcessor.processCallCount).isEqualTo(1)
|
||||
}
|
||||
|
|
@ -50,7 +51,7 @@ class MediaSenderTests {
|
|||
val sender = aMediaSender(room = room)
|
||||
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
sender.sendMedia(uri = uri, mimeType = "image/jpeg", compressIfPossible = true)
|
||||
sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg, compressIfPossible = true)
|
||||
|
||||
assertThat(room.sendMediaCount).isEqualTo(1)
|
||||
}
|
||||
|
|
@ -63,7 +64,7 @@ class MediaSenderTests {
|
|||
val sender = aMediaSender(preProcessor)
|
||||
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
val result = sender.sendMedia(uri = uri, mimeType = "image/jpeg", compressIfPossible = true)
|
||||
val result = sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg, compressIfPossible = true)
|
||||
|
||||
assertThat(result.exceptionOrNull()).isNotNull()
|
||||
}
|
||||
|
|
@ -76,7 +77,7 @@ class MediaSenderTests {
|
|||
val sender = aMediaSender(room = room)
|
||||
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
val result = sender.sendMedia(uri = uri, mimeType = "image/jpeg", compressIfPossible = true)
|
||||
val result = sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg, compressIfPossible = true)
|
||||
|
||||
assertThat(result.exceptionOrNull()).isNotNull()
|
||||
}
|
||||
|
|
@ -88,7 +89,7 @@ class MediaSenderTests {
|
|||
val sender = aMediaSender(room = room)
|
||||
val sendJob = launch {
|
||||
val uri = Uri.parse("content://image.jpg")
|
||||
sender.sendMedia(uri = uri, mimeType = "image/jpeg", compressIfPossible = true)
|
||||
sender.sendMedia(uri = uri, mimeType = MimeTypes.Jpeg, compressIfPossible = true)
|
||||
}
|
||||
// Wait until several internal tasks run and the file is being uploaded
|
||||
advanceTimeBy(3L)
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ android {
|
|||
|
||||
dependencies {
|
||||
api(projects.libraries.mediaupload.api)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(projects.tests.testutils)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.libraries.mediaupload.test
|
||||
|
||||
import android.net.Uri
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
import io.element.android.libraries.matrix.api.media.AudioInfo
|
||||
import io.element.android.libraries.matrix.api.media.FileInfo
|
||||
import io.element.android.libraries.mediaupload.api.MediaPreProcessor
|
||||
|
|
@ -34,7 +35,7 @@ class FakeMediaPreProcessor : MediaPreProcessor {
|
|||
MediaUploadInfo.AnyFile(
|
||||
File("test"),
|
||||
FileInfo(
|
||||
mimetype = "*/*",
|
||||
mimetype = MimeTypes.Any,
|
||||
size = 999L,
|
||||
thumbnailInfo = null,
|
||||
thumbnailSource = null,
|
||||
|
|
@ -64,7 +65,7 @@ class FakeMediaPreProcessor : MediaPreProcessor {
|
|||
audioInfo = AudioInfo(
|
||||
duration = 1000.seconds,
|
||||
size = 1000,
|
||||
mimetype = "audio/ogg",
|
||||
mimetype = MimeTypes.Ogg,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.media.MediaRecorder
|
|||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.voicerecorder.impl.audio.AudioConfig
|
||||
import io.element.android.libraries.voicerecorder.impl.audio.SampleRate
|
||||
|
|
@ -50,7 +51,7 @@ object VoiceRecorderModule {
|
|||
VoiceFileConfig(
|
||||
cacheSubdir = "voice_recordings",
|
||||
fileExt = "ogg",
|
||||
mimeType = "audio/ogg",
|
||||
mimeType = MimeTypes.Ogg,
|
||||
)
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import android.media.MediaRecorder
|
|||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.appconfig.VoiceMessageConfig
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
import io.element.android.libraries.voicerecorder.api.VoiceRecorderState
|
||||
import io.element.android.libraries.voicerecorder.impl.audio.Audio
|
||||
import io.element.android.libraries.voicerecorder.impl.audio.AudioConfig
|
||||
|
|
@ -85,7 +86,7 @@ class VoiceRecorderImplTest {
|
|||
assertThat(awaitItem()).isEqualTo(
|
||||
VoiceRecorderState.Finished(
|
||||
file = File(FILE_PATH),
|
||||
mimeType = "audio/ogg",
|
||||
mimeType = MimeTypes.Ogg,
|
||||
waveform = List(100) { 1f },
|
||||
duration = VoiceMessageConfig.maxVoiceMessageDuration,
|
||||
)
|
||||
|
|
@ -107,7 +108,7 @@ class VoiceRecorderImplTest {
|
|||
assertThat(awaitItem()).isEqualTo(
|
||||
VoiceRecorderState.Finished(
|
||||
file = File(FILE_PATH),
|
||||
mimeType = "audio/ogg",
|
||||
mimeType = MimeTypes.Ogg,
|
||||
waveform = List(100) { 1f },
|
||||
duration = 5.seconds,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,4 +28,5 @@ dependencies {
|
|||
|
||||
implementation(libs.coroutines.test)
|
||||
implementation(libs.test.truth)
|
||||
implementation(projects.libraries.core)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.libraries.voicerecorder.test
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||
import io.element.android.libraries.voicerecorder.api.VoiceRecorder
|
||||
import io.element.android.libraries.voicerecorder.api.VoiceRecorderState
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
|
@ -73,7 +74,7 @@ class FakeVoiceRecorder(
|
|||
null -> VoiceRecorderState.Idle
|
||||
else -> VoiceRecorderState.Finished(
|
||||
file = curRecording!!,
|
||||
mimeType = "audio/ogg",
|
||||
mimeType = MimeTypes.Ogg,
|
||||
duration = recordingDuration,
|
||||
waveform = waveform,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue