Skip to content

Commit

Permalink
Add navigation for FilesDetailsScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Oct 30, 2024
1 parent ee76361 commit 1333f2c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun FileItemList(
isUidChecked: (String) -> Boolean,
setUidCheckStatus: (String, Boolean) -> Unit,
onRemoveUid: (String) -> Unit,
onClick: (String) -> Unit,
) {
LazyVerticalGrid(
modifier = modifier,
Expand All @@ -52,7 +53,7 @@ fun FileItemList(
isRemoveButtonVisible = isRemoveButtonVisible,
isCheckboxVisible = isCheckboxVisible,
isChecked = { isUidChecked(file.uid) },
onClick = { if (isCheckboxVisible) setUidCheckStatus(file.uid, !isUidChecked(file.uid)) },
onClick = { if (isCheckboxVisible) setUidCheckStatus(file.uid, !isUidChecked(file.uid)) else onClick(file.uid) },
onRemove = { onRemoveUid(file.uid) },
)
}
Expand All @@ -70,6 +71,7 @@ private fun FileItemListPreview(@PreviewParameter(FileUiListPreviewParameter::cl
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = {},
onClick = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ sealed class MainNavigation : NavigationDestination() {
@Serializable
data class TransferDetailsDestination(val transferId: Int) : MainNavigation()

@Serializable
data class FilesDetailsDestination(val fileId: String) : MainNavigation()

@Serializable
data object SettingsDestination : MainNavigation()

Expand Down Expand Up @@ -65,6 +68,9 @@ sealed class NewTransferNavigation : NavigationDestination() {
@Serializable
data object UploadSuccessDestination : NewTransferNavigation()

@Serializable
data class FilesDetailsDestination(val fileId: String) : MainNavigation()

companion object {
val startDestination = ImportFilesDestination
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.infomaniak.swisstransfer.ui.screen.main.received.ReceivedScreen
import com.infomaniak.swisstransfer.ui.screen.main.sent.SentScreen
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsScreenWrapper
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.FilesDetailsScreen

@Composable
fun MainNavHost(
Expand All @@ -54,6 +55,19 @@ fun MainNavHost(
val transferDetails: TransferDetailsDestination = it.toRoute()
TransferDetailsScreen(transferId = transferDetails.transferId)
}
composable<FilesDetailsDestination> {
val filesDetailsDestination: FilesDetailsDestination = it.toRoute()
FilesDetailsScreen(
navigateToDetails = { fileId ->
//TODO check here if specified filedId is a folder
navController.navigate(FilesDetailsDestination(fileId))
},
fileId = filesDetailsDestination.fileId,
navigateBack = { navController.popBackStack() },
withSpaceLeft = false,
onCloseClicked = {},
)
}
composable<SettingsDestination> {
SettingsScreenWrapper()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private fun ReceivedScreen(
isUidChecked = isFileChecked,
setUidCheckStatus = setFileCheckStatus,
onRemoveUid = {},
onClick = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fun SentListScreen(transfers: List<Any>) {
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = {},
onClick = {},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import com.infomaniak.swisstransfer.ui.navigation.NewTransferNavigation
import com.infomaniak.swisstransfer.ui.navigation.NewTransferNavigation.*
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.FilesDetailsScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.ImportFilesScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionsScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.ValidateUserEmailScreen
Expand Down Expand Up @@ -52,5 +54,17 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
// TODO: Use correct TransferType instead of hard-coded value
UploadSuccessScreen(transferType = TransferType.MAIL)
}
composable<FilesDetailsDestination> {
val filesDetailsDestination: FilesDetailsDestination = it.toRoute()
FilesDetailsScreen(
navigateToDetails = { fileId ->
navController.navigate(FilesDetailsDestination(fileId))
},
fileId = filesDetailsDestination.fileId,
withSpaceLeft = false, onCloseClicked = {},
onFileRemoved = {},
navigateBack = { navController.popBackStack() }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.hilt.navigation.compose.hiltViewModel
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.FileItemList
import com.infomaniak.swisstransfer.ui.components.FileUi
Expand All @@ -36,31 +37,57 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@Composable
fun FilesDetailsScreen(
title: String? = null,
filesList: () -> List<FileUi>,
filesDetailsViewModel: FilesDetailsViewModel = hiltViewModel<FilesDetailsViewModel>(),
fileId: String,
navigateToDetails: (String) -> Unit,
withSpaceLeft: Boolean,
onFileRemoved: ((uuid: String) -> Unit)? = null,
onCloseClicked: (() -> Unit),
navigateBack: (() -> Unit),
) {
val files = filesList()
FilesDetailsScreen(
title = {
//TODO Get fileId detail to get the title
"Some Folder"
},
files = { filesDetailsViewModel.getFilesFromUUID(fileId) },
navigateToDetails = navigateToDetails,
withSpaceLeft = withSpaceLeft,
onFileRemoved = onFileRemoved,
onCloseClicked = onCloseClicked,
navigateBack = navigateBack,
)
}

@Composable
private fun FilesDetailsScreen(
title: () -> String,
files: () -> List<FileUi>,
navigateToDetails: (String) -> Unit,
withSpaceLeft: Boolean,
onFileRemoved: ((uuid: String) -> Unit)? = null,
onCloseClicked: (() -> Unit),
navigateBack: (() -> Unit),
) {
val filesToDisplay = files()
Column {
SwissTransferTopAppBar(
title = title,
title = title(),
titleRes = R.string.importFilesScreenTitle,
navigationMenu = TopAppBarButton.backButton { navigateBack() },
TopAppBarButton.closeButton { onCloseClicked() },
)

FilesSize(files, withSpaceLeft)
FilesSize(filesToDisplay, withSpaceLeft)
FileItemList(
modifier = Modifier.padding(horizontal = Margin.Medium),
files = files,
files = filesToDisplay,
isRemoveButtonVisible = onFileRemoved != null,
isCheckboxVisible = false,
isUidChecked = { false },
setUidCheckStatus = { _, _ -> },
onRemoveUid = { onFileRemoved?.invoke(it) },
onClick = { navigateToDetails(it) }
)
}
}
Expand All @@ -71,8 +98,8 @@ private fun FilesDetailsScreenPreview(@PreviewParameter(FileUiListPreviewParamet
SwissTransferTheme {
Surface {
FilesDetailsScreen(
title = "My album",
filesList = { files },
fileId = "",
navigateToDetails = { },
withSpaceLeft = true,
onFileRemoved = { },
onCloseClicked = { },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles

import androidx.lifecycle.ViewModel
import com.infomaniak.swisstransfer.ui.components.FileUi
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class FilesDetailsViewModel @Inject constructor() : ViewModel() {

fun getFilesFromUUID(uuid: String): List<FileUi> {
// TODO Call the right manager to fetch files from Realm
return listOf(
FileUi(
fileName = "How to not get fired.pdf",
uid = "How to not get fired.pdf",
fileSizeInBytes = 10302130,
mimeType = null,
uri = "",
),
FileUi(
fileName = "Opening images tutorial.png",
uid = "Opening images tutorial.png",
fileSizeInBytes = 456782,
mimeType = null,
uri = "https://picsum.photos/200/300",
),
FileUi(
fileName = "The 5 step guide to turning it off and on again.docx",
uid = "The 5 step guide to turning it off and on again.docx",
fileSizeInBytes = 89723143,
mimeType = null,
uri = "",
),
)
}
}

0 comments on commit 1333f2c

Please sign in to comment.