diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt index 79808294e..c18a32918 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt @@ -70,7 +70,7 @@ sealed class NewTransferNavigation : NavigationDestination() { data object UploadErrorDestination : NewTransferNavigation() @Serializable - data object FilesDetailsDestination : MainNavigation() + data object FilesDetailsDestination : NewTransferNavigation() companion object { val startDestination = ImportFilesDestination diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt index 7e7f75e6a..8689e70ec 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/previewparameter/FileUiListPreviewParameterProvider.kt @@ -82,4 +82,13 @@ val filesPreviewData = listOf( localPath = null, path = "", ), + FileUi( + uid = UUID.randomUUID().toString(), + fileName = "Secret foldert", + isFolder = true, + fileSize = 57_689_032L, + mimeType = null, + localPath = null, + path = "", + ), ) 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 926b0e482..8f555b228 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 @@ -31,7 +31,7 @@ import com.infomaniak.swisstransfer.ui.navigation.MainNavigation import com.infomaniak.swisstransfer.ui.navigation.MainNavigation.* import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsScreenWrapper import com.infomaniak.swisstransfer.ui.screen.main.transfers.TransfersScreenWrapper -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.FilesDetailsScreen +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.FilesDetailsComponent @Composable fun MainNavHost( @@ -63,7 +63,7 @@ fun MainNavHost( composable { SettingsScreenWrapper() } composable { val filesDetailsDestination: FilesDetailsDestination = it.toRoute() - FilesDetailsScreen( + FilesDetailsComponent( navigateToDetails = { folderUuid -> navController.navigate(FilesDetailsDestination(folderUuid)) }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt index 1b5344d49..e14b87480 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt @@ -45,14 +45,14 @@ fun MainScreen() { MainScaffold( navController = navController, currentDestination = currentDestination, - largeWindowTopAppBar = { + windowTopAppBar = { isWindowLarge -> // This is temporary to fix an issue with the animation when displaying the FilesDetailsScreen if (currentDestination is MainNavigation.FilesDetailsDestination) { SwissTransferTopAppBar( navigationMenu = TopAppBarButton.backButton { navController.popBackStack() }, actionMenus = arrayOf(TopAppBarButton.closeButton { }), ) - } else { + } else if (isWindowLarge) { BrandTopAppBar() } }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/MainScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/MainScaffold.kt index a4d6de271..f0916524d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/MainScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/MainScaffold.kt @@ -40,7 +40,7 @@ import com.infomaniak.swisstransfer.ui.utils.isWindowSmall fun MainScaffold( navController: NavHostController, currentDestination: MainNavigation, - largeWindowTopAppBar: @Composable () -> Unit = {}, + windowTopAppBar: @Composable (isWindowLarge: Boolean) -> Unit = {}, content: @Composable () -> Unit = {}, ) { val navType by rememberNavType(currentDestination) @@ -49,7 +49,7 @@ fun MainScaffold( navType = navType, currentDestination = currentDestination, navigateToSelectedItem = navController::navigateToSelectedItem, - largeWindowTopAppBar = largeWindowTopAppBar, + windowTopAppBar = windowTopAppBar, content = content ) } @@ -59,13 +59,13 @@ private fun MainScaffold( navType: NavigationSuiteType, currentDestination: MainNavigation, navigateToSelectedItem: (MainNavigation) -> Unit, - largeWindowTopAppBar: @Composable () -> Unit, + windowTopAppBar: @Composable (isWindowLarge: Boolean) -> Unit = {}, content: @Composable () -> Unit, ) { val windowAdaptiveInfo = LocalWindowAdaptiveInfo.current Column { - if (windowAdaptiveInfo.isWindowLarge()) largeWindowTopAppBar() + windowTopAppBar(windowAdaptiveInfo.isWindowLarge()) AppNavigationSuiteScaffold(navType, NavigationItem.entries, currentDestination, navigateToSelectedItem) { if (windowAdaptiveInfo.isWindowSmall()) { Column { @@ -129,7 +129,7 @@ private fun NavigationSmallWindowPreview() { currentDestination = MainNavigation.SentDestination, navigateToSelectedItem = {}, navType = NavigationSuiteType.NavigationBar, - largeWindowTopAppBar = { BrandTopAppBar() }, + windowTopAppBar = { isWindowLarge -> if (isWindowLarge) BrandTopAppBar() }, content = {}, ) } @@ -143,7 +143,7 @@ private fun NavigationLargeWindowPreview() { currentDestination = MainNavigation.SentDestination, navigateToSelectedItem = {}, navType = NavigationSuiteType.NavigationRail, - largeWindowTopAppBar = { BrandTopAppBar() }, + windowTopAppBar = { isWindowLarge -> if (isWindowLarge) BrandTopAppBar() }, content = {}, ) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/FilesDetailsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/FilesDetailsScreen.kt index 48c559e74..0593aca38 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/FilesDetailsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/FilesDetailsScreen.kt @@ -18,16 +18,21 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi import com.infomaniak.swisstransfer.ui.components.FileItemList +import com.infomaniak.swisstransfer.ui.components.SwissTransferTopAppBar +import com.infomaniak.swisstransfer.ui.components.TopAppBarButton import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParameter import com.infomaniak.swisstransfer.ui.screen.newtransfer.FilesSize import com.infomaniak.swisstransfer.ui.screen.newtransfer.ImportFilesViewModel @@ -57,6 +62,7 @@ fun FilesDetailsScreen( withFileSize = withFileSize, withSpaceLeft = withSpaceLeft, onFileRemoved = getOnFileRemoveCallback(importFilesViewModel, withFileDelete), + navigateBack = navigateBack, ) } } @@ -77,9 +83,65 @@ private fun FilesDetailsScreen( withFileSize: Boolean, withSpaceLeft: Boolean, onFileRemoved: ((uuid: String) -> Unit)? = null, + navigateBack: (() -> Unit), ) { - Column { + Scaffold( + topBar = { + SwissTransferTopAppBar( + navigationMenu = TopAppBarButton.backButton { navigateBack() }, + actionMenus = arrayOf(TopAppBarButton.closeButton { }), // TODO Implement this later + ) + } + ) { paddingValues -> + FilesDetailsComponent( + paddingValues = paddingValues, + files = files, + navigateToDetails = navigateToDetails, + withFileSize = withFileSize, + withSpaceLeft = withSpaceLeft, + onFileRemoved = onFileRemoved + ) + } +} +@Composable +fun FilesDetailsComponent( + paddingValues: PaddingValues = PaddingValues(0.dp), + importFilesViewModel: ImportFilesViewModel = hiltViewModel(), + folderUuid: String? = null, + navigateToDetails: (String) -> Unit, + withFileSize: Boolean, + withSpaceLeft: Boolean, + withFileDelete: Boolean, + navigateBack: (() -> Unit), +) { + // If we don't have a folderUuid, it means we have to load files from importedFiles in ImportFilesViewModel + val files by importFilesViewModel.getFiles(folderUuid).collectAsStateWithLifecycle(null) + + if (files?.isEmpty() == true) navigateBack() + + files?.let { + FilesDetailsComponent( + paddingValues = paddingValues, + files = it, + navigateToDetails = navigateToDetails, + withFileSize = withFileSize, + withSpaceLeft = withSpaceLeft, + onFileRemoved = getOnFileRemoveCallback(importFilesViewModel, withFileDelete), + ) + } +} + +@Composable +fun FilesDetailsComponent( + paddingValues: PaddingValues, + files: List, + navigateToDetails: (String) -> Unit, + withFileSize: Boolean, + withSpaceLeft: Boolean, + onFileRemoved: ((uuid: String) -> Unit)? = null, +) { + Column(modifier = Modifier.padding(paddingValues)) { FilesSize(files, withFileSize = withFileSize, withSpaceLeft) FileItemList( modifier = Modifier.padding(horizontal = Margin.Medium), @@ -90,7 +152,6 @@ private fun FilesDetailsScreen( setUidCheckStatus = { _, _ -> }, onRemoveUid = { onFileRemoved?.invoke(it) }, onClick = { - //TODO Check here if the clicked file is a folder before navigating navigateToDetails(it) } ) @@ -108,6 +169,7 @@ private fun FilesDetailsScreenPreview(@PreviewParameter(FileUiListPreviewParamet withFileSize = true, withSpaceLeft = true, onFileRemoved = {}, + navigateBack = {}, ) } }