Skip to content

Commit

Permalink
chore: Various fixes with top app bar and theme
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Dec 5, 2024
1 parent 38b9b33 commit 7e8b061
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -63,7 +63,7 @@ fun MainNavHost(
composable<SettingsDestination> { SettingsScreenWrapper() }
composable<FilesDetailsDestination> {
val filesDetailsDestination: FilesDetailsDestination = it.toRoute()
FilesDetailsScreen(
FilesDetailsComponent(
navigateToDetails = { folderUuid ->
navController.navigate(FilesDetailsDestination(folderUuid))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -49,7 +49,7 @@ fun MainScaffold(
navType = navType,
currentDestination = currentDestination,
navigateToSelectedItem = navController::navigateToSelectedItem,
largeWindowTopAppBar = largeWindowTopAppBar,
windowTopAppBar = windowTopAppBar,
content = content
)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -129,7 +129,7 @@ private fun NavigationSmallWindowPreview() {
currentDestination = MainNavigation.SentDestination,
navigateToSelectedItem = {},
navType = NavigationSuiteType.NavigationBar,
largeWindowTopAppBar = { BrandTopAppBar() },
windowTopAppBar = { isWindowLarge -> if (isWindowLarge) BrandTopAppBar() },
content = {},
)
}
Expand All @@ -143,7 +143,7 @@ private fun NavigationLargeWindowPreview() {
currentDestination = MainNavigation.SentDestination,
navigateToSelectedItem = {},
navType = NavigationSuiteType.NavigationRail,
largeWindowTopAppBar = { BrandTopAppBar() },
windowTopAppBar = { isWindowLarge -> if (isWindowLarge) BrandTopAppBar() },
content = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +62,7 @@ fun FilesDetailsScreen(
withFileSize = withFileSize,
withSpaceLeft = withSpaceLeft,
onFileRemoved = getOnFileRemoveCallback(importFilesViewModel, withFileDelete),
navigateBack = navigateBack,
)
}
}
Expand All @@ -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<ImportFilesViewModel>(),
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<FileUi>,
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),
Expand All @@ -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)
}
)
Expand All @@ -108,6 +169,7 @@ private fun FilesDetailsScreenPreview(@PreviewParameter(FileUiListPreviewParamet
withFileSize = true,
withSpaceLeft = true,
onFileRemoved = {},
navigateBack = {},
)
}
}
Expand Down

0 comments on commit 7e8b061

Please sign in to comment.