Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiple image preview [WPB-8801] #3004

Merged
merged 20 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,7 @@ import com.wire.kalium.logic.data.asset.AttachmentType
@Composable
fun AssetTooLargeDialog(dialogState: AssetTooLargeDialogState, hideDialog: () -> Unit) {
when (dialogState) {
is AssetTooLargeDialogState.SingleVisible -> {
WireDialog(
title = getTitle(dialogState),
text = getLabel(dialogState),
buttonsHorizontalAlignment = false,
onDismiss = hideDialog,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
type = WireDialogButtonType.Primary,
onClick = hideDialog
)
)
}

is AssetTooLargeDialogState.SingleVisible,
is AssetTooLargeDialogState.MultipleVisible -> {
WireDialog(
title = getTitle(dialogState),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand All @@ -43,6 +42,7 @@ import com.wire.android.ui.common.spacers.VerticalSpace
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.DeviceUtil
import java.util.Locale

@Composable
Expand All @@ -68,36 +68,24 @@ fun AssetFilePreview(
Text(
modifier = Modifier.padding(bottom = dimensions().spacing8x),
text = assetName.split(".").last().uppercase(Locale.getDefault()),
style = MaterialTheme.wireTypography.title01.copy(
fontWeight = FontWeight.W900,
color = MaterialTheme.colorScheme.onPrimary
)
color = MaterialTheme.colorScheme.onPrimary,
style = MaterialTheme.wireTypography.title05
)
}
VerticalSpace.x16()
Text(
assetName,
style = MaterialTheme.wireTypography.title02.copy(color = MaterialTheme.colorScheme.onBackground),
style = MaterialTheme.wireTypography.title02,
color = MaterialTheme.colorScheme.onBackground,
textAlign = TextAlign.Center,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
VerticalSpace.x8()
Text(sizeInBytes.toFileSize(), style = MaterialTheme.wireTypography.body01.copy(MaterialTheme.wireColorScheme.secondaryText))
}
}

@Suppress("MagicNumber")
private fun Long.toFileSize(): String {
val kilobyte = 1024.0
val megabyte = kilobyte * 1024
val gigabyte = megabyte * 1024

return when {
this < kilobyte -> "$this B"
this < megabyte -> String.format("%.2f KB", this / kilobyte)
this < gigabyte -> String.format("%.2f MB", this / megabyte)
else -> String.format("%.2f GB", this / gigabyte)
Text(
DeviceUtil.formatSize(sizeInBytes),
style = MaterialTheme.wireTypography.body01.copy(MaterialTheme.wireColorScheme.secondaryText)
alexandreferris marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp
import com.wire.android.R
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.image.WireImage
Expand Down Expand Up @@ -111,10 +109,8 @@ fun AssetTilePreview(
fun AssetExtensionPreviewTile(assetName: String) {
Text(
text = assetName.split(".").last().uppercase(Locale.getDefault()),
style = MaterialTheme.wireTypography.title01.copy(
fontWeight = FontWeight.W900,
color = MaterialTheme.wireColorScheme.secondaryText
)
style = MaterialTheme.wireTypography.title05,
color = MaterialTheme.wireColorScheme.secondaryText
)
}

Expand All @@ -141,7 +137,6 @@ fun AssetFilePreviewTile(assetBundle: AssetBundle, modifier: Modifier = Modifier
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.wireColorScheme.secondaryText,
fontSize = 12.sp,
style = MaterialTheme.wireTypography.subline01
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ import com.wire.android.ui.common.progress.WireCircularProgressIndicator
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.DeviceUtil
import com.wire.kalium.logic.data.asset.AssetTransferStatus
import com.wire.kalium.logic.data.asset.isFailed
import com.wire.kalium.logic.data.asset.isInProgress
import kotlin.math.roundToInt

@Composable
internal fun MessageAsset(
Expand Down Expand Up @@ -317,11 +317,5 @@ private fun isNotClickable(assetTransferStatus: AssetTransferStatus) =
@Suppress("MagicNumber")
@Stable
private fun provideAssetDescription(assetExtension: String, assetSizeInBytes: Long): String {
val oneKB = 1024L
val oneMB = oneKB * oneKB
return when {
assetSizeInBytes < oneKB -> "${assetExtension.uppercase()} ($assetSizeInBytes B)"
assetSizeInBytes in oneKB..oneMB -> "${assetExtension.uppercase()} (${assetSizeInBytes / oneKB} KB)"
else -> "${assetExtension.uppercase()} (${((assetSizeInBytes / oneMB) * 100.0).roundToInt() / 100.0} MB)" // 2 decimals round off
}
return "${assetExtension.uppercase()} (${DeviceUtil.formatSize(assetSizeInBytes)})"
}
33 changes: 6 additions & 27 deletions app/src/main/kotlin/com/wire/android/util/DeviceUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object DeviceUtil {
private const val BYTES_IN_KILOBYTE = 1024
private const val BYTES_IN_MEGABYTE = BYTES_IN_KILOBYTE * 1024
private const val BYTES_IN_GIGABYTE = BYTES_IN_MEGABYTE * 1024
private const val DIGITS_GROUP_SIZE = 3 // Number of digits between commas in formatted size.

fun getAvailableInternalMemorySize(): String = try {
val path = Environment.getDataDirectory()
Expand All @@ -46,32 +45,12 @@ object DeviceUtil {
""
}

private fun formatSize(sizeInBytes: Long): String {
var size = sizeInBytes
var suffix: String? = null
when {
size >= BYTES_IN_GIGABYTE -> {
suffix = "GB"
size /= BYTES_IN_GIGABYTE
}

size >= BYTES_IN_MEGABYTE -> {
suffix = "MB"
size /= BYTES_IN_MEGABYTE
}

size >= BYTES_IN_KILOBYTE -> {
suffix = "KB"
size /= BYTES_IN_KILOBYTE
}
}
val resultBuffer = StringBuilder(size.toString())
var commaOffset = resultBuffer.length - DIGITS_GROUP_SIZE
while (commaOffset > 0) {
resultBuffer.insert(commaOffset, ',')
commaOffset -= DIGITS_GROUP_SIZE
fun formatSize(sizeInBytes: Long): String {
return when {
sizeInBytes < BYTES_IN_KILOBYTE -> "$sizeInBytes B"
sizeInBytes < BYTES_IN_MEGABYTE -> String.format("%.2f KB", sizeInBytes / BYTES_IN_KILOBYTE)
sizeInBytes < BYTES_IN_GIGABYTE -> String.format("%.2f MB", sizeInBytes / BYTES_IN_MEGABYTE)
else -> String.format("%.2f GB", sizeInBytes / BYTES_IN_GIGABYTE)
}
suffix?.let { resultBuffer.append(it) }
return resultBuffer.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

@file:Suppress("ParameterListWrapping")

package com.wire.android.ui.theme

import androidx.compose.material3.Typography
Expand All @@ -25,7 +27,7 @@ import io.github.esentsov.PackagePrivate

@Immutable
data class WireTypography(
val title01: TextStyle, val title02: TextStyle, val title03: TextStyle, val title04: TextStyle,
val title01: TextStyle, val title02: TextStyle, val title03: TextStyle, val title04: TextStyle, val title05: TextStyle,
val body01: TextStyle, val body02: TextStyle, val body03: TextStyle, val body04: TextStyle, val body05: TextStyle,
val button01: TextStyle, val button02: TextStyle, val button03: TextStyle, val button04: TextStyle, val button05: TextStyle,
val label01: TextStyle, val label02: TextStyle, val label03: TextStyle, val label04: TextStyle, val label05: TextStyle,
Expand All @@ -45,6 +47,7 @@ private val DefaultWireTypography = WireTypography(
title02 = WireTypographyBase.Title02,
title03 = WireTypographyBase.Title03,
title04 = WireTypographyBase.Title04,
title05 = WireTypographyBase.Title05,
body01 = WireTypographyBase.Body01,
body02 = WireTypographyBase.Body02,
body03 = WireTypographyBase.Body03,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ object WireTypographyBase {
val Title04 = Title01.copy(
fontWeight = FontWeight.W400,
)
val Title05 = Title01.copy(
fontWeight = FontWeight.W900
)
val Body01 = TextStyle(
fontWeight = FontWeight.W400,
fontSize = 15.sp,
Expand Down
Loading