Merge pull request #900 from vector-im/feature/fga/better_media_handling
Feature/fga/better media handling
This commit is contained in:
commit
d7cb8e076c
47 changed files with 402 additions and 77 deletions
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = false,
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@ import java.time.Duration
|
|||
data class AudioInfo(
|
||||
val duration: Duration?,
|
||||
val size: Long?,
|
||||
val mimeType: String?,
|
||||
val mimetype: String?,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -46,36 +46,43 @@ class MediaSender @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun MatrixRoom.sendMedia(
|
||||
info: MediaUploadInfo,
|
||||
uploadInfo: MediaUploadInfo,
|
||||
progressCallback: ProgressCallback?
|
||||
): Result<Unit> {
|
||||
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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
@ -196,7 +196,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
val info = AudioInfo(
|
||||
duration = extractDuration(),
|
||||
size = file.length(),
|
||||
mimeType = mimeType,
|
||||
mimetype = mimeType,
|
||||
)
|
||||
|
||||
MediaUploadInfo.Audio(file, info)
|
||||
|
|
|
|||
|
|
@ -483,7 +483,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",
|
||||
|
|
@ -501,7 +501,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",
|
||||
|
|
@ -519,7 +519,7 @@ fun TextComposerReplyPreview() = ElementPreview {
|
|||
senderName = "Alice",
|
||||
eventId = EventId("$1234"),
|
||||
attachmentThumbnailInfo = AttachmentThumbnailInfo(
|
||||
mediaSource = null,
|
||||
thumbnailSource = null,
|
||||
textContent = "logs.txt",
|
||||
type = AttachmentThumbnailType.File,
|
||||
blurHash = null,
|
||||
|
|
@ -537,7 +537,7 @@ fun TextComposerReplyPreview() = ElementPreview {
|
|||
senderName = "Alice",
|
||||
eventId = EventId("$1234"),
|
||||
attachmentThumbnailInfo = AttachmentThumbnailInfo(
|
||||
mediaSource = null,
|
||||
thumbnailSource = null,
|
||||
textContent = null,
|
||||
type = AttachmentThumbnailType.Location,
|
||||
blurHash = null,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue