From 0e4cf511ec9d208dd3d025919996285c088b585e Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Wed, 13 Nov 2024 09:08:12 +0100 Subject: [PATCH] review: Apply suggestions from code review --- .../ui/components/transfer/TransferItemList.kt | 12 +++++------- .../main/transfers/TransfersScreenWrapper.kt | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) 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 57c9208db..23262535a 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 @@ -44,7 +44,10 @@ fun TransferItemList( ) { val selectedTransferUuid = getSelectedTransferUuid() - val titleRes = if (direction == TransferDirection.SENT) R.string.sentFilesTitle else R.string.receivedFilesTitle + val titleRes = when (direction) { + TransferDirection.SENT -> R.string.sentFilesTitle + TransferDirection.RECEIVED -> R.string.receivedFilesTitle + } LazyColumn( modifier = modifier, @@ -52,12 +55,7 @@ fun TransferItemList( contentPadding = PaddingValues(top = Margin.Mini), ) { - item { - Text( - text = stringResource(titleRes), - style = SwissTransferTheme.typography.h1, - ) - } + item { Text(stringResource(titleRes), style = SwissTransferTheme.typography.h1) } items( count = transfers.count(), diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt index e534d2d2d..9d7e84ab4 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transfers/TransfersScreenWrapper.kt @@ -52,16 +52,26 @@ fun TransfersScreenWrapper(direction: TransferDirection) { private fun ListPane(direction: TransferDirection, navigator: ThreePaneScaffoldNavigator) { when (direction) { TransferDirection.SENT -> SentScreen( - navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) }, - getSelectedTransferUuid = { navigator.currentDestination?.content }, + navigateToDetails = navigator::navigateToDetails, + getSelectedTransferUuid = navigator::getSelectedTransferUuid, ) TransferDirection.RECEIVED -> ReceivedScreen( - navigateToDetails = { transferUuid -> navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) }, - getSelectedTransferUuid = { navigator.currentDestination?.content }, + navigateToDetails = navigator::navigateToDetails, + getSelectedTransferUuid = navigator::getSelectedTransferUuid, ) } } +@OptIn(ExperimentalMaterial3AdaptiveApi::class) +private fun ThreePaneScaffoldNavigator.navigateToDetails(transferUuid: String) { + navigateTo(ListDetailPaneScaffoldRole.Detail, transferUuid) +} + +@OptIn(ExperimentalMaterial3AdaptiveApi::class) +private fun ThreePaneScaffoldNavigator.getSelectedTransferUuid(): String? { + return currentDestination?.content +} + @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable private fun DetailPane(navigator: ThreePaneScaffoldNavigator) {