From b2a66ddafec9d899facfebb6f9b8350060ca6db4 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 26 May 2023 19:09:51 +0200 Subject: [PATCH] Media: handle PR review remarks --- .../element/android/features/messages/impl/MessagesView.kt | 2 +- .../messages/impl/media/viewer/MediaViewerPresenter.kt | 6 +++--- .../android/libraries/matrix/api/media/MatrixMediaLoader.kt | 2 +- .../android/libraries/matrix/impl/media/RustMediaLoader.kt | 2 +- .../android/libraries/matrix/test/media/FakeMediaLoader.kt | 2 +- .../android/libraries/matrix/ui/media/CoilMediaFetcher.kt | 3 +-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 7ec51dab3f..cdaa27cc52 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -105,7 +105,7 @@ fun MessagesView( initialValue = ModalBottomSheetValue.Hidden, ) val composerState = state.composerState - val initialBottomSheetState = if (LocalInspectionMode.current && composerState.showAttachmentSourcePicker != null) { + val initialBottomSheetState = if (LocalInspectionMode.current && composerState.showAttachmentSourcePicker) { ModalBottomSheetValue.Expanded } else { ModalBottomSheetValue.Hidden diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt index 01b562f62c..fb563461c5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt @@ -58,7 +58,7 @@ class MediaViewerPresenter @AssistedInject constructor( mutableStateOf(Async.Uninitialized) } DisposableEffect(loadMediaTrigger) { - coroutineScope.loadMedia(mediaFile, localMedia) + coroutineScope.downloadMedia(mediaFile, localMedia) onDispose { mediaFile.value?.close() } @@ -80,9 +80,9 @@ class MediaViewerPresenter @AssistedInject constructor( ) } - private fun CoroutineScope.loadMedia(mediaFile: MutableState, localMedia: MutableState>) = launch { + private fun CoroutineScope.downloadMedia(mediaFile: MutableState, localMedia: MutableState>) = launch { localMedia.value = Async.Loading() - mediaLoader.loadMediaFile(inputs.mediaSource, inputs.mimeType) + mediaLoader.downloadMediaFile(inputs.mediaSource, inputs.mimeType) .onSuccess { mediaFile.value = it }.mapCatching { diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt index 5dabef6d48..4d1d2445ce 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt @@ -36,5 +36,5 @@ interface MatrixMediaLoader { * @param mimeType: optional mime type * @return a [Result] of [MediaFile] */ - suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result + suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt index 5e9c26d6c6..9e4f2c53de 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt @@ -59,7 +59,7 @@ class RustMediaLoader( } } - override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result = + override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result = withContext(dispatchers.io) { runCatching { source.toRustMediaSource().use { mediaSource -> diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt index 266c81c605..96c49aa165 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt @@ -44,7 +44,7 @@ class FakeMediaLoader : MatrixMediaLoader { } } - override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result { + override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result { delay(FAKE_DELAY_IN_MS) return if (shouldFail) { Result.failure(RuntimeException()) diff --git a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt index a409b9de97..d638db2902 100644 --- a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt +++ b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt @@ -35,8 +35,7 @@ internal class CoilMediaFetcher( override suspend fun fetch(): FetchResult? { return loadMedia() .map { data -> - ByteBuffer.wrap(data) - }.map { byteBuffer -> + val byteBuffer = ByteBuffer.wrap(data) imageLoader.components.newFetcher(byteBuffer, options, imageLoader)?.first?.fetch() }.getOrThrow() }