From b53fbd666f78d1e0786d8cc4085d3de1aa57883d Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Tue, 12 Nov 2024 18:05:23 +0100 Subject: [PATCH] feat: Use real data for Sent & Received transfers lists --- .../TransfersListWithExpiredBottomSheet.kt | 10 ++++--- .../ui/screen/main/received/ReceivedScreen.kt | 26 +++++-------------- .../ui/screen/main/sent/SentScreen.kt | 25 ++++-------------- 3 files changed, 19 insertions(+), 42 deletions(-) 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 f8bf925c8..3d4a85040 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 @@ -26,8 +26,10 @@ import androidx.compose.runtime.mutableStateOf 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.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection -import com.infomaniak.swisstransfer.ui.previewparameter.transfersPreviewData +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 @@ -36,6 +38,7 @@ import java.util.Date @Composable fun TransfersListWithExpiredBottomSheet( direction: TransferDirection, + transfers: List, navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, ) { @@ -47,7 +50,7 @@ fun TransfersListWithExpiredBottomSheet( TransferItemList( modifier = Modifier.padding(Margin.Medium), direction = direction, - transfers = transfersPreviewData, // TODO: Use real data + transfers = transfers, getSelectedTransferUuid = getSelectedTransferUuid, onClick = { transfer -> when { @@ -81,11 +84,12 @@ fun TransfersListWithExpiredBottomSheet( @PreviewLightAndDark @Composable -private fun Preview() { +private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) transfers: List) { SwissTransferTheme { Surface { TransfersListWithExpiredBottomSheet( direction = TransferDirection.RECEIVED, + transfers = transfers, navigateToDetails = {}, getSelectedTransferUuid = { null }, ) 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 668e1de14..b097adfa2 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 @@ -19,7 +19,9 @@ package com.infomaniak.swisstransfer.ui.screen.main.received import androidx.compose.material3.Surface import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection @@ -40,34 +42,21 @@ fun ReceivedScreen( getSelectedTransferUuid: () -> String?, transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle() - val areTransfersEmpty = false // TODO: Use the next line instead when available : - // val areTransfersEmpty by remember { derivedStateOf { transfers?.isEmpty() == true } } - ReceivedScreen( - navigateToDetails = navigateToDetails, - getSelectedTransferUuid = getSelectedTransferUuid, - areTransfersEmpty = { areTransfersEmpty }, - ) -} + val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle() + val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } } -@Composable -private fun ReceivedScreen( - navigateToDetails: (transferUuid: String) -> Unit, - getSelectedTransferUuid: () -> String?, - areTransfersEmpty: () -> Boolean, -) { BrandTopAppBarScaffold( - floatingActionButton = { ReceivedEmptyFab(areTransfersEmpty) }, + floatingActionButton = { ReceivedEmptyFab { areTransfersEmpty } }, ) { - if (areTransfersEmpty()) { + if (areTransfersEmpty) { EmptyState( icon = AppIllus.MascotSearching, titleRes = R.string.noTransferReceivedTitle, descriptionRes = R.string.noTransferReceivedDescription, ) } else { - TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, navigateToDetails, getSelectedTransferUuid) + TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, transfers, navigateToDetails, getSelectedTransferUuid) } } } @@ -80,7 +69,6 @@ private fun Preview() { ReceivedScreen( navigateToDetails = {}, getSelectedTransferUuid = { null }, - areTransfersEmpty = { false }, ) } } 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 8a375da46..8c57a6b55 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 @@ -41,36 +41,22 @@ fun SentScreen( getSelectedTransferUuid: () -> String?, transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - 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( - navigateToDetails: (transferUuid: String) -> Unit, - getSelectedTransferUuid: () -> String?, - areTransfersEmpty: () -> Boolean, -) { + val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle() + val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } } val windowAdaptiveInfo = currentWindowAdaptiveInfo() BrandTopAppBarScaffold( floatingActionButton = { - if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty()) { + if (windowAdaptiveInfo.isWindowSmall() && !areTransfersEmpty) { NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR) } }, ) { - if (areTransfersEmpty()) { + if (areTransfersEmpty) { SentEmptyScreen() } else { - TransfersListWithExpiredBottomSheet(TransferDirection.SENT, navigateToDetails, getSelectedTransferUuid) + TransfersListWithExpiredBottomSheet(TransferDirection.SENT, transfers, navigateToDetails, getSelectedTransferUuid) } } } @@ -83,7 +69,6 @@ private fun Preview() { SentScreen( navigateToDetails = {}, getSelectedTransferUuid = { null }, - areTransfersEmpty = { true }, ) } }