Skip to content

Commit

Permalink
chore: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Jan 9, 2025
1 parent 660653a commit cd676f1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ fun MainNavHost(
enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None },
exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None },
) {
composable<SentDestination> {
TransfersScreenWrapper(direction = TransferDirection.SENT)
}
composable<SentDestination> { TransfersScreenWrapper(TransferDirection.SENT) }
receivedDestination {
val args = it.toRoute<ReceivedDestination>()
TransfersScreenWrapper(
direction = TransferDirection.RECEIVED,
transferUuid = args.transferUuid,
)
TransfersScreenWrapper(TransferDirection.RECEIVED, transferUuid = args.transferUuid)
}
composable<SettingsDestination> { SettingsScreenWrapper() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main

import android.annotation.SuppressLint
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand All @@ -30,7 +29,6 @@ import com.infomaniak.swisstransfer.ui.screen.main.components.MainScaffold
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

@SuppressLint("RestrictedApi")
@Composable
fun MainScreen(isTransferDeeplink: Boolean = false) {
val navController = rememberNavController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ fun TransferDetailsScreen(
setFileCheckStatus = { fileUid, isChecked ->
transferDetailsViewModel.checkedFiles[fileUid] = isChecked
},
navigateToFilesDetails = {
navigateToFolder?.invoke(it)
},
navigateToFolder = { navigateToFolder?.invoke(it) },
)
TransferDetailsViewModel.TransferDetailsUiState.Loading -> Unit
}
Expand All @@ -107,7 +105,7 @@ private fun TransferDetailsScreen(
getCheckedFiles: () -> SnapshotStateMap<String, Boolean>,
clearCheckedFiles: () -> Unit, // TODO: Unused for now, to be implemented or deleted someday
setFileCheckStatus: (String, Boolean) -> Unit,
navigateToFilesDetails: ((folderUuid: String) -> Unit)? = null,
navigateToFolder: ((folderUuid: String) -> Unit)? = null,
) {

val context = LocalContext.current
Expand Down Expand Up @@ -136,7 +134,7 @@ private fun TransferDetailsScreen(
isMultiselectOn,
getCheckedFiles,
setFileCheckStatus,
navigateToFilesDetails,
navigateToFolder,
)

BottomBar {
Expand Down Expand Up @@ -206,7 +204,7 @@ private fun ColumnScope.FilesList(
isMultiselectOn: Boolean,
getCheckedFiles: () -> SnapshotStateMap<String, Boolean>,
setFileCheckStatus: (String, Boolean) -> Unit,
navigateToFilesDetails: ((folderUuid: String) -> Unit)? = null,
navigateToFolder: ((folderUuid: String) -> Unit)? = null,
) {

val shouldDisplayRecipients = transferRecipients.isNotEmpty()
Expand All @@ -224,7 +222,7 @@ private fun ColumnScope.FilesList(
setFileCheckStatus(fileUid, isChecked)
},
onClick = { fileUuid ->
navigateToFilesDetails?.invoke(fileUuid)
navigateToFolder?.invoke(fileUuid)
},
header = {
Column {
Expand Down Expand Up @@ -333,7 +331,7 @@ private fun Preview(@PreviewParameter(TransferUiListPreviewParameter::class) tra
downloadFiles = {},
clearCheckedFiles = {},
setFileCheckStatus = { _, _ -> },
navigateToFilesDetails = { _ -> },
navigateToFolder = { _ -> },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParamet
import com.infomaniak.swisstransfer.ui.screen.main.components.SwissTransferScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsViewModel
import com.infomaniak.swisstransfer.ui.screen.newtransfer.FilesSize
import com.infomaniak.swisstransfer.ui.screen.newtransfer.ImportFilesViewModel
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
Expand All @@ -34,7 +33,6 @@ fun FilesDetailsScreen(
navigateBack: () -> Unit,
close: (() -> Unit),
) {
// If we don't have a folderUuid, it means we have to load files from importedFiles in ImportFilesViewModel
val files by transferDetailsViewModel.filesInFolder.collectAsStateWithLifecycle()

if (files?.isEmpty() == true) navigateBack()
Expand Down Expand Up @@ -89,15 +87,6 @@ fun FilesDetailsScreen(
}
}

fun getOnFileRemoveCallback(
importFilesViewModel: ImportFilesViewModel,
withFileDelete: Boolean,
): ((String) -> Unit)? {
return if (withFileDelete) {
{ importFilesViewModel.removeFileByUid(it) }
} else null
}

@PreviewAllWindows
@Composable
private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files: List<FileUi>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ import kotlinx.parcelize.Parcelize

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun TransfersScreenWrapper(
direction: TransferDirection,
transferUuid: String? = null,
) {
fun TransfersScreenWrapper(direction: TransferDirection, transferUuid: String? = null) {
var hasTransfer: Boolean by rememberSaveable { mutableStateOf(false) }

TwoPaneScaffold<DestinationContent>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.infomaniak.swisstransfer.ui.previewparameter.FileUiListPreviewParamet
import com.infomaniak.swisstransfer.ui.screen.newtransfer.ImportFilesViewModel
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
import getOnFileRemoveCallback

@Composable
fun NewTransferFilesDetailsScreen(
Expand All @@ -42,7 +41,6 @@ fun NewTransferFilesDetailsScreen(
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.importedFilesDebounced.collectAsStateWithLifecycle()

if (files.isEmpty()) navigateBack()
Expand All @@ -56,6 +54,15 @@ fun NewTransferFilesDetailsScreen(
)
}

private fun getOnFileRemoveCallback(
importFilesViewModel: ImportFilesViewModel,
withFileDelete: Boolean,
): ((String) -> Unit)? {
return if (withFileDelete) {
{ importFilesViewModel.removeFileByUid(it) }
} else null
}

@Composable
private fun NewTransferFilesDetailsScreen(
files: List<FileUi>,
Expand Down

0 comments on commit cd676f1

Please sign in to comment.