diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferExpiredBottomSheet.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferExpiredBottomSheet.kt index 81c55c4f7..5212368fa 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferExpiredBottomSheet.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferExpiredBottomSheet.kt @@ -20,8 +20,11 @@ package com.infomaniak.swisstransfer.ui.components.transfer import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.PreviewParameter import com.infomaniak.core2.FORMAT_DATE_SIMPLE import com.infomaniak.core2.format +import com.infomaniak.multiplatform_swisstransfer.common.ext.toDateFromSeconds +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.LargeButton import com.infomaniak.swisstransfer.ui.components.SwissTransferBottomSheet @@ -29,29 +32,29 @@ 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.previewparameter.TransferUiListPreviewParameter 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?, + expiredTransfer: () -> TransferUi?, onDeleteTransferClicked: () -> Unit, closeBottomSheet: () -> Unit, ) { - if (!isVisible()) return + val transfer = expiredTransfer() ?: return - val date = expirationDate() - val descriptionText = if (date != null) { + val descriptionText = if (transfer.expiresInDays < 0) { stringResource( R.string.transferExpiredDateReachedDescription, - date.format(FORMAT_DATE_SIMPLE), + transfer.expirationDateTimestamp.toDateFromSeconds().format(FORMAT_DATE_SIMPLE), ) } else { - stringResource(R.string.transferExpiredLimitReachedDescription, downloadsLimit()!!) + stringResource( + R.string.transferExpiredLimitReachedDescription, + transfer.downloadLimit, + ) } SwissTransferBottomSheet( @@ -61,7 +64,10 @@ fun TransferExpiredBottomSheet( modifier = it, titleRes = R.string.transferExpiredButton, imageVector = AppIcons.Bin, - onClick = onDeleteTransferClicked, + onClick = { + onDeleteTransferClicked() + closeBottomSheet() + }, ) }, imageVector = AppIllus.MascotDead.image(), @@ -72,13 +78,11 @@ fun TransferExpiredBottomSheet( @PreviewAllWindows @Composable -private fun Preview() { +private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List) { SwissTransferTheme { Surface { TransferExpiredBottomSheet( - isVisible = { true }, - expirationDate = { Date() }, - downloadsLimit = { 42 }, + expiredTransfer = { transfers.first() }, onDeleteTransferClicked = {}, closeBottomSheet = {}, ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransfersListWithExpiredBottomSheet.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransfersListWithExpiredBottomSheet.kt index 63a181ece..0343d2145 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransfersListWithExpiredBottomSheet.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransfersListWithExpiredBottomSheet.kt @@ -17,7 +17,6 @@ */ package com.infomaniak.swisstransfer.ui.components.transfer -import android.util.Log import androidx.compose.foundation.layout.padding import androidx.compose.material3.Surface import androidx.compose.runtime.Composable @@ -27,14 +26,13 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewParameter -import com.infomaniak.multiplatform_swisstransfer.common.ext.toDateFromSeconds import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark -import java.util.Date +import com.infomaniak.swisstransfer.ui.utils.isExpired @Composable fun TransfersListWithExpiredBottomSheet( @@ -42,46 +40,30 @@ fun TransfersListWithExpiredBottomSheet( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, getTransfers: () -> List, - onSwiped: (String) -> Unit, + onDeleteTransfer: (String) -> Unit, ) { - var isExpirySheetVisible: Boolean by rememberSaveable { mutableStateOf(false) } - var expirationDate: Date? by rememberSaveable { mutableStateOf(null) } - var downloadsLimit: Int? by rememberSaveable { mutableStateOf(null) } + var expiredTransfer: TransferUi? by rememberSaveable { mutableStateOf(null) } TransferItemList( modifier = Modifier.padding(Margin.Medium), direction = direction, getSelectedTransferUuid = getSelectedTransferUuid, getTransfers = getTransfers, - onSwiped = onSwiped, + onSwiped = onDeleteTransfer, onClick = { transfer -> - when { - transfer.expiresInDays < 0 -> { - isExpirySheetVisible = true - expirationDate = transfer.expirationDateTimestamp.toDateFromSeconds() - } - transfer.downloadLeft == 0 -> { - isExpirySheetVisible = true - downloadsLimit = transfer.downloadLimit - } - else -> { - navigateToDetails(transfer.uuid) - } + if (transfer.isExpired) { + expiredTransfer = transfer + } else { + navigateToDetails(transfer.uuid) } } ) TransferExpiredBottomSheet( - isVisible = { isExpirySheetVisible }, - expirationDate = { expirationDate }, - downloadsLimit = { downloadsLimit }, - onDeleteTransferClicked = { Log.d("TODO", "Delete expired Transfer") }, // TODO - closeBottomSheet = { - isExpirySheetVisible = false - expirationDate = null - downloadsLimit = null - }, + expiredTransfer = { expiredTransfer }, + onDeleteTransferClicked = { expiredTransfer?.uuid?.let(onDeleteTransfer) }, + closeBottomSheet = { expiredTransfer = null }, ) } @@ -95,7 +77,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra navigateToDetails = {}, getSelectedTransferUuid = { null }, getTransfers = { transfers }, - onSwiped = {}, + onDeleteTransfer = {}, ) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt index 2f7c9eaf4..06932a726 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt @@ -52,7 +52,7 @@ fun ReceivedScreen( navigateToDetails = navigateToDetails, getSelectedTransferUuid = getSelectedTransferUuid, getTransfers = { transfers!! }, - onSwiped = transfersViewModel::deleteTransfer, + onDeleteTransfer = transfersViewModel::deleteTransfer, ) } } @@ -62,7 +62,7 @@ private fun ReceivedScreen( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, getTransfers: () -> List, - onSwiped: (String) -> Unit, + onDeleteTransfer: (String) -> Unit, ) { val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } } @@ -82,7 +82,7 @@ private fun ReceivedScreen( navigateToDetails = navigateToDetails, getSelectedTransferUuid = getSelectedTransferUuid, getTransfers = getTransfers, - onSwiped = onSwiped, + onDeleteTransfer = onDeleteTransfer, ) } } @@ -97,7 +97,7 @@ private fun Preview() { navigateToDetails = {}, getSelectedTransferUuid = { null }, getTransfers = { emptyList() }, - onSwiped = {}, + onDeleteTransfer = {}, ) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt index a4a541c93..091f9f965 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt @@ -59,7 +59,7 @@ fun SentScreen( navigateToDetails = navigateToDetails, getSelectedTransferUuid = getSelectedTransferUuid, getTransfers = { transfers!! }, - onSwiped = transfersViewModel::deleteTransfer, + onDeleteTransfer = transfersViewModel::deleteTransfer, ) } } @@ -69,7 +69,7 @@ private fun SentScreen( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, getTransfers: () -> List, - onSwiped: (String) -> Unit, + onDeleteTransfer: (String) -> Unit, ) { val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } } @@ -90,7 +90,7 @@ private fun SentScreen( navigateToDetails = navigateToDetails, getSelectedTransferUuid = getSelectedTransferUuid, getTransfers = getTransfers, - onSwiped = onSwiped, + onDeleteTransfer = onDeleteTransfer, ) } } @@ -105,7 +105,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra navigateToDetails = {}, getSelectedTransferUuid = { null }, getTransfers = { transfers }, - onSwiped = {}, + onDeleteTransfer = {}, ) } }