Browse Source

Media: handle PR review remarks

feature/jme/open-room-member-details-when-clicking-on-user-data
ganfra 1 year ago
parent
commit
b2a66ddafe
  1. 2
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt
  2. 6
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt
  3. 2
      libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt
  4. 2
      libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt
  5. 2
      libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt
  6. 3
      libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt

2
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt

@ -105,7 +105,7 @@ fun MessagesView( @@ -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

6
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerPresenter.kt

@ -58,7 +58,7 @@ class MediaViewerPresenter @AssistedInject constructor( @@ -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( @@ -80,9 +80,9 @@ class MediaViewerPresenter @AssistedInject constructor(
)
}
private fun CoroutineScope.loadMedia(mediaFile: MutableState<MediaFile?>, localMedia: MutableState<Async<LocalMedia>>) = launch {
private fun CoroutineScope.downloadMedia(mediaFile: MutableState<MediaFile?>, localMedia: MutableState<Async<LocalMedia>>) = launch {
localMedia.value = Async.Loading()
mediaLoader.loadMediaFile(inputs.mediaSource, inputs.mimeType)
mediaLoader.downloadMediaFile(inputs.mediaSource, inputs.mimeType)
.onSuccess {
mediaFile.value = it
}.mapCatching {

2
libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/MatrixMediaLoader.kt

@ -36,5 +36,5 @@ interface MatrixMediaLoader { @@ -36,5 +36,5 @@ interface MatrixMediaLoader {
* @param mimeType: optional mime type
* @return a [Result] of [MediaFile]
*/
suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile>
suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile>
}

2
libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/RustMediaLoader.kt

@ -59,7 +59,7 @@ class RustMediaLoader( @@ -59,7 +59,7 @@ class RustMediaLoader(
}
}
override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> =
override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> =
withContext(dispatchers.io) {
runCatching {
source.toRustMediaSource().use { mediaSource ->

2
libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/media/FakeMediaLoader.kt

@ -44,7 +44,7 @@ class FakeMediaLoader : MatrixMediaLoader { @@ -44,7 +44,7 @@ class FakeMediaLoader : MatrixMediaLoader {
}
}
override suspend fun loadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> {
override suspend fun downloadMediaFile(source: MediaSource, mimeType: String?): Result<MediaFile> {
delay(FAKE_DELAY_IN_MS)
return if (shouldFail) {
Result.failure(RuntimeException())

3
libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/CoilMediaFetcher.kt

@ -35,8 +35,7 @@ internal class CoilMediaFetcher( @@ -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()
}

Loading…
Cancel
Save