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 23262535a..7401d5a99 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 @@ -38,8 +38,8 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark fun TransferItemList( modifier: Modifier = Modifier, direction: TransferDirection, - transfers: List, getSelectedTransferUuid: () -> String?, + getTransfers: () -> List, onClick: (TransferUi) -> Unit, ) { @@ -58,11 +58,11 @@ fun TransferItemList( item { Text(stringResource(titleRes), style = SwissTransferTheme.typography.h1) } items( - count = transfers.count(), - key = { transfers[it].uuid }, - contentType = { transfers[it] }, + count = getTransfers().count(), + key = { getTransfers()[it].uuid }, + contentType = { getTransfers()[it] }, itemContent = { - val transfer = transfers[it] + val transfer = getTransfers()[it] TransferItem( transfer = transfer, isSelected = { selectedTransferUuid == transfer.uuid }, @@ -79,9 +79,9 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra SwissTransferTheme { Surface { TransferItemList( - transfers = transfers, direction = TransferDirection.SENT, getSelectedTransferUuid = { null }, + getTransfers = { transfers }, onClick = {}, ) } 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 3d4a85040..51114a502 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 @@ -38,9 +38,9 @@ import java.util.Date @Composable fun TransfersListWithExpiredBottomSheet( direction: TransferDirection, - transfers: List, navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, + getTransfers: () -> List, ) { var isExpirySheetVisible: Boolean by rememberSaveable { mutableStateOf(false) } @@ -50,8 +50,8 @@ fun TransfersListWithExpiredBottomSheet( TransferItemList( modifier = Modifier.padding(Margin.Medium), direction = direction, - transfers = transfers, getSelectedTransferUuid = getSelectedTransferUuid, + getTransfers = getTransfers, onClick = { transfer -> when { transfer.expiresInDays < 0 -> { @@ -89,9 +89,9 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra Surface { TransfersListWithExpiredBottomSheet( direction = TransferDirection.RECEIVED, - transfers = transfers, navigateToDetails = {}, getSelectedTransferUuid = { null }, + getTransfers = { transfers }, ) } } 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 88447e4bd..c4c391c1a 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 @@ -23,7 +23,6 @@ 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.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection import com.infomaniak.swisstransfer.R @@ -44,19 +43,20 @@ fun ReceivedScreen( transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - val transfers by transfersViewModel.receivedTransfers.collectAsStateWithLifecycle() - val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } } + val getTransfers = { transfersViewModel.receivedTransfers.value } - ReceivedScreen(navigateToDetails, getSelectedTransferUuid, transfers, areTransfersEmpty) + ReceivedScreen(navigateToDetails, getSelectedTransferUuid, getTransfers) } @Composable private fun ReceivedScreen( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, - transfers: List, - areTransfersEmpty: Boolean, + getTransfers: () -> List, ) { + + val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } } + BrandTopAppBarScaffold( floatingActionButton = { ReceivedEmptyFab { areTransfersEmpty } }, ) { @@ -67,7 +67,12 @@ private fun ReceivedScreen( descriptionRes = R.string.noTransferReceivedDescription, ) } else { - TransfersListWithExpiredBottomSheet(TransferDirection.RECEIVED, transfers, navigateToDetails, getSelectedTransferUuid) + TransfersListWithExpiredBottomSheet( + direction = TransferDirection.RECEIVED, + navigateToDetails = navigateToDetails, + getSelectedTransferUuid = getSelectedTransferUuid, + getTransfers = getTransfers, + ) } } } @@ -80,8 +85,7 @@ private fun Preview() { ReceivedScreen( navigateToDetails = {}, getSelectedTransferUuid = { null }, - transfers = emptyList(), - areTransfersEmpty = true, + getTransfers = { emptyList() }, ) } } 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 1ae6ce2fd..437b61914 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 @@ -25,7 +25,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.hilt.navigation.compose.hiltViewModel -import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection import com.infomaniak.swisstransfer.ui.components.NewTransferFab @@ -45,20 +44,19 @@ fun SentScreen( transfersViewModel: TransfersViewModel = hiltViewModel(), ) { - val transfers by transfersViewModel.sentTransfers.collectAsStateWithLifecycle() - val areTransfersEmpty by remember { derivedStateOf { transfers.isEmpty() } } + val getTransfers = { transfersViewModel.sentTransfers.value } - SentScreen(navigateToDetails, getSelectedTransferUuid, transfers, areTransfersEmpty) + SentScreen(navigateToDetails, getSelectedTransferUuid, getTransfers) } @Composable private fun SentScreen( navigateToDetails: (transferUuid: String) -> Unit, getSelectedTransferUuid: () -> String?, - transfers: List, - areTransfersEmpty: Boolean, + getTransfers: () -> List, ) { + val areTransfersEmpty by remember { derivedStateOf { getTransfers().isEmpty() } } val windowAdaptiveInfo = currentWindowAdaptiveInfo() BrandTopAppBarScaffold( @@ -71,7 +69,12 @@ private fun SentScreen( if (areTransfersEmpty) { SentEmptyScreen() } else { - TransfersListWithExpiredBottomSheet(TransferDirection.SENT, transfers, navigateToDetails, getSelectedTransferUuid) + TransfersListWithExpiredBottomSheet( + direction = TransferDirection.SENT, + navigateToDetails = navigateToDetails, + getSelectedTransferUuid = getSelectedTransferUuid, + getTransfers = getTransfers, + ) } } } @@ -84,8 +87,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra SentScreen( navigateToDetails = {}, getSelectedTransferUuid = { null }, - transfers = transfers, - areTransfersEmpty = false, + getTransfers = { transfers }, ) } }