From f334ac980f8a3658a6861f2c52bcffeb3bd68b31 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Tue, 12 Nov 2024 10:00:37 +0100 Subject: [PATCH] feat: Make Sent screen use the ScreenWrapper --- .../components/transfer/TransferItemList.kt | 5 +- .../ui/screen/main/MainNavHost.kt | 16 ++-- .../ui/screen/main/received/ReceivedScreen.kt | 13 ++- .../ui/screen/main/sent/SentScreen.kt | 81 ++++++++++++++++--- .../TransfersScreenWrapper.kt} | 31 ++++--- .../TransfersViewModel.kt} | 7 +- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 11 files changed, 116 insertions(+), 42 deletions(-) rename app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/{received/ReceivedScreenWrapper.kt => transfers/TransfersScreenWrapper.kt} (72%) rename app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/{sent/SentViewModel.kt => transfers/TransfersViewModel.kt} (77%) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt index 48dc74932..5976264d9 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItemList.kt @@ -29,6 +29,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark @@ -36,6 +37,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark @Composable fun TransferItemList( modifier: Modifier = Modifier, + type:TransfersType, transfers: List, getSelectedTransferUuid: () -> String?, onClick: (TransferUi) -> Unit, @@ -51,7 +53,7 @@ fun TransferItemList( item { Text( - text = stringResource(R.string.receivedFilesTitle), + text = stringResource(if (type == TransfersType.SENT) R.string.sentFilesTitle else R.string.receivedFilesTitle), style = SwissTransferTheme.typography.h1, ) } @@ -79,6 +81,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra Surface { TransferItemList( transfers = transfers, + type = TransfersType.SENT, getSelectedTransferUuid = { null }, onClick = {}, ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt index 0ccc66c19..56467adab 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt @@ -27,9 +27,9 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import com.infomaniak.swisstransfer.ui.navigation.MainNavigation import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.* -import com.infomaniak.swisstransfer.ui.screen.main.received.ReceivedScreenWrapper -import com.infomaniak.swisstransfer.ui.screen.main.sent.SentScreen import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsScreenWrapper +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersScreenWrapper +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType @Composable fun MainNavHost( @@ -42,14 +42,8 @@ fun MainNavHost( enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None }, exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None }, ) { - composable { - SentScreen(navigateToDetails = { navController.navigate(TransferDetailsDestination(it)) }) - } - composable { - ReceivedScreenWrapper() - } - composable { - SettingsScreenWrapper() - } + composable { TransfersScreenWrapper(TransfersType.SENT) } + composable { TransfersScreenWrapper(TransfersType.RECEIVED) } + composable { SettingsScreenWrapper() } } } 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 da7ebdbf2..540f71f8b 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 @@ -34,7 +34,8 @@ import com.infomaniak.swisstransfer.ui.images.illus.MascotSearching import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold import com.infomaniak.swisstransfer.ui.screen.main.received.components.ReceivedEmptyFab -import com.infomaniak.swisstransfer.ui.screen.main.sent.SentViewModel +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @@ -44,9 +45,9 @@ import java.util.Date fun ReceivedScreen( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, - sentViewModel: SentViewModel = hiltViewModel(), + transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - val transfers by sentViewModel.transfers.collectAsStateWithLifecycle() + val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle() val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } } ReceivedScreen( @@ -79,6 +80,7 @@ private fun ReceivedScreen( } else { TransferItemList( modifier = Modifier.padding(Margin.Medium), + type = TransfersType.RECEIVED, transfers = transfersPreviewData, // TODO: Use real data getSelectedTransferUuid = getSelectedTransferUuid, onClick = { transfer -> @@ -102,10 +104,7 @@ private fun ReceivedScreen( isVisible = { isVisible }, expirationDate = { expirationDate }, downloadsLimit = { downloadsLimit }, - onDeleteTransferClicked = { - Log.d("TODO", "Delete expired Transfer") - // TODO - }, + onDeleteTransferClicked = { Log.d("TODO", "Delete expired Transfer") }, // TODO closeBottomSheet = { isVisible = false expirationDate = null 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 cc2f32a97..89b6b5721 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 @@ -17,45 +17,100 @@ */ package com.infomaniak.swisstransfer.ui.screen.main.sent +import android.util.Log +import androidx.compose.foundation.layout.padding import androidx.compose.material3.Surface import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue +import androidx.compose.runtime.* +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.swisstransfer.ui.components.NewTransferFab import com.infomaniak.swisstransfer.ui.components.NewTransferFabType +import com.infomaniak.swisstransfer.ui.components.transfer.TransferExpiredBottomSheet +import com.infomaniak.swisstransfer.ui.components.transfer.TransferItemList +import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData import com.infomaniak.swisstransfer.ui.screen.main.components.BrandTopAppBarScaffold +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersType +import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersViewModel +import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows import com.infomaniak.swisstransfer.ui.utils.isWindowSmall +import java.util.Date @Composable fun SentScreen( navigateToDetails: (transferUuid: String) -> Unit, - sentViewModel: SentViewModel = hiltViewModel(), + getSelectedTransferUuid: () -> String?, + transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - val transfers by sentViewModel.transfers.collectAsStateWithLifecycle() - SentScreen(transfers) + val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle() + val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } } + + SentScreen( + navigateToDetails = navigateToDetails, + getSelectedTransferUuid = getSelectedTransferUuid, + areTransfersEmpty = { areTransfersEmpty }, + ) } @Composable -private fun SentScreen(transfers: List?) { +private fun SentScreen( + navigateToDetails: (transferUuid: String) -> Unit, + getSelectedTransferUuid: () -> String?, + areTransfersEmpty: () -> Boolean, +) { - if (transfers == null) return val windowAdaptiveInfo = currentWindowAdaptiveInfo() + var isVisible: Boolean by rememberSaveable { mutableStateOf(false) } + var expirationDate: Date? by rememberSaveable { mutableStateOf(null) } + var downloadsLimit: Int? by rememberSaveable { mutableStateOf(null) } BrandTopAppBarScaffold( floatingActionButton = { - if (windowAdaptiveInfo.isWindowSmall() && transfers.isNotEmpty()) { + if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty()) { NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR) } }, ) { - if (transfers.isEmpty()) { + if (areTransfersEmpty()) { SentEmptyScreen() } else { - SentListScreen(transfers) + TransferItemList( + modifier = Modifier.padding(Margin.Medium), + type = TransfersType.SENT, + transfers = transfersPreviewData, // TODO: Use real data + getSelectedTransferUuid = getSelectedTransferUuid, + onClick = { transfer -> + when { + transfer.expiresInDays < 0 -> { + isVisible = true + expirationDate = Date(transfer.expirationDateTimestamp) + } + transfer.downloadLeft == 0 -> { + isVisible = true + downloadsLimit = transfer.downloadLimit + } + else -> { + navigateToDetails(transfer.uuid) + } + } + } + ) + + TransferExpiredBottomSheet( + isVisible = { isVisible }, + expirationDate = { expirationDate }, + downloadsLimit = { downloadsLimit }, + onDeleteTransferClicked = { Log.d("TODO", "Delete expired Transfer") }, // TODO + closeBottomSheet = { + isVisible = false + expirationDate = null + downloadsLimit = null + }, + ) } } } @@ -65,7 +120,11 @@ private fun SentScreen(transfers: List?) { private fun Preview() { SwissTransferTheme { Surface { - SentScreen(transfers = emptyList()) + SentScreen( + navigateToDetails = {}, + getSelectedTransferUuid = { null }, + areTransfersEmpty = { true }, + ) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt similarity index 72% rename from app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreenWrapper.kt rename to app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt index c9b10a060..9827a5e7a 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.swisstransfer.ui.screen.main.received +package com.infomaniak.swisstransfer.ui.screen.main.transfers import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -30,6 +30,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.infomaniak.swisstransfer.ui.components.TwoPaneScaffold import com.infomaniak.swisstransfer.ui.components.safeCurrentContent +import com.infomaniak.swisstransfer.ui.screen.main.received.ReceivedScreen +import com.infomaniak.swisstransfer.ui.screen.main.sent.SentScreen import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsScreen import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @@ -37,20 +39,26 @@ import com.infomaniak.swisstransfer.ui.utils.ScreenWrapperUtils @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable -fun ReceivedScreenWrapper() { +fun TransfersScreenWrapper(type: TransfersType) { TwoPaneScaffold( - listPane = { ListPane(navigator = this) }, + listPane = { ListPane(type, navigator = this) }, detailPane = { DetailPane(navigator = this) }, ) } @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable -private fun ListPane(navigator: ThreePaneScaffoldNavigator) { - ReceivedScreen( - navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) }, - getSelectedTransferUuid = { navigator.currentDestination?.content }, - ) +private fun ListPane(type: TransfersType, navigator: ThreePaneScaffoldNavigator) { + when (type) { + TransfersType.SENT -> SentScreen( + navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) }, + getSelectedTransferUuid = { navigator.currentDestination?.content }, + ) + TransfersType.RECEIVED -> ReceivedScreen( + navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) }, + getSelectedTransferUuid = { navigator.currentDestination?.content }, + ) + } } @OptIn(ExperimentalMaterial3AdaptiveApi::class) @@ -77,12 +85,17 @@ private fun NoSelectionEmptyState() { } } +enum class TransfersType { + SENT, + RECEIVED, +} + @PreviewAllWindows @Composable private fun Preview() { SwissTransferTheme { Surface(color = MaterialTheme.colorScheme.background) { - ReceivedScreenWrapper() + TransfersScreenWrapper(TransfersType.RECEIVED) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersViewModel.kt similarity index 77% rename from app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentViewModel.kt rename to app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersViewModel.kt index e7ce982a6..1196b2514 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersViewModel.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.infomaniak.swisstransfer.ui.screen.main.sent +package com.infomaniak.swisstransfer.ui.screen.main.transfers import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.snapshots.SnapshotStateMap @@ -28,7 +28,8 @@ import kotlinx.coroutines.flow.stateIn import javax.inject.Inject @HiltViewModel -class SentViewModel @Inject constructor() : ViewModel() { - val transfers = flow> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null) +class TransfersViewModel @Inject constructor() : ViewModel() { + val sentTransfers = flow> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null) + val receivedTransfers = flow> { emit(listOf(1)) }.stateIn(viewModelScope, SharingStarted.Eagerly, null) val selectedTransferUuids: SnapshotStateMap = mutableStateMapOf() } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 07953fbaf..ebf8bb0c1 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -52,6 +52,7 @@ Empfangene Dateien Empfangen Unsere Geschichte beginnt hier + Geteilte Dateien Gesendet Verfolgung genehmigen Über diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8840028d5..2978d5c7b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -52,6 +52,7 @@ Archivos recibidos Recibido Nuestra historia comienza aquí + Archivos compartidos Enviado a Autorizar el seguimiento Quiénes somos diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5c505fc63..49d980474 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -53,6 +53,7 @@ Fichiers reçus Reçu Notre histoire commence ici + Fichiers partagés Envoyé Autoriser le suivi A propos diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 659893cb6..85ef5002c 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -52,6 +52,7 @@ File ricevuti Ricevuto La nostra storia inizia qui + File condivisi Inviato a Autorizza il tracciamento Chi siamo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4b878b5e1..aefc59e4d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ Received files Received Our story begins here + Shared files Sent Authorize tracking About