From 7e5d339922dabd660e524804fa2a667e85fffa1a Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 13 Jul 2023 18:09:58 +0200 Subject: [PATCH 1/8] Media: render audio content --- .../messages/impl/MessagesPresenter.kt | 19 +-- .../impl/actionlist/ActionListView.kt | 21 +++- .../components/TimelineItemEventRow.kt | 15 +-- .../components/event/TimelineItemAudioView.kt | 108 ++++++++++++++++++ .../event/TimelineItemContentView.kt | 6 + .../TimelineItemContentMessageFactory.kt | 10 ++ .../impl/timeline/groups/Groupability.kt | 2 + .../model/event/TimelineItemAudioContent.kt | 33 ++++++ .../event/TimelineItemAudioContentProvider.kt | 39 +++++++ .../MessageSummaryFormatterImpl.kt | 2 + .../libraries/matrix/api/media/AudioInfo.kt | 2 +- .../libraries/matrix/impl/media/AudioInfo.kt | 4 +- .../ui/components/AttachmentThumbnail.kt | 21 ++-- .../mediaupload/AndroidMediaPreProcessor.kt | 2 +- .../libraries/textcomposer/TextComposer.kt | 8 +- 15 files changed, 257 insertions(+), 35 deletions(-) create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContent.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContentProvider.kt diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt index 841ccb8faa..ddc9f17262 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt @@ -43,6 +43,7 @@ import io.element.android.features.messages.impl.timeline.TimelinePresenter import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionPresenter import io.element.android.features.messages.impl.timeline.components.retrysendmenu.RetrySendMenuPresenter import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent @@ -108,10 +109,10 @@ class MessagesPresenter @AssistedInject constructor( val syncUpdateFlow = room.syncUpdateFlow.collectAsState() val userHasPermissionToSendMessage by room.canSendEventAsState(type = MessageEventType.ROOM_MESSAGE, updateKey = syncUpdateFlow.value) - val roomName by produceState(initialValue = room.displayName, key1 = syncUpdateFlow.value){ + val roomName by produceState(initialValue = room.displayName, key1 = syncUpdateFlow.value) { value = room.displayName } - val roomAvatar by produceState(initialValue = room.avatarData(), key1 = syncUpdateFlow.value){ + val roomAvatar by produceState(initialValue = room.avatarData(), key1 = syncUpdateFlow.value) { value = room.avatarData() } var hasDismissedInviteDialog by rememberSaveable { @@ -250,28 +251,28 @@ class MessagesPresenter @AssistedInject constructor( val textContent = messageSummaryFormatter.format(targetEvent) val attachmentThumbnailInfo = when (targetEvent.content) { is TimelineItemImageContent -> AttachmentThumbnailInfo( - mediaSource = targetEvent.content.mediaSource, + thumbnailSource = targetEvent.content.thumbnailSource, textContent = targetEvent.content.body, type = AttachmentThumbnailType.Image, blurHash = targetEvent.content.blurhash, ) is TimelineItemVideoContent -> AttachmentThumbnailInfo( - mediaSource = targetEvent.content.thumbnailSource, + thumbnailSource = targetEvent.content.thumbnailSource, textContent = targetEvent.content.body, type = AttachmentThumbnailType.Video, blurHash = targetEvent.content.blurHash, ) is TimelineItemFileContent -> AttachmentThumbnailInfo( - mediaSource = targetEvent.content.thumbnailSource, + thumbnailSource = targetEvent.content.thumbnailSource, textContent = targetEvent.content.body, type = AttachmentThumbnailType.File, - blurHash = null, + ) + is TimelineItemAudioContent -> AttachmentThumbnailInfo( + textContent = targetEvent.content.body, + type = AttachmentThumbnailType.Audio, ) is TimelineItemLocationContent -> AttachmentThumbnailInfo( - mediaSource = null, - textContent = null, type = AttachmentThumbnailType.Location, - blurHash = null, ) is TimelineItemTextBasedContent, is TimelineItemRedactedContent, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt index bb1f2a7ac8..c41f1006c8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt @@ -56,6 +56,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import io.element.android.features.messages.impl.actionlist.model.TimelineItemAction import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent @@ -246,7 +247,7 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif info = AttachmentThumbnailInfo( type = AttachmentThumbnailType.Location, textContent = stringResource(CommonStrings.common_shared_location), - mediaSource = null, + thumbnailSource = null, blurHash = null, ) ) @@ -258,7 +259,7 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif AttachmentThumbnail( modifier = imageModifier, info = AttachmentThumbnailInfo( - mediaSource = event.content.mediaSource, + thumbnailSource = event.content.mediaSource, textContent = textContent, type = AttachmentThumbnailType.File, blurHash = event.content.blurhash, @@ -272,7 +273,7 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif AttachmentThumbnail( modifier = imageModifier, info = AttachmentThumbnailInfo( - mediaSource = event.content.thumbnailSource, + thumbnailSource = event.content.thumbnailSource, textContent = textContent, type = AttachmentThumbnailType.Video, blurHash = event.content.blurHash, @@ -286,7 +287,7 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif AttachmentThumbnail( modifier = imageModifier, info = AttachmentThumbnailInfo( - mediaSource = null, + thumbnailSource = event.content.thumbnailSource, textContent = textContent, type = AttachmentThumbnailType.File, blurHash = null @@ -295,6 +296,18 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif } content = { ContentForBody(event.content.body) } } + is TimelineItemAudioContent -> { + icon = { + AttachmentThumbnail( + modifier = imageModifier, + info = AttachmentThumbnailInfo( + textContent = textContent, + type = AttachmentThumbnailType.Audio, + ) + ) + } + content = { ContentForBody(event.content.body) } + } } Row(modifier = modifier) { icon() diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt index 8d7ff263e8..fbb745c34e 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt @@ -56,7 +56,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.compose.ui.zIndex import androidx.constraintlayout.compose.ConstrainScope import androidx.constraintlayout.compose.ConstraintLayout @@ -85,6 +84,7 @@ import io.element.android.libraries.designsystem.text.toPx import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.UserId +import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType import io.element.android.libraries.matrix.api.timeline.item.event.InReplyTo @@ -521,28 +521,29 @@ private fun ReplyToContent( private fun attachmentThumbnailInfoForInReplyTo(inReplyTo: InReplyTo.Ready) = when (val type = inReplyTo.content.type) { is ImageMessageType -> AttachmentThumbnailInfo( - mediaSource = type.info?.thumbnailSource, + thumbnailSource = type.info?.thumbnailSource, textContent = inReplyTo.content.body, type = AttachmentThumbnailType.Image, blurHash = type.info?.blurhash, ) is VideoMessageType -> AttachmentThumbnailInfo( - mediaSource = type.info?.thumbnailSource, + thumbnailSource = type.info?.thumbnailSource, textContent = inReplyTo.content.body, type = AttachmentThumbnailType.Video, blurHash = type.info?.blurhash, ) is FileMessageType -> AttachmentThumbnailInfo( - mediaSource = type.info?.thumbnailSource, + thumbnailSource = type.info?.thumbnailSource, textContent = inReplyTo.content.body, type = AttachmentThumbnailType.File, - blurHash = null, ) is LocationMessageType -> AttachmentThumbnailInfo( - mediaSource = null, textContent = inReplyTo.content.body, type = AttachmentThumbnailType.Location, - blurHash = null, + ) + is AudioMessageType -> AttachmentThumbnailInfo( + textContent = inReplyTo.content.body, + type = AttachmentThumbnailType.Audio, ) else -> null } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt new file mode 100644 index 0000000000..3cae19e237 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.components.event + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Attachment +import androidx.compose.material.icons.outlined.GraphicEq +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContentProvider +import io.element.android.libraries.designsystem.preview.ElementPreviewDark +import io.element.android.libraries.designsystem.preview.ElementPreviewLight +import io.element.android.libraries.designsystem.theme.components.Icon +import io.element.android.libraries.designsystem.theme.components.Text +import io.element.android.libraries.theme.ElementTheme + +@Composable +fun TimelineItemAudioView( + content: TimelineItemAudioContent, + extraPadding: ExtraPadding, + modifier: Modifier = Modifier, +) { + Row( + modifier = modifier, + ) { + Box( + modifier = Modifier + .size(32.dp) + .clip(CircleShape) + .background(ElementTheme.materialColors.background), + contentAlignment = Alignment.Center, + ) { + Icon( + imageVector = Icons.Outlined.GraphicEq, + contentDescription = null, + tint = ElementTheme.materialColors.primary, + modifier = Modifier + .size(16.dp), + ) + } + Spacer(Modifier.width(8.dp)) + Column { + Text( + text = content.body, + color = ElementTheme.materialColors.primary, + maxLines = 2, + style = ElementTheme.typography.fontBodyLgRegular, + overflow = TextOverflow.Ellipsis + ) + Text( + text = content.fileExtensionAndSize + extraPadding.getStr(12.sp), + color = ElementTheme.materialColors.secondary, + style = ElementTheme.typography.fontBodySmRegular, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } +} + +@Preview +@Composable +internal fun TimelineItemAudioViewLightPreview(@PreviewParameter(TimelineItemAudioContentProvider::class) content: TimelineItemAudioContent) = + ElementPreviewLight { ContentToPreview(content) } + +@Preview +@Composable +internal fun TimelineItemAudioViewDarkPreview(@PreviewParameter(TimelineItemAudioContentProvider::class) content: TimelineItemAudioContent) = + ElementPreviewDark { ContentToPreview(content) } + +@Composable +private fun ContentToPreview(content: TimelineItemAudioContent) { + TimelineItemAudioView( + content, + extraPadding = noExtraPadding, + ) +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemContentView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemContentView.kt index 7d3f8835ca..3df45eb760 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemContentView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemContentView.kt @@ -19,6 +19,7 @@ package io.element.android.features.messages.impl.timeline.components.event import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent @@ -80,6 +81,11 @@ fun TimelineItemEventContentView( extraPadding = extraPadding, modifier = modifier ) + is TimelineItemAudioContent -> TimelineItemAudioView( + content = content, + extraPadding = extraPadding, + modifier = modifier + ) is TimelineItemStateContent -> TimelineItemStateView( content = content, modifier = modifier diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt index 9d4304cec0..9da31ee6a7 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentMessageFactory.kt @@ -17,6 +17,7 @@ package io.element.android.features.messages.impl.timeline.factories.event import io.element.android.features.location.api.Location +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEmoteContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent @@ -30,6 +31,7 @@ import io.element.android.features.messages.impl.timeline.util.FileExtensionExtr import io.element.android.features.messages.impl.timeline.util.toHtmlDocument import io.element.android.libraries.androidutils.filesize.FileSizeFormatter import io.element.android.libraries.core.mimetype.MimeTypes +import io.element.android.libraries.matrix.api.timeline.item.event.AudioMessageType import io.element.android.libraries.matrix.api.timeline.item.event.EmoteMessageType import io.element.android.libraries.matrix.api.timeline.item.event.FileMessageType import io.element.android.libraries.matrix.api.timeline.item.event.ImageMessageType @@ -99,6 +101,14 @@ class TimelineItemContentMessageFactory @Inject constructor( fileExtension = fileExtensionExtractor.extractFromName(messageType.body) ) } + is AudioMessageType -> TimelineItemAudioContent( + body = messageType.body, + audioSource = messageType.source, + duration = messageType.info?.duration?.toMillis() ?: 0L, + mimeType = messageType.info?.mimetype ?: MimeTypes.OctetStream, + formattedFileSize = fileSizeFormatter.format(messageType.info?.size ?: 0), + fileExtension = fileExtensionExtractor.extractFromName(messageType.body) + ) is FileMessageType -> TimelineItemFileContent( body = messageType.body, thumbnailSource = messageType.info?.thumbnailSource, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/groups/Groupability.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/groups/Groupability.kt index bf827a2b3d..0b8baf692a 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/groups/Groupability.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/groups/Groupability.kt @@ -17,6 +17,7 @@ package io.element.android.features.messages.impl.timeline.groups import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent @@ -52,6 +53,7 @@ internal fun TimelineItem.Event.canBeGrouped(): Boolean { is TimelineItemImageContent, is TimelineItemFileContent, is TimelineItemVideoContent, + is TimelineItemAudioContent, is TimelineItemLocationContent, TimelineItemRedactedContent, TimelineItemUnknownContent -> false diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContent.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContent.kt new file mode 100644 index 0000000000..485b863170 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContent.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.model.event + +import io.element.android.features.messages.impl.media.helper.formatFileExtensionAndSize +import io.element.android.libraries.matrix.api.media.MediaSource + +data class TimelineItemAudioContent( + val body: String, + val duration: Long, + val audioSource: MediaSource, + val mimeType: String, + val formattedFileSize: String, + val fileExtension: String, +) : TimelineItemEventContent { + + val fileExtensionAndSize = formatFileExtensionAndSize(fileExtension, formattedFileSize) + override val type: String = "TimelineItemAudioContent" +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContentProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContentProvider.kt new file mode 100644 index 0000000000..ed424781f8 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemAudioContentProvider.kt @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.model.event + +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import io.element.android.libraries.core.mimetype.MimeTypes +import io.element.android.libraries.matrix.api.media.MediaSource + +open class TimelineItemAudioContentProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + aTimelineItemAudioContent("A sound.mp3"), + aTimelineItemAudioContent("A bigger name sound.mp3"), + aTimelineItemAudioContent("An even bigger bigger bigger bigger bigger bigger bigger sound name which doesn't fit .mp3"), + ) +} + +fun aTimelineItemAudioContent(fileName: String = "A sound.mp3") = TimelineItemAudioContent( + body = fileName, + mimeType = MimeTypes.Pdf, + formattedFileSize = "100kB", + fileExtension = "mp3", + duration = 100, + audioSource = MediaSource(""), +) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/MessageSummaryFormatterImpl.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/MessageSummaryFormatterImpl.kt index e22aed6af9..42c50bbd9d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/MessageSummaryFormatterImpl.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/MessageSummaryFormatterImpl.kt @@ -19,6 +19,7 @@ package io.element.android.features.messages.impl.utils.messagesummary import android.content.Context import com.squareup.anvil.annotations.ContributesBinding import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent @@ -50,6 +51,7 @@ class MessageSummaryFormatterImpl @Inject constructor( is TimelineItemImageContent -> context.getString(CommonStrings.common_image) is TimelineItemVideoContent -> context.getString(CommonStrings.common_video) is TimelineItemFileContent -> context.getString(CommonStrings.common_file) + is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio) } } } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/AudioInfo.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/AudioInfo.kt index e9708a6926..bd4539bced 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/AudioInfo.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/media/AudioInfo.kt @@ -21,5 +21,5 @@ import java.time.Duration data class AudioInfo( val duration: Duration?, val size: Long?, - val mimeType: String?, + val mimetype: String?, ) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/AudioInfo.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/AudioInfo.kt index 2f0d6879a4..70c3bac6ed 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/AudioInfo.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/media/AudioInfo.kt @@ -22,11 +22,11 @@ import org.matrix.rustcomponents.sdk.AudioInfo as RustAudioInfo fun RustAudioInfo.map(): AudioInfo = AudioInfo( duration = duration, size = size?.toLong(), - mimeType = mimetype + mimetype = mimetype ) fun AudioInfo.map(): RustAudioInfo = RustAudioInfo( duration = duration, size = size?.toULong(), - mimetype = mimeType, + mimetype = mimetype, ) diff --git a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/AttachmentThumbnail.kt b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/AttachmentThumbnail.kt index cac211bcb5..71883ebc20 100644 --- a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/AttachmentThumbnail.kt +++ b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/AttachmentThumbnail.kt @@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Attachment +import androidx.compose.material.icons.outlined.GraphicEq import androidx.compose.material.icons.outlined.VideoCameraBack import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable @@ -44,9 +45,9 @@ fun AttachmentThumbnail( thumbnailSize: Long = 32L, backgroundColor: Color = MaterialTheme.colorScheme.surface, ) { - if (info.mediaSource != null) { + if (info.thumbnailSource != null) { val mediaRequestData = MediaRequestData( - source = info.mediaSource, + source = info.thumbnailSource, kind = MediaRequestData.Kind.Thumbnail(thumbnailSize), ) BlurHashAsyncImage( @@ -68,6 +69,12 @@ fun AttachmentThumbnail( contentDescription = info.textContent, ) } + AttachmentThumbnailType.Audio -> { + Icon( + imageVector = Icons.Outlined.GraphicEq, + contentDescription = info.textContent, + ) + } AttachmentThumbnailType.File -> { Icon( imageVector = Icons.Outlined.Attachment, @@ -88,13 +95,13 @@ fun AttachmentThumbnail( @Parcelize enum class AttachmentThumbnailType: Parcelable { - Image, Video, File, Location + Image, Video, File, Audio, Location } @Parcelize data class AttachmentThumbnailInfo( - val mediaSource: MediaSource?, - val textContent: String?, - val type: AttachmentThumbnailType?, - val blurHash: String?, + val type: AttachmentThumbnailType, + val thumbnailSource: MediaSource? = null, + val textContent: String? = null, + val blurHash: String? = null, ): Parcelable diff --git a/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt b/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt index 9482aecc13..f0cf6b9dcb 100644 --- a/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt +++ b/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt @@ -196,7 +196,7 @@ class AndroidMediaPreProcessor @Inject constructor( val info = AudioInfo( duration = extractDuration(), size = file.length(), - mimeType = mimeType, + mimetype = mimeType, ) MediaUploadInfo.Audio(file, info) diff --git a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt index b757f69f03..3994d8f55c 100644 --- a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt +++ b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt @@ -482,7 +482,7 @@ fun TextComposerReplyPreview() = ElementPreview { senderName = "Alice", eventId = EventId("$1234"), attachmentThumbnailInfo = AttachmentThumbnailInfo( - mediaSource = MediaSource("https://domain.com/image.jpg"), + thumbnailSource = MediaSource("https://domain.com/image.jpg"), textContent = "image.jpg", type = AttachmentThumbnailType.Image, blurHash = "TQF5:I_NtRE4kXt7Z#MwkCIARPjr", @@ -500,7 +500,7 @@ fun TextComposerReplyPreview() = ElementPreview { senderName = "Alice", eventId = EventId("$1234"), attachmentThumbnailInfo = AttachmentThumbnailInfo( - mediaSource = MediaSource("https://domain.com/video.mp4"), + thumbnailSource = MediaSource("https://domain.com/video.mp4"), textContent = "video.mp4", type = AttachmentThumbnailType.Video, blurHash = "TQF5:I_NtRE4kXt7Z#MwkCIARPjr", @@ -518,7 +518,7 @@ fun TextComposerReplyPreview() = ElementPreview { senderName = "Alice", eventId = EventId("$1234"), attachmentThumbnailInfo = AttachmentThumbnailInfo( - mediaSource = null, + thumbnailSource = null, textContent = "logs.txt", type = AttachmentThumbnailType.File, blurHash = null, @@ -536,7 +536,7 @@ fun TextComposerReplyPreview() = ElementPreview { senderName = "Alice", eventId = EventId("$1234"), attachmentThumbnailInfo = AttachmentThumbnailInfo( - mediaSource = null, + thumbnailSource = null, textContent = null, type = AttachmentThumbnailType.Location, blurHash = null, From 31abc20fc24a49154bff12d43ec4c1faa7da28fc Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 13 Jul 2023 20:34:07 +0200 Subject: [PATCH 2/8] Media: upload audio --- .../messages/impl/media/local/MediaInfo.kt | 2 +- .../MessageComposerPresenterTest.kt | 4 +-- .../edit/RoomDetailsEditPresenterTest.kt | 2 +- .../libraries/mediaupload/api/MediaSender.kt | 29 ++++++++++++------- .../mediaupload/api/MediaUploadInfo.kt | 8 ++--- .../mediaupload/AndroidMediaPreProcessor.kt | 6 ++-- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt index 2fc47e0d2c..3dede8e929 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt @@ -29,7 +29,7 @@ data class MediaInfo( ) : Parcelable fun anImageInfo(): MediaInfo = MediaInfo( - "an image file.jpg", MimeTypes.Jpeg, "4MB","jpg" + "an image file.jpg", MimeTypes.Jpeg, "4MB", "jpg" ) fun aVideoInfo(): MediaInfo = MediaInfo( diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/textcomposer/MessageComposerPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/textcomposer/MessageComposerPresenterTest.kt index 97bbf925bd..8391704701 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/textcomposer/MessageComposerPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/textcomposer/MessageComposerPresenterTest.kt @@ -324,7 +324,7 @@ class MessageComposerPresenterTest { Result.success( MediaUploadInfo.Image( file = File("/some/path"), - info = ImageInfo( + imageInfo = ImageInfo( width = null, height = null, mimetype = null, @@ -357,7 +357,7 @@ class MessageComposerPresenterTest { Result.success( MediaUploadInfo.Video( file = File("/some/path"), - info = VideoInfo( + videoInfo = VideoInfo( width = null, height = null, mimetype = null, diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/edit/RoomDetailsEditPresenterTest.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/edit/RoomDetailsEditPresenterTest.kt index df80f40e9b..20d253f3fb 100644 --- a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/edit/RoomDetailsEditPresenterTest.kt +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/edit/RoomDetailsEditPresenterTest.kt @@ -605,7 +605,7 @@ class RoomDetailsEditPresenterTest { Result.success( MediaUploadInfo.AnyFile( file = processedFile, - info = mockk(), + fileInfo = mockk(), ) ) ) diff --git a/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaSender.kt b/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaSender.kt index 6dab564b6e..cfa59d65d3 100644 --- a/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaSender.kt +++ b/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaSender.kt @@ -46,36 +46,43 @@ class MediaSender @Inject constructor( } private suspend fun MatrixRoom.sendMedia( - info: MediaUploadInfo, + uploadInfo: MediaUploadInfo, progressCallback: ProgressCallback? ): Result { - return when (info) { + return when (uploadInfo) { is MediaUploadInfo.Image -> { sendImage( - file = info.file, - thumbnailFile = info.thumbnailFile, - imageInfo = info.info, + file = uploadInfo.file, + thumbnailFile = uploadInfo.thumbnailFile, + imageInfo = uploadInfo.imageInfo, progressCallback = progressCallback ) } is MediaUploadInfo.Video -> { sendVideo( - file = info.file, - thumbnailFile = info.thumbnailFile, - videoInfo = info.info, + file = uploadInfo.file, + thumbnailFile = uploadInfo.thumbnailFile, + videoInfo = uploadInfo.videoInfo, + progressCallback = progressCallback + ) + } + is MediaUploadInfo.Audio -> { + sendAudio( + file = uploadInfo.file, + audioInfo = uploadInfo.audioInfo, progressCallback = progressCallback ) } is MediaUploadInfo.AnyFile -> { sendFile( - file = info.file, - fileInfo = info.info, + file = uploadInfo.file, + fileInfo = uploadInfo.fileInfo, progressCallback = progressCallback ) } - else -> Result.failure(IllegalStateException("Unexpected MediaUploadInfo format: $info")) + else -> Result.failure(IllegalStateException("Unexpected MediaUploadInfo format: $uploadInfo")) } } } diff --git a/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaUploadInfo.kt b/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaUploadInfo.kt index 5da3d36c44..51f6372b23 100644 --- a/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaUploadInfo.kt +++ b/libraries/mediaupload/api/src/main/kotlin/io/element/android/libraries/mediaupload/api/MediaUploadInfo.kt @@ -26,8 +26,8 @@ sealed interface MediaUploadInfo { val file: File - data class Image(override val file: File, val info: ImageInfo, val thumbnailFile: File) : MediaUploadInfo - data class Video(override val file: File, val info: VideoInfo, val thumbnailFile: File) : MediaUploadInfo - data class Audio(override val file: File, val info: AudioInfo) : MediaUploadInfo - data class AnyFile(override val file: File, val info: FileInfo) : MediaUploadInfo + data class Image(override val file: File, val imageInfo: ImageInfo, val thumbnailFile: File) : MediaUploadInfo + data class Video(override val file: File, val videoInfo: VideoInfo, val thumbnailFile: File) : MediaUploadInfo + data class Audio(override val file: File, val audioInfo: AudioInfo) : MediaUploadInfo + data class AnyFile(override val file: File, val fileInfo: FileInfo) : MediaUploadInfo } diff --git a/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt b/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt index f0cf6b9dcb..8ff40fae39 100644 --- a/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt +++ b/libraries/mediaupload/impl/src/main/kotlin/io/element/android/libraries/mediaupload/AndroidMediaPreProcessor.kt @@ -133,7 +133,7 @@ class AndroidMediaPreProcessor @Inject constructor( removeSensitiveImageMetadata(compressionResult.file) return MediaUploadInfo.Image( file = compressionResult.file, - info = imageInfo, + imageInfo = imageInfo, thumbnailFile = thumbnailResult.file ) } @@ -156,7 +156,7 @@ class AndroidMediaPreProcessor @Inject constructor( removeSensitiveImageMetadata(file) return MediaUploadInfo.Image( file = file, - info = imageInfo, + imageInfo = imageInfo, thumbnailFile = thumbnailResult.file ) } @@ -184,7 +184,7 @@ class AndroidMediaPreProcessor @Inject constructor( val videoInfo = extractVideoMetadata(resultFile, mimeType, thumbnailInfo) return MediaUploadInfo.Video( file = resultFile, - info = videoInfo, + videoInfo = videoInfo, thumbnailFile = thumbnailInfo.file ) } From 20643c1f89a809258296110274a69380bdb6dedc Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 13 Jul 2023 21:55:49 +0200 Subject: [PATCH 3/8] Media: show audio in LocalMediaView (as a file for now...) --- .../features/messages/impl/MessagesFlowNode.kt | 15 +++++++++++++++ .../messages/impl/media/local/LocalMediaView.kt | 10 +++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt index 1593c19afc..da10171d0a 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt @@ -41,6 +41,7 @@ import io.element.android.features.messages.impl.media.viewer.MediaViewerNode import io.element.android.features.messages.impl.report.ReportMessageNode import io.element.android.features.messages.impl.timeline.debug.EventDebugInfoNode import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemImageContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLocationContent @@ -224,6 +225,20 @@ class MessagesFlowNode @AssistedInject constructor( ) backstack.push(navTarget) } + is TimelineItemAudioContent -> { + val mediaSource = event.content.audioSource + val navTarget = NavTarget.MediaViewer( + mediaInfo = MediaInfo( + name = event.content.body, + mimeType = event.content.mimeType, + formattedFileSize = event.content.formattedFileSize, + fileExtension = event.content.fileExtension + ), + mediaSource = mediaSource, + thumbnailSource = null, + ) + backstack.push(navTarget) + } is TimelineItemLocationContent -> { val navTarget = NavTarget.LocationViewer( location = event.content.location, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/LocalMediaView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/LocalMediaView.kt index 3d2b1da222..ff17029497 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/LocalMediaView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/LocalMediaView.kt @@ -32,6 +32,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Attachment +import androidx.compose.material.icons.outlined.GraphicEq import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -47,7 +48,6 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.compose.ui.viewinterop.AndroidView import androidx.lifecycle.Lifecycle import androidx.media3.common.MediaItem @@ -59,7 +59,9 @@ import io.element.android.features.messages.impl.media.helper.formatFileExtensio import io.element.android.features.messages.impl.media.local.exoplayer.ExoPlayerWrapper import io.element.android.features.messages.impl.media.local.pdf.PdfViewer import io.element.android.features.messages.impl.media.local.pdf.rememberPdfViewerState +import io.element.android.libraries.core.bool.orFalse import io.element.android.libraries.core.mimetype.MimeTypes +import io.element.android.libraries.core.mimetype.MimeTypes.isMimeTypeAudio import io.element.android.libraries.core.mimetype.MimeTypes.isMimeTypeImage import io.element.android.libraries.core.mimetype.MimeTypes.isMimeTypeVideo import io.element.android.libraries.designsystem.R @@ -103,6 +105,7 @@ fun LocalMediaView( zoomableState = zoomableState, modifier = modifier ) + //TODO handle audio with exoplayer else -> MediaFileView( localMediaViewState = localMediaViewState, uri = localMedia?.uri, @@ -215,6 +218,7 @@ fun MediaFileView( info: MediaInfo?, modifier: Modifier = Modifier, ) { + val isAudio = info?.mimeType.isMimeTypeAudio().orFalse() localMediaViewState.isReady = uri != null Box(modifier = modifier.padding(horizontal = 8.dp), contentAlignment = Alignment.Center) { Column(horizontalAlignment = Alignment.CenterHorizontally) { @@ -226,12 +230,12 @@ fun MediaFileView( contentAlignment = Alignment.Center, ) { Icon( - imageVector = Icons.Outlined.Attachment, + imageVector = if (isAudio) Icons.Outlined.GraphicEq else Icons.Outlined.Attachment, contentDescription = null, tint = MaterialTheme.colorScheme.background, modifier = Modifier .size(32.dp) - .rotate(-45f), + .rotate(if (isAudio) 0f else -45f), ) } if (info != null) { From f66c3eb233611aad4f07f20b6710a147b4f4e2c0 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 13 Jul 2023 22:00:29 +0200 Subject: [PATCH 4/8] Media: add audio fixture for tests --- .../features/messages/impl/media/local/MediaInfo.kt | 4 ++++ .../impl/media/viewer/MediaViewerStateProvider.kt | 13 ++++++++++++- .../android/libraries/core/mimetype/MimeTypes.kt | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt index 3dede8e929..af0f142bd8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/local/MediaInfo.kt @@ -43,3 +43,7 @@ fun aPdfInfo(): MediaInfo = MediaInfo( fun aFileInfo(): MediaInfo = MediaInfo( "an apk file.apk", MimeTypes.Apk, "50MB", "apk" ) + +fun anAudioInfo(): MediaInfo = MediaInfo( + "an audio file.mp3", MimeTypes.Mp3, "7MB", "mp3" +) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerStateProvider.kt index 786ec984b7..820a34d8d4 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/media/viewer/MediaViewerStateProvider.kt @@ -23,6 +23,7 @@ import io.element.android.features.messages.impl.media.local.MediaInfo import io.element.android.features.messages.impl.media.local.aFileInfo import io.element.android.features.messages.impl.media.local.aPdfInfo import io.element.android.features.messages.impl.media.local.aVideoInfo +import io.element.android.features.messages.impl.media.local.anAudioInfo import io.element.android.features.messages.impl.media.local.anImageInfo import io.element.android.libraries.architecture.Async @@ -59,7 +60,17 @@ open class MediaViewerStateProvider : PreviewParameterProvider LocalMedia(Uri.EMPTY, aFileInfo()) ), aFileInfo(), - ) + ), + aMediaViewerState( + Async.Loading(), + anAudioInfo(), + ), + aMediaViewerState( + Async.Success( + LocalMedia(Uri.EMPTY, anAudioInfo()) + ), + anAudioInfo(), + ), ) } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/mimetype/MimeTypes.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/mimetype/MimeTypes.kt index 637d2c056c..c6373fbbf6 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/mimetype/MimeTypes.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/mimetype/MimeTypes.kt @@ -38,6 +38,7 @@ object MimeTypes { const val Audio = "audio/*" const val Ogg = "audio/ogg" + const val Mp3 = "audio/mp3" const val PlainText = "text/plain" From c4d09388395683812ff3797822b7596fb58b5541 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 13 Jul 2023 23:49:55 +0200 Subject: [PATCH 5/8] ProgressDialog: add cancelable... --- .../designsystem/components/ProgressDialog.kt | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ProgressDialog.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ProgressDialog.kt index 140ab131ef..0154fb9252 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ProgressDialog.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ProgressDialog.kt @@ -20,14 +20,17 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.Immutable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog @@ -37,21 +40,32 @@ import io.element.android.libraries.designsystem.preview.ElementThemedPreview import io.element.android.libraries.designsystem.preview.PreviewGroup import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator import io.element.android.libraries.designsystem.theme.components.Text +import io.element.android.libraries.designsystem.theme.components.TextButton +import io.element.android.libraries.ui.strings.CommonStrings +import timber.log.Timber @Composable fun ProgressDialog( modifier: Modifier = Modifier, text: String? = null, type: ProgressDialogType = ProgressDialogType.Indeterminate, - onDismiss: () -> Unit = {}, + isCancellable: Boolean = false, + onDismissRequest: () -> Unit = {}, ) { + DisposableEffect(Unit) { + onDispose { + Timber.v("OnDispose progressDialog") + } + } Dialog( - onDismissRequest = onDismiss, + onDismissRequest = onDismissRequest, properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false) ) { ProgressDialogContent( modifier = modifier, text = text, + isCancellable = isCancellable, + onCancelClicked = onDismissRequest, progressIndicator = { when (type) { is ProgressDialogType.Indeterminate -> { @@ -81,6 +95,8 @@ sealed interface ProgressDialogType { private fun ProgressDialogContent( modifier: Modifier = Modifier, text: String? = null, + isCancellable: Boolean = true, + onCancelClicked: () -> Unit = {}, progressIndicator: @Composable () -> Unit = { CircularProgressIndicator( color = MaterialTheme.colorScheme.primary @@ -107,6 +123,17 @@ private fun ProgressDialogContent( color = MaterialTheme.colorScheme.primary, ) } + if (isCancellable) { + Spacer(modifier = Modifier.height(24.dp)) + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.BottomEnd + ) { + TextButton(onClick = onCancelClicked) { + Text(stringResource(id = CommonStrings.action_cancel)) + } + } + } } } } From c9b3b3f83fbbf72841a26fc729d9eb8784a21d5d Mon Sep 17 00:00:00 2001 From: ElementBot Date: Tue, 18 Jul 2023 12:35:42 +0000 Subject: [PATCH 6/8] Update screenshots --- ...Group_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png | 4 ++-- ...Group_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png | 4 ++-- ...up_MediaViewerViewDarkPreview_0_null_8,NEXUS_5,1.0,en].png | 3 +++ ...up_MediaViewerViewDarkPreview_0_null_9,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewDarkPreview_0_null_0,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewDarkPreview_0_null_1,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewDarkPreview_0_null_2,NEXUS_5,1.0,en].png | 3 +++ ...lineItemAudioViewLightPreview_0_null_0,NEXUS_5,1.0,en].png | 3 +++ ...lineItemAudioViewLightPreview_0_null_1,NEXUS_5,1.0,en].png | 3 +++ ...lineItemAudioViewLightPreview_0_null_2,NEXUS_5,1.0,en].png | 3 +++ ...l_Dialogs_ProgressDialogPreview_0_null,NEXUS_5,1.0,en].png | 4 ++-- 11 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_8,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_9,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_0,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_1,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_2,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_0,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_1,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_2,NEXUS_5,1.0,en].png diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png index b0937d3b09..0905a820cb 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e4bcce9d53c7c094698f07de6c6a25be2c7831707581861df4b0cdf0c3d6d1fd -size 40906 +oid sha256:16e955d418eadb90cf9952d18b87669e03c50d5b166e0fee1d193a733e48372d +size 39775 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png index 6cc64a9ea3..579b7a76dd 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9bb3eab588d8cc20eb2bcbbcb8a7acdf6431299bf575a124ed7aff8a4fe6cd15 -size 39182 +oid sha256:5c9f0a9aa7cb0b1665eae95564a189c6752c707dce195979076b0504eac497a1 +size 38170 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_8,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_8,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..8aea9ffda4 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_8,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1805563eccf45f507152722511cacfa3f0411d1ccb90dd8d539f9a4a697b56f +size 14459 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_9,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_9,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..48767dad09 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.media.viewer_null_DefaultGroup_MediaViewerViewDarkPreview_0_null_9,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2824676afbff473eff8c8cfbcf8b3e58b2851e37324c6a8d9ba47d626b0f8bc +size 14234 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_0,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..e0136f4c31 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_0,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b83378cdfb20b5ffc781fc514c5a4d3aaa0714101b12a572f032f92ec13180c +size 9776 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_1,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..9f9e9a32fc --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_1,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40d1ea7620f7f830f52b87fbe32d39d4c01ddeeeb10535da17f7207acc80a1d6 +size 11821 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_2,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..179c04456a --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewDarkPreview_0_null_2,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11e2a8b0a79c56b379d387a3987362d5309e7f30903b940994ed43217de1380d +size 21441 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_0,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..53bfbe6d54 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_0,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e00510a5f35eb33aaef15c30e6caac62045d8e4c37c032a24922bbb749ad0375 +size 9817 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_1,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..9ce9173802 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_1,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:229d83ed02804137ab1dad4114eecc6d52d6a0e3ccbad436cf226f6cfc628cf7 +size 12200 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_2,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..77a65f3b40 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewLightPreview_0_null_2,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27fff9f0ea88cf06934298ea6155cbf4dd49c370cc5d0a14b4d387ac8a7e7c39 +size 23203 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.libraries.designsystem.components_null_Dialogs_ProgressDialogPreview_0_null,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.libraries.designsystem.components_null_Dialogs_ProgressDialogPreview_0_null,NEXUS_5,1.0,en].png index af63d0ef73..9d7ab1352b 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.libraries.designsystem.components_null_Dialogs_ProgressDialogPreview_0_null,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.libraries.designsystem.components_null_Dialogs_ProgressDialogPreview_0_null,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:10b9570b3f00b7ad9fa473bd5de8568fc4e3305fc3ad5d6d3bec9cb40a1fbe46 -size 20350 +oid sha256:22747c979bf704a554dfa4ee3ace1551e78f1180bc594c55f1497ec1d6529aa2 +size 21211 From fa0aeccf229cc527f93b8976e4597aa97a33ddf5 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 18 Jul 2023 16:38:36 +0200 Subject: [PATCH 7/8] Media: Clean after pr reviews --- .../impl/actionlist/ActionListView.kt | 5 +-- .../components/event/TimelineItemAudioView.kt | 31 ++++++------------- .../event/TimelineItemEventContentProvider.kt | 2 +- .../event/TimelineItemFileContentProvider.kt | 4 +-- .../event/TimelineItemVideoContentProvider.kt | 2 +- .../designsystem/components/ProgressDialog.kt | 4 +-- 6 files changed, 17 insertions(+), 31 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt index c41f1006c8..fd2ad94345 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt @@ -247,8 +247,6 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif info = AttachmentThumbnailInfo( type = AttachmentThumbnailType.Location, textContent = stringResource(CommonStrings.common_shared_location), - thumbnailSource = null, - blurHash = null, ) ) } @@ -261,7 +259,7 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif info = AttachmentThumbnailInfo( thumbnailSource = event.content.mediaSource, textContent = textContent, - type = AttachmentThumbnailType.File, + type = AttachmentThumbnailType.Image, blurHash = event.content.blurhash, ) ) @@ -290,7 +288,6 @@ private fun MessageSummary(event: TimelineItem.Event, modifier: Modifier = Modif thumbnailSource = event.content.thumbnailSource, textContent = textContent, type = AttachmentThumbnailType.File, - blurHash = null ) ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt index 3cae19e237..f96290cb51 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event/TimelineItemAudioView.kt @@ -25,22 +25,19 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.Attachment import androidx.compose.material.icons.outlined.GraphicEq import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.draw.rotate import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContentProvider -import io.element.android.libraries.designsystem.preview.ElementPreviewDark -import io.element.android.libraries.designsystem.preview.ElementPreviewLight +import io.element.android.libraries.designsystem.preview.DayNightPreviews +import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.theme.components.Icon import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.theme.ElementTheme @@ -89,20 +86,12 @@ fun TimelineItemAudioView( } } -@Preview +@DayNightPreviews @Composable -internal fun TimelineItemAudioViewLightPreview(@PreviewParameter(TimelineItemAudioContentProvider::class) content: TimelineItemAudioContent) = - ElementPreviewLight { ContentToPreview(content) } - -@Preview -@Composable -internal fun TimelineItemAudioViewDarkPreview(@PreviewParameter(TimelineItemAudioContentProvider::class) content: TimelineItemAudioContent) = - ElementPreviewDark { ContentToPreview(content) } - -@Composable -private fun ContentToPreview(content: TimelineItemAudioContent) { - TimelineItemAudioView( - content, - extraPadding = noExtraPadding, - ) -} +internal fun TimelineItemAudioViewPreview(@PreviewParameter(TimelineItemAudioContentProvider::class) content: TimelineItemAudioContent) = + ElementPreview { + TimelineItemAudioView( + content, + extraPadding = noExtraPadding, + ) + } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt index 85b739cd80..4c25bdfb23 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemEventContentProvider.kt @@ -26,7 +26,7 @@ class TimelineItemEventContentProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( - aTimelineItemFileContent("A file.pdf"), + aTimelineItemFileContent(), aTimelineItemFileContent("A bigger name file.pdf"), aTimelineItemFileContent("An even bigger bigger bigger bigger bigger bigger bigger file name which doesn't fit .pdf"), ) @@ -31,7 +31,7 @@ open class TimelineItemFileContentProvider : PreviewParameterProvider Unit = {}, progressIndicator: @Composable () -> Unit = { CircularProgressIndicator( @@ -145,6 +145,6 @@ internal fun ProgressDialogPreview() = ElementThemedPreview { ContentToPreview() @Composable private fun ContentToPreview() { DialogPreview { - ProgressDialogContent(text = "test dialog content") + ProgressDialogContent(text = "test dialog content", isCancellable = true) } } From 03013d5c2a4a17f970d79c32cdba788d502893d8 Mon Sep 17 00:00:00 2001 From: ElementBot Date: Tue, 18 Jul 2023 14:51:59 +0000 Subject: [PATCH 8/8] Update screenshots --- ...Group_SheetContentPreview-D-0_1_null_4,NEXUS_5,1.0,en].png | 4 ++-- ...Group_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png | 4 ++-- ...Group_SheetContentPreview-N-0_2_null_4,NEXUS_5,1.0,en].png | 4 ++-- ...Group_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png | 4 ++-- ...elineItemAudioViewPreview-D-7_8_null_0,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewPreview-D-7_8_null_1,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewPreview-D-7_8_null_2,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewPreview-N-7_9_null_0,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewPreview-N-7_9_null_1,NEXUS_5,1.0,en].png | 3 +++ ...elineItemAudioViewPreview-N-7_9_null_2,NEXUS_5,1.0,en].png | 3 +++ ...tedHistoryBannerViewPreview-D-8_9_null,NEXUS_5,1.0,en].png | 3 +++ ...edHistoryBannerViewPreview-N-8_10_null,NEXUS_5,1.0,en].png | 3 +++ 12 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_0,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_1,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_2,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_0,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_1,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_2,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-D-8_9_null,NEXUS_5,1.0,en].png create mode 100644 tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-N-8_10_null,NEXUS_5,1.0,en].png diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_4,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_4,NEXUS_5,1.0,en].png index 17f4410180..f9c5109ceb 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_4,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_4,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a667744cd675695d67f5b402101f2ce72318fcc9311933300a83cf86bf3b2c19 -size 47473 +oid sha256:e456ca95ee33cf14cac839b2b57879d17ca47b156da65c8a870882a90ef2c84c +size 40664 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png index 0905a820cb..b0937d3b09 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-D-0_1_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:16e955d418eadb90cf9952d18b87669e03c50d5b166e0fee1d193a733e48372d -size 39775 +oid sha256:e4bcce9d53c7c094698f07de6c6a25be2c7831707581861df4b0cdf0c3d6d1fd +size 40906 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_4,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_4,NEXUS_5,1.0,en].png index 9b6329a89b..410fe4da24 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_4,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_4,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:64a8da63cd27373a61e788cdf569e05f1608ab32bebffd2651755d5a3345c37c -size 45752 +oid sha256:66a7d55b40a9d5d7bc02f531bd3c80a1ba96e24a619c123f68549df355019558 +size 38989 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png index 579b7a76dd..6cc64a9ea3 100644 --- a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.actionlist_null_DefaultGroup_SheetContentPreview-N-0_2_null_5,NEXUS_5,1.0,en].png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5c9f0a9aa7cb0b1665eae95564a189c6752c707dce195979076b0504eac497a1 -size 38170 +oid sha256:9bb3eab588d8cc20eb2bcbbcb8a7acdf6431299bf575a124ed7aff8a4fe6cd15 +size 39182 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_0,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..53bfbe6d54 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_0,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e00510a5f35eb33aaef15c30e6caac62045d8e4c37c032a24922bbb749ad0375 +size 9817 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_1,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..9ce9173802 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_1,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:229d83ed02804137ab1dad4114eecc6d52d6a0e3ccbad436cf226f6cfc628cf7 +size 12200 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_2,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..77a65f3b40 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-D-7_8_null_2,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27fff9f0ea88cf06934298ea6155cbf4dd49c370cc5d0a14b4d387ac8a7e7c39 +size 23203 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_0,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_0,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..c02a4d8bf8 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_0,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ba5f5fefedaaf994fb2eae3df38724b245e27a1b03d48cb20d33f7ca49caa356 +size 9458 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_1,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_1,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..d636a6b668 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_1,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19ce1d8ddd69760417e267cda7d4663b44d7a50f8ef1a5617497e1135f8aa586 +size 11500 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_2,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_2,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..6db46605ae --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.event_null_DefaultGroup_TimelineItemAudioViewPreview-N-7_9_null_2,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e589a013be7a4b54e3f91816565dd38a05086c19d9832480713d895b1462e72 +size 20864 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-D-8_9_null,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-D-8_9_null,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..45593d6af2 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-D-8_9_null,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c806ee0293d94ab1c882b0f0ceaac2c7ac69d587f47cc22b4d16bc331351a2e +size 14711 diff --git a/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-N-8_10_null,NEXUS_5,1.0,en].png b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-N-8_10_null,NEXUS_5,1.0,en].png new file mode 100644 index 0000000000..c74bbe95f8 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/io.element.android.tests.uitests_ScreenshotTest_preview_tests[io.element.android.features.messages.impl.timeline.components.virtual_null_DefaultGroup_TimelineEncryptedHistoryBannerViewPreview-N-8_10_null,NEXUS_5,1.0,en].png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77c97c6c99943858530219234356459a7f0a88774332a4f11cd738b92ee15c91 +size 14200