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: Rename Transfer Options related code #164

Merged
merged 4 commits into from
Nov 12, 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 @@ -57,8 +57,6 @@ sealed class NewTransferNavigation : NavigationDestination() {
@Serializable
data object TransferTypeDestination : NewTransferNavigation()
@Serializable
data object TransferOptionsDestination : NewTransferNavigation()
@Serializable
data object ValidateUserEmailDestination : NewTransferNavigation()

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun MainScreen() {

@PreviewAllWindows
@Composable
private fun MainScreenPreview() {
private fun Preview() {
SwissTransferTheme {
MainScreen()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun ReceivedEmptyFab(isMessageVisible: () -> Boolean) {

@PreviewLightAndDark
@Composable
private fun ReceivedEmptyFabPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
Row(Modifier.fillMaxSize(), horizontalArrangement = Arrangement.End, verticalAlignment = Alignment.Bottom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fun SentEmptyScreen() {

@PreviewAllWindows
@Composable
private fun SentEmptyScreenPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
SentEmptyScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private fun SentScreen(transfers: List<Any>?) {

@PreviewAllWindows
@Composable
private fun SentScreenPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
SentScreen(transfers = emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class DownloadLimitOption(
ONE({ DownloadLimit.ONE.value });

companion object {
fun DownloadLimit.toAdvancedOption() = when (this) {
fun DownloadLimit.toTransferOption() = when (this) {
DownloadLimit.TWO_HUNDRED_FIFTY -> TWO_HUNDRED_FIFTY
DownloadLimit.ONE_HUNDRED -> ONE_HUNDRED
DownloadLimit.TWENTY -> TWENTY
Expand All @@ -65,7 +65,7 @@ enum class DownloadLimitOption(

@PreviewAllWindows
@Composable
private fun SettingsThemeScreenPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsDownloadsLimitScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum class EmailLanguageOption(
SPANISH({ stringResource(R.string.settingsEmailLanguageValueSpanish) }, imageVectorResId = R.drawable.flag_es);

companion object {
fun EmailLanguage.toAdvancedOption() = when (this) {
fun EmailLanguage.toTransferOption() = when (this) {
EmailLanguage.ENGLISH -> ENGLISH
EmailLanguage.FRENCH -> FRENCH
EmailLanguage.GERMAN -> GERMAN
Expand All @@ -68,7 +68,7 @@ enum class EmailLanguageOption(

@PreviewAllWindows
@Composable
private fun SettingsThemeScreenPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsEmailLanguageScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum class ValidityPeriodOption(
ONE({ getValidityPeriodTitle(ValidityPeriod.ONE) });

companion object {
fun ValidityPeriod.toAdvancedOption() = when (this) {
fun ValidityPeriod.toTransferOption() = when (this) {
ValidityPeriod.THIRTY -> THIRTY
ValidityPeriod.FIFTEEN -> FIFTEEN
ValidityPeriod.SEVEN -> SEVEN
Expand All @@ -72,7 +72,7 @@ private fun getValidityPeriodTitle(validityPeriod: ValidityPeriod): String {

@PreviewAllWindows
@Composable
private fun SettingsThemeScreenPreview() {
private fun Preview() {
SwissTransferTheme {
Surface {
SettingsValidityPeriodScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package com.infomaniak.swisstransfer.ui.screen.newtransfer

import android.net.Uri
import androidx.compose.runtime.*
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -32,15 +35,15 @@ import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager
import com.infomaniak.sentry.SentryLog
import com.infomaniak.swisstransfer.di.IoDispatcher
import com.infomaniak.swisstransfer.ui.screen.main.settings.DownloadLimitOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.DownloadLimitOption.Companion.toAdvancedOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.DownloadLimitOption.Companion.toTransferOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.EmailLanguageOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.EmailLanguageOption.Companion.toAdvancedOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.EmailLanguageOption.Companion.toTransferOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.ValidityPeriodOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.ValidityPeriodOption.Companion.toAdvancedOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.ValidityPeriodOption.Companion.toTransferOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.AdvancedOptionsCallbacks
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.AdvancedOptionsState
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.PasswordTransferOption
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionState
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionsCallbacks
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType
import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks
import com.infomaniak.swisstransfer.workers.UploadWorker
Expand Down Expand Up @@ -155,7 +158,7 @@ class ImportFilesViewModel @Inject constructor(
}
//endregion

//region Transfer Advanced Options
//region Transfer Options
val selectedValidityPeriodOption = savedStateHandle.getStateFlow(
key = SELECTED_VALIDITY_PERIOD_KEY,
initialValue = ValidityPeriodOption.THIRTY
Expand Down Expand Up @@ -192,12 +195,12 @@ class ImportFilesViewModel @Inject constructor(
savedStateHandle[SELECTED_LANGUAGE_KEY] = language
}

fun initTransferAdvancedOptionsValues() {
fun initTransferOptionsValues() {
viewModelScope.launch(ioDispatcher) {
appSettingsManager.getAppSettings()?.let {
selectTransferValidityPeriod(it.validityPeriod.toAdvancedOption())
selectTransferDownloadLimit(it.downloadLimit.toAdvancedOption())
selectTransferLanguage(it.emailLanguage.toAdvancedOption())
selectTransferValidityPeriod(it.validityPeriod.toTransferOption())
selectTransferDownloadLimit(it.downloadLimit.toTransferOption())
selectTransferLanguage(it.emailLanguage.toTransferOption())
} ?: run {
SentryLog.e(TAG, "AppSettings is null in ImportFilesScreen, it should not happened")
selectTransferValidityPeriod(ValidityPeriodOption.THIRTY)
Expand All @@ -207,10 +210,10 @@ class ImportFilesViewModel @Inject constructor(
}
}

fun getTransferAdvancedOptionsCallbacks(advancedOptionsStates: () -> List<AdvancedOptionsState>): AdvancedOptionsCallbacks {
return AdvancedOptionsCallbacks(
advancedOptionsStates = advancedOptionsStates,
onAdvancedOptionsValueSelected = ::onAdvancedOptionsValueSelected,
fun getTransferOptionsCallbacks(transferOptionsStates: () -> List<TransferOptionState>): TransferOptionsCallbacks {
return TransferOptionsCallbacks(
transferOptionsStates = transferOptionsStates,
onTransferOptionValueSelected = ::onTransferOptionValueSelected,
password = GetSetCallbacks(
get = { transferPassword },
set = { transferPassword = it },
Expand All @@ -219,7 +222,7 @@ class ImportFilesViewModel @Inject constructor(
)
}

private fun onAdvancedOptionsValueSelected(option: SettingOption) {
private fun onTransferOptionValueSelected(option: SettingOption) {
when (option) {
is ValidityPeriodOption -> selectTransferValidityPeriod(option)
is DownloadLimitOption -> selectTransferDownloadLimit(option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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.ImportFilesScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionsScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.ValidateUserEmailScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadErrorScreen
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.UploadProgressScreen
Expand All @@ -43,9 +42,6 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
},
)
}
composable<TransferOptionsDestination> {
TransferOptionsScreen()
}
composable<ValidateUserEmailDestination> {
ValidateUserEmailScreen()
}
Expand Down
Loading
Loading