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

Expired transfer BottomSheet #126

Merged
merged 8 commits into from
Nov 4, 2024
1 change: 1 addition & 0 deletions Core2/src/main/java/com/infomaniak/core2/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ import java.util.Locale

const val FORMAT_DATE_DEFAULT = "dd.MM.yy"
const val FORMAT_DATE_TITLE = "E d MMMM"
const val FORMAT_DATE_SIMPLE = "dd/MM/yyyy"

fun Date.format(pattern: String = FORMAT_DATE_DEFAULT): String = SimpleDateFormat(pattern, Locale.getDefault()).format(this)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
fun EmptyState(
icon: ImageVector,
@StringRes title: Int,
@StringRes description: Int,
description: String,
modifier: Modifier = Modifier,
) {
Box(
Expand All @@ -49,7 +49,7 @@ fun EmptyState(
IllustratedMessageBlock(
icon = icon,
title = title,
description = stringResource(description),
description = description,
modifier = modifier.padding(horizontal = Margin.Medium),
)
}
Expand All @@ -64,7 +64,7 @@ private fun EmptyStatePreview() {
EmptyState(
icon = AppIllus.MascotSearching,
title = R.string.noTransferReceivedTitle,
description = R.string.noTransferReceivedDescription,
description = stringResource(R.string.noTransferReceivedDescription),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.infomaniak.swisstransfer.ui.components

import android.text.format.Formatter
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
Expand All @@ -35,6 +34,7 @@ import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
Expand All @@ -53,7 +53,7 @@ fun FileItem(
isRemoveButtonVisible = isRemoveButtonVisible,
onRemove = onRemove,
title = file.fileName,
description = Formatter.formatShortFileSize(LocalContext.current, file.fileSize),
description = HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, file.fileSize),
content = {
FilePreview(
file = file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun SwissTransferBottomSheet(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit,
imageVector: ImageVector? = null,
@StringRes titleRes: Int,
@StringRes titleRes: Int? = null,
@StringRes descriptionRes: Int? = null,
topButton: @Composable ((Modifier) -> Unit)? = null,
bottomButton: @Composable ((Modifier) -> Unit)? = null,
Expand All @@ -72,8 +72,8 @@ fun SwissTransferBottomSheet(
@Composable
private fun BottomSheetContent(
imageVector: ImageVector?,
titleRes: Int,
descriptionRes: Int?,
@StringRes titleRes: Int?,
@StringRes descriptionRes: Int?,
content: @Composable (() -> Unit)?,
topButton: @Composable ((Modifier) -> Unit)? = null,
bottomButton: @Composable ((Modifier) -> Unit)? = null,
Expand All @@ -89,13 +89,15 @@ private fun BottomSheetContent(
Spacer(modifier = Modifier.height(Margin.Large))
}

Text(
text = stringResource(titleRes),
style = SwissTransferTheme.typography.bodyMedium,
color = SwissTransferTheme.colors.primaryTextColor,
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(Margin.Large))
titleRes?.let {
Text(
text = stringResource(it),
style = SwissTransferTheme.typography.bodyMedium,
color = SwissTransferTheme.colors.primaryTextColor,
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(Margin.Large))
}

descriptionRes?.let {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fun TextDotText(
modifier: Modifier = Modifier,
color: Color = SwissTransferTheme.colors.secondaryTextColor,
style: TextStyle = SwissTransferTheme.typography.bodySmallRegular,
optionalSecondTextColor: Color? = null,
) {
Row(modifier) {
CustomText(firstText, color, style)
Expand All @@ -45,7 +46,7 @@ fun TextDotText(
style = style,
)
Spacer(Modifier.width(Margin.Mini))
CustomText(secondText, color, style)
CustomText(secondText, optionalSecondTextColor ?: color, style)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.swisstransfer.ui.components.transfer

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.infomaniak.core2.FORMAT_DATE_SIMPLE
import com.infomaniak.core2.format
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.EmptyState
import com.infomaniak.swisstransfer.ui.components.LargeButton
import com.infomaniak.swisstransfer.ui.components.SwissTransferBottomSheet
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.icons.Bin
import com.infomaniak.swisstransfer.ui.images.illus.mascotDead.MascotDead
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import java.util.Date

@Composable
fun TransferExpiredBottomSheet(
isVisible: () -> Boolean,
expirationDate: () -> Date?,
downloadsLimit: () -> Int?,
onDeleteTransferClicked: () -> Unit,
closeBottomSheet: () -> Unit,
) {

if (!isVisible()) return

val date = expirationDate()
val descriptionText = if (date != null) {
stringResource(
R.string.transferExpiredDateReachedDescription,
date.format(FORMAT_DATE_SIMPLE),
)
} else {
stringResource(R.string.transferExpiredLimitReachedDescription, downloadsLimit()!!)
}

SwissTransferBottomSheet(
onDismissRequest = closeBottomSheet,
bottomButton = {
LargeButton(
modifier = it,
titleRes = R.string.transferExpiredButton,
imageVector = AppIcons.Bin,
onClick = onDeleteTransferClicked,
)
},
) {
Column {
Spacer(modifier = Modifier.height(Margin.Medium))
EmptyState(
icon = AppIllus.MascotDead.image(),
title = R.string.transferExpiredTitle,
description = descriptionText,
)
}
}
}

@PreviewAllWindows
@Composable
private fun Preview() {
SwissTransferTheme {
Surface {
TransferExpiredBottomSheet(
isVisible = { true },
expirationDate = { Date() },
downloadsLimit = { 42 },
onDeleteTransferClicked = {},
closeBottomSheet = {},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.infomaniak.swisstransfer.ui.components.transfer

import android.text.format.Formatter
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand All @@ -26,6 +25,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import com.infomaniak.core2.FORMAT_DATE_SIMPLE
import com.infomaniak.core2.FORMAT_DATE_TITLE
import com.infomaniak.core2.format
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi
Expand All @@ -37,6 +37,7 @@ import com.infomaniak.swisstransfer.ui.images.icons.ChevronRightThick
import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import java.util.Calendar
import java.util.Date
Expand All @@ -45,6 +46,27 @@ import java.util.UUID
@OptIn(ExperimentalLayoutApi::class)
@Composable
fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {

val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE)
val expirationDate = Date(transfer.expirationDateTimestamp)
val remainingDays = transfer.expiresInDays
val remainingDownloads = transfer.downloadLeft
val uploadedSize = HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, transfer.sizeUploaded)
val files = transfer.files
val filesCount = files.count()
val (expiryText, expiryColor) = when {
remainingDays < 0 -> {
stringResource(R.string.expiredThe, expirationDate.format(FORMAT_DATE_SIMPLE)) to
SwissTransferTheme.materialColors.error
}
remainingDownloads == 0 -> {
"Transfert expiré (TODO)" to SwissTransferTheme.materialColors.error
}
else -> {
stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor
}
}

Card(
onClick = onClick,
colors = CardDefaults.cardColors(containerColor = SwissTransferTheme.materialColors.surfaceContainerHighest),
Expand All @@ -58,7 +80,7 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {
Column(modifier = Modifier.weight(1.0f)) {

Text(
text = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE),
text = createdDate,
style = SwissTransferTheme.typography.bodyMedium,
color = SwissTransferTheme.colors.primaryTextColor,
maxLines = 1,
Expand All @@ -67,18 +89,19 @@ fun TransferItem(transfer: TransferUi, onClick: () -> Unit) {

Spacer(modifier = Modifier.height(Margin.Mini))
TextDotText(
firstText = { Formatter.formatShortFileSize(LocalContext.current, transfer.sizeUploaded) },
secondText = { stringResource(R.string.expiresIn, transfer.expiresInDays) },
firstText = { uploadedSize },
secondText = { expiryText },
optionalSecondTextColor = expiryColor,
)

Spacer(modifier = Modifier.height(Margin.Mini))
ContextualFlowRow(
itemCount = transfer.files.count(),
itemCount = filesCount,
maxLines = 1,
horizontalArrangement = Arrangement.spacedBy(Margin.Mini),
overflow = ContextualFlowRowOverflow.expandIndicator { TransferFilePreview(remainingFilesCount = totalItemCount - shownItemCount) },
) { index ->
TransferFilePreview(file = transfer.files[index])
TransferFilePreview(file = files[index])
}
}

Expand Down
Loading
Loading