From 9c02c4cfdeea1cc1d34c9c06348db638974baac1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 6 Dec 2024 10:02:16 +0100 Subject: [PATCH] MediaViewer: Align title to left and move action bottom to top bar. --- .../impl/viewer/MediaViewerView.kt | 90 ++++++++----------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/viewer/MediaViewerView.kt b/libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/viewer/MediaViewerView.kt index cdcc6f9fb2..d802aac778 100644 --- a/libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/viewer/MediaViewerView.kt +++ b/libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/viewer/MediaViewerView.kt @@ -17,8 +17,6 @@ import androidx.compose.animation.fadeOut 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -117,6 +115,9 @@ fun MediaViewerView( ) { MediaViewerTopBar( actionsEnabled = state.downloadedMedia is AsyncData.Success, + canDownload = state.canDownload, + canShare = state.canShare, + mimeType = state.mediaInfo.mimeType, senderName = state.mediaInfo.senderName, dateSent = state.mediaInfo.dateSent, onBackClick = onBackClick, @@ -124,13 +125,8 @@ fun MediaViewerView( ) MediaViewerBottomBar( modifier = Modifier.align(Alignment.BottomCenter), - actionsEnabled = state.downloadedMedia is AsyncData.Success, - canDownload = state.canDownload, - canShare = state.canShare, - mimeType = state.mediaInfo.mimeType, caption = state.mediaInfo.caption, onHeightChange = { bottomPaddingInPixels = it }, - eventSink = state.eventSink ) } } @@ -276,11 +272,13 @@ private fun rememberShowProgress(downloadedMedia: AsyncData): Boolea return showProgress } -@Suppress("UNUSED_PARAMETER") @OptIn(ExperimentalMaterial3Api::class) @Composable private fun MediaViewerTopBar( actionsEnabled: Boolean, + canDownload: Boolean, + canShare: Boolean, + mimeType: String, senderName: String?, dateSent: String?, onBackClick: () -> Unit, @@ -292,8 +290,6 @@ private fun MediaViewerTopBar( Column( modifier = Modifier .fillMaxWidth() - .padding(end = 48.dp), - horizontalAlignment = Alignment.CenterHorizontally, ) { Text( text = senderName, @@ -313,55 +309,12 @@ private fun MediaViewerTopBar( ), navigationIcon = { BackButton(onClick = onBackClick) }, actions = { - // TODO Add action to open infos. - } - ) -} - -@Composable -private fun MediaViewerBottomBar( - actionsEnabled: Boolean, - canDownload: Boolean, - canShare: Boolean, - mimeType: String, - caption: String?, - onHeightChange: (Int) -> Unit, - eventSink: (MediaViewerEvents) -> Unit, - modifier: Modifier = Modifier, -) { - Column( - modifier = modifier - .fillMaxWidth() - .background(Color(0x99101317)) - .onSizeChanged { - onHeightChange(it.height) - }, - ) { - HorizontalDivider() - if (caption != null) { - Text( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - text = caption, - maxLines = 5, - overflow = TextOverflow.Ellipsis, - style = ElementTheme.typography.fontBodyLgRegular, - ) - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(start = 8.dp, end = 8.dp, bottom = 8.dp), - verticalAlignment = Alignment.CenterVertically, - ) { if (canShare) { IconButton( enabled = actionsEnabled, onClick = { eventSink(MediaViewerEvents.Share) }, - modifier = Modifier.align(Alignment.CenterVertically) ) { Icon( imageVector = CompoundIcons.ShareAndroid(), @@ -369,7 +322,6 @@ private fun MediaViewerBottomBar( ) } } - Spacer(modifier = Modifier.weight(1f)) IconButton( enabled = actionsEnabled, onClick = { @@ -400,6 +352,36 @@ private fun MediaViewerBottomBar( ) } } + // TODO Add action to open infos. + } + ) +} + +@Composable +private fun MediaViewerBottomBar( + caption: String?, + onHeightChange: (Int) -> Unit, + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier + .fillMaxWidth() + .background(Color(0x99101317)) + .onSizeChanged { + onHeightChange(it.height) + }, + ) { + HorizontalDivider() + if (caption != null) { + Text( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + text = caption, + maxLines = 5, + overflow = TextOverflow.Ellipsis, + style = ElementTheme.typography.fontBodyLgRegular, + ) } } }