Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use a dedicated Modifier to handle horizontal padding #238

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks
import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows

private val HORIZONTAL_PADDING = Margin.Medium

@Composable
fun ImportFilesScreen(
importFilesViewModel: ImportFilesViewModel = hiltViewModel<ImportFilesViewModel>(),
Expand Down Expand Up @@ -152,26 +154,24 @@ private fun ImportFilesScreen(
)
},
topButton = { modifier ->
SendButton(filesToImportCount, currentSessionFilesCount, files, modifier, sendTransfer)
SendButton(modifier, filesToImportCount, currentSessionFilesCount, files, sendTransfer)
},
content = {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
FilesToImport(files, removeFileByUid, addFiles, shouldStartByPromptingUserForFiles)
val modifier = Modifier.padding(horizontal = HORIZONTAL_PADDING)
FilesToImport(modifier, files, removeFileByUid, addFiles, shouldStartByPromptingUserForFiles)
Spacer(Modifier.height(Margin.Medium))
ImportTextFields(
modifier = Modifier.padding(horizontal = Margin.Medium),
transferMessage = transferMessage,
selectedTransferType = selectedTransferType.get,
)
SendByOptions(selectedTransferType)
TransferOptions(transferOptionsCallbacks)
ImportTextFields(modifier, transferMessage, selectedTransferType.get)
SendByOptions(modifier, selectedTransferType)
TransferOptions(modifier, transferOptionsCallbacks)
}
}
)
}

@Composable
private fun FilesToImport(
modifier: Modifier,
files: () -> List<FileUi>,
removeFileByUid: (uid: String) -> Unit,
addFiles: (List<Uri>) -> Unit,
Expand All @@ -191,31 +191,25 @@ private fun FilesToImport(

LaunchedEffect(Unit) { if (shouldShowInitialFilePick) pickFiles() }

ImportFilesTitle(modifier = Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.myFilesTitle)
ImportedFilesCard(
modifier = Modifier.padding(horizontal = Margin.Medium),
files = files,
pickFiles = ::pickFiles,
removeFileByUid = removeFileByUid,
)
ImportFilesTitle(modifier, R.string.myFilesTitle)
ImportedFilesCard(modifier, files, ::pickFiles, removeFileByUid)
}

@Composable
private fun ImportTextFields(
modifier: Modifier,
private fun ColumnScope.ImportTextFields(
horizontalPaddingModifier: Modifier,
transferMessage: GetSetCallbacks<String>,
selectedTransferType: () -> TransferTypeUi,
) {
Column(modifier) {
EmailAddressesTextFields(Modifier.fillMaxWidth(), selectedTransferType)
SwissTransferTextField(
modifier = Modifier.fillMaxWidth(),
label = stringResource(R.string.transferMessagePlaceholder),
isRequired = false,
minLineNumber = 3,
onValueChange = transferMessage.set,
)
}
val modifier = horizontalPaddingModifier.fillMaxWidth()
EmailAddressesTextFields(modifier, selectedTransferType)
SwissTransferTextField(
modifier = modifier,
label = stringResource(R.string.transferMessagePlaceholder),
isRequired = false,
minLineNumber = 3,
onValueChange = transferMessage.set,
)
}

@Composable
Expand All @@ -242,23 +236,23 @@ private fun ColumnScope.EmailAddressesTextFields(modifier: Modifier, selectedTra
}

@Composable
private fun SendByOptions(selectedTransferType: GetSetCallbacks<TransferTypeUi>) {
ImportFilesTitle(Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.transferTypeTitle)
TransferTypeButtons(selectedTransferType)
private fun SendByOptions(modifier: Modifier, selectedTransferType: GetSetCallbacks<TransferTypeUi>) {
ImportFilesTitle(modifier, R.string.transferTypeTitle)
TransferTypeButtons(HORIZONTAL_PADDING, selectedTransferType)
}

@Composable
private fun TransferOptions(transferOptionsCallbacks: TransferOptionsCallbacks) {
private fun TransferOptions(modifier: Modifier, transferOptionsCallbacks: TransferOptionsCallbacks) {

var showTransferOption by rememberSaveable { mutableStateOf<TransferOptionType?>(null) }

fun closeTransferOption() {
showTransferOption = null
}

ImportFilesTitle(Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.advancedSettingsTitle)
ImportFilesTitle(modifier, R.string.advancedSettingsTitle)
TransferOptionsTypes(
modifier = Modifier.padding(horizontal = Margin.Medium),
modifier = modifier,
transferOptionsStates = transferOptionsCallbacks.transferOptionsStates,
onClick = { selectedOptionType -> showTransferOption = selectedOptionType },
)
Expand Down Expand Up @@ -311,10 +305,10 @@ private fun ImportFilesTitle(modifier: Modifier = Modifier, @StringRes titleRes:

@Composable
private fun SendButton(
modifier: Modifier,
filesToImportCount: () -> Int,
currentSessionFilesCount: () -> Int,
importedFiles: () -> List<FileUi>,
modifier: Modifier,
navigateToUploadProgress: () -> Unit,
) {
val remainingFilesCount = filesToImportCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.component
import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.Dp
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferType
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons
Expand All @@ -40,11 +42,11 @@ import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark

@Composable
fun TransferTypeButtons(transferType: GetSetCallbacks<TransferTypeUi>) {
fun TransferTypeButtons(horizontalPadding: Dp, transferType: GetSetCallbacks<TransferTypeUi>) {
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState())
.padding(horizontal = Margin.Medium),
.padding(horizontal = horizontalPadding),
horizontalArrangement = Arrangement.spacedBy(Margin.Mini),
) {
for (transferTypeEntry in TransferTypeUi.entries) {
Expand Down Expand Up @@ -108,7 +110,10 @@ enum class TransferTypeUi(
private fun TransferTypeButtonsPreview() {
SwissTransferTheme {
Surface {
TransferTypeButtons(GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {}))
TransferTypeButtons(
horizontalPadding = Margin.Medium,
transferType = GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {}),
)
}
}
}
Loading