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

feature: Email language will be synced to the phone language until the user set a custom one #191

Closed
wants to merge 1 commit into from
Closed
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 @@ -17,6 +17,7 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.settings

import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
Expand All @@ -29,10 +30,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
Expand All @@ -51,18 +54,39 @@ fun SettingsScreenWrapper(
val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null)

appSettings?.let { safeAppSettings ->
val theme = GetSetCallbacks(get = { safeAppSettings.theme }, set = { settingsViewModel.setTheme(it) })
val theme = GetSetCallbacks(
get = { safeAppSettings.theme },
set = { settingsViewModel.setTheme(it) },
)
val validityPeriod =
GetSetCallbacks(get = { safeAppSettings.validityPeriod }, set = { settingsViewModel.setValidityPeriod(it) })
GetSetCallbacks(
get = { safeAppSettings.validityPeriod },
set = { settingsViewModel.setValidityPeriod(it) },
)
val downloadLimit =
GetSetCallbacks(get = { safeAppSettings.downloadLimit }, set = { settingsViewModel.setDownloadLimit(it) })
val emailLanguage =
GetSetCallbacks(get = { safeAppSettings.emailLanguage }, set = { settingsViewModel.setEmailLanguage(it) })
GetSetCallbacks(
get = { safeAppSettings.downloadLimit },
set = { settingsViewModel.setDownloadLimit(it) },
)
val configuration = LocalConfiguration.current
val emailLanguage = GetSetCallbacks(
get = { getEmailLanguage(safeAppSettings, configuration) },
set = { settingsViewModel.setEmailLanguage(it) },
)

SettingsScreenWrapper(theme, validityPeriod, downloadLimit, emailLanguage)
}
}

private fun getEmailLanguage(appSettings: AppSettings, configuration: Configuration): EmailLanguage {
return if (appSettings.hasCustomEmailLanguage) {
appSettings.emailLanguage
} else {
val locale = configuration.locales[0].toString()
EmailLanguage.entries.find { it.code == locale } ?: EmailLanguage.ENGLISH
}
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun SettingsScreenWrapper(
Expand Down
Loading