From bee193699983b83bf8dd03ccd30ab6ad596caca4 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Wed, 18 Sep 2024 13:11:50 +0200 Subject: [PATCH 1/3] Use theme stored in realm --- .../infomaniak/swisstransfer/ui/theme/Theme.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt index 777b01c6..e54fd4f3 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt @@ -25,6 +25,10 @@ import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.infomaniak.multiplatform_swisstransfer.common.models.Theme +import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsViewModel val LocalCustomTypography = staticCompositionLocalOf { Typography } val LocalCustomColorScheme: ProvidableCompositionLocal = staticCompositionLocalOf { CustomColorScheme() } @@ -32,7 +36,8 @@ val LocalWindowAdaptiveInfo = staticCompositionLocalOf { err @Composable fun SwissTransferTheme( - darkTheme: Boolean = isDarkTheme(), + settingsViewModel: SettingsViewModel = hiltViewModel(), + darkTheme: Boolean = isDarkTheme(settingsViewModel), content: @Composable () -> Unit, ) { val customColors = if (darkTheme) CustomDarkColorScheme else CustomLightColorScheme @@ -51,10 +56,11 @@ fun SwissTransferTheme( } @Composable -fun isDarkTheme(): Boolean { - // rememberMutableStateOf - // TODO check in realm. If system, isSystemDark, otherwise, - return isSystemInDarkTheme() +fun isDarkTheme(settingsViewModel: SettingsViewModel): Boolean { + val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) + return appSettings?.let { + if (it.theme == Theme.SYSTEM) isSystemInDarkTheme() else it.theme == Theme.DARK + } ?: isSystemInDarkTheme() } object SwissTransferTheme { From a9ce7c75ae89a0708c2eada314bb6d0e430a01a4 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Fri, 20 Sep 2024 09:06:30 +0200 Subject: [PATCH 2/3] Fix preview and avoid passing a viewModel to composable --- .../swisstransfer/ui/MainActivity.kt | 21 ++++- .../ui/screen/main/settings/SettingsScreen.kt | 30 ++++--- .../main/settings/SettingsScreenWrapper.kt | 89 ++++++++++++++----- .../swisstransfer/ui/theme/Theme.kt | 19 +--- 4 files changed, 105 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt index 177e184c..41a7cf22 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt @@ -21,7 +21,16 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.infomaniak.multiplatform_swisstransfer.common.models.Theme import com.infomaniak.swisstransfer.ui.screen.main.MainScreen +import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsViewModel import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import dagger.hilt.android.AndroidEntryPoint @@ -32,9 +41,19 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { - SwissTransferTheme { + SwissTransferTheme(isDarkTheme = isDarkTheme()) { MainScreen() } } } } + +@Composable +fun isDarkTheme(): Boolean { + val settingsViewModel = hiltViewModel() + val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) + + return appSettings?.let { + if (it.theme == Theme.SYSTEM) isSystemInDarkTheme() else it.theme == Theme.DARK + } ?: isSystemInDarkTheme() +} diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index 486377ab..df06f4d4 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt @@ -29,7 +29,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource -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 @@ -51,7 +50,10 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow @Composable fun SettingsScreen( - appSettings: AppSettings, + theme: GetSetCallbacks, + validityPeriod: GetSetCallbacks, + downloadLimit: GetSetCallbacks, + emailLanguage: GetSetCallbacks, onItemClick: (SettingsOptionScreens) -> Unit, getSelectedSetting: () -> SettingsOptionScreens?, ) { @@ -74,7 +76,7 @@ fun SettingsScreen( titleRes = R.string.settingsOptionTheme, isSelected = { selectedSetting == THEME }, icon = AppIcons.PaintbrushPalette, - description = appSettings.theme.getString(), + description = theme.get().getString(), endIcon = CHEVRON, onClick = { onItemClick(THEME) }, ) @@ -93,7 +95,7 @@ fun SettingsScreen( titleRes = R.string.settingsOptionValidityPeriod, isSelected = { selectedSetting == VALIDITY_PERIOD }, icon = AppIcons.ArrowDownFile, - description = appSettings.validityPeriod.getString(), + description = validityPeriod.get().getString(), endIcon = CHEVRON, onClick = { onItemClick(VALIDITY_PERIOD) }, ) @@ -101,7 +103,7 @@ fun SettingsScreen( titleRes = R.string.settingsOptionDownloadLimit, isSelected = { selectedSetting == DOWNLOAD_LIMIT }, icon = AppIcons.Clock, - description = appSettings.downloadLimit.getString(), + description = downloadLimit.get().getString(), endIcon = CHEVRON, onClick = { onItemClick(DOWNLOAD_LIMIT) }, ) @@ -109,7 +111,7 @@ fun SettingsScreen( titleRes = R.string.settingsOptionEmailLanguage, isSelected = { selectedSetting == EMAIL_LANGUAGE }, icon = AppIcons.SpeechBubble, - description = appSettings.emailLanguage.getString(), + description = emailLanguage.get().getString(), endIcon = CHEVRON, onClick = { onItemClick(EMAIL_LANGUAGE) }, ) @@ -182,19 +184,19 @@ enum class SettingsOptionScreens { DISCOVER_INFOMANIAK, SHARE_IDEAS, GIVE_FEEDBACK, } -private class DummyAppSettings( - override var theme: Theme = Theme.SYSTEM, - override var downloadLimit: DownloadLimit = DownloadLimit.TWOHUNDREDFIFTY, - override var emailLanguage: EmailLanguage = EmailLanguage.FRENCH, - override var validityPeriod: ValidityPeriod = ValidityPeriod.THIRTY, -) : AppSettings - @PreviewSmallWindow @Composable private fun SettingsScreenPreview() { SwissTransferTheme { Surface(color = MaterialTheme.colorScheme.background) { - SettingsScreen(appSettings = DummyAppSettings(), onItemClick = {}, getSelectedSetting = { null }) + SettingsScreen( + theme = GetSetCallbacks(get = { Theme.SYSTEM }, set = {}), + validityPeriod = GetSetCallbacks(get = { ValidityPeriod.THIRTY }, set = {}), + downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWOHUNDREDFIFTY }, set = {}), + emailLanguage = GetSetCallbacks(get = { EmailLanguage.ENGLISH }, set = {}), + onItemClick = {}, + getSelectedSetting = { null }, + ) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt index 235a81b0..c80be976 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt @@ -27,47 +27,83 @@ import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier 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 +import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.TwoPaneScaffold import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsOptionScreens.* import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.* -@OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable fun SettingsScreenWrapper( settingsViewModel: SettingsViewModel = hiltViewModel(), ) { val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) + appSettings?.let { safeAppSettings -> - TwoPaneScaffold( - listPane = { ListPane(this, safeAppSettings) }, - detailPane = { DetailPane(safeAppSettings, settingsViewModel, navigator = this) }, - ) + val theme = GetSetCallbacks(get = { safeAppSettings.theme }, set = { settingsViewModel.setTheme(it) }) + val validityPeriod = + 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) }) + + SettingsScreenWrapper(windowAdaptiveInfo, theme, validityPeriod, downloadLimit, emailLanguage) } } @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable -private fun ListPane(navigator: ThreePaneScaffoldNavigator, appSettings: AppSettings) { +fun SettingsScreenWrapper( + windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(), + theme: GetSetCallbacks, + validityPeriod: GetSetCallbacks, + downloadLimit: GetSetCallbacks, + emailLanguage: GetSetCallbacks, +) { + TwoPaneScaffold( + windowAdaptiveInfo = windowAdaptiveInfo, + listPane = { ListPane(navigator = this, theme, validityPeriod, downloadLimit, emailLanguage) }, + detailPane = { DetailPane(navigator = this, theme, validityPeriod, downloadLimit, emailLanguage) }, + ) +} + +@Immutable +class GetSetCallbacks( + val get: () -> T, + val set: (T) -> Unit, +) + +@OptIn(ExperimentalMaterial3AdaptiveApi::class) +@Composable +private fun ListPane( + navigator: ThreePaneScaffoldNavigator, + theme: GetSetCallbacks, + validityPeriod: GetSetCallbacks, + downloadLimit: GetSetCallbacks, + emailLanguage: GetSetCallbacks, +) { val context = LocalContext.current val aboutURL = stringResource(R.string.urlAbout) val userReportURL = stringResource(R.string.urlUserReportAndroid) SettingsScreen( - appSettings, + theme, + validityPeriod, + downloadLimit, + emailLanguage, onItemClick = { item -> when (item) { NOTIFICATIONS -> context.openAppNotificationSettings() @@ -87,9 +123,11 @@ private fun ListPane(navigator: ThreePaneScaffoldNavigator, + theme: GetSetCallbacks, + validityPeriod: GetSetCallbacks, + downloadLimit: GetSetCallbacks, + emailLanguage: GetSetCallbacks, ) { var lastSelectedScreen by rememberSaveable { mutableStateOf(null) } @@ -101,24 +139,24 @@ private fun DetailPane( when (destination) { THEME -> SettingsThemeScreen( - theme = appSettings.theme, + theme = theme.get(), navigateBack = navigateBack, - onThemeUpdate = settingsViewModel::setTheme, + onThemeUpdate = { theme.set(it) }, ) VALIDITY_PERIOD -> SettingsValidityPeriodScreen( - validityPeriod = appSettings.validityPeriod, + validityPeriod = validityPeriod.get(), navigateBack = navigateBack, - onValidityPeriodChange = settingsViewModel::setValidityPeriod, + onValidityPeriodChange = { validityPeriod.set(it) }, ) DOWNLOAD_LIMIT -> SettingsDownloadsLimitScreen( - downloadLimit = appSettings.downloadLimit, + downloadLimit = downloadLimit.get(), navigateBack = navigateBack, - onDownloadLimitChange = settingsViewModel::setDownloadLimit, + onDownloadLimitChange = { downloadLimit.set(it) }, ) EMAIL_LANGUAGE -> SettingsEmailLanguageScreen( - emailLanguage = appSettings.emailLanguage, + emailLanguage = emailLanguage.get(), navigateBack = navigateBack, - onEmailLanguageChange = settingsViewModel::setEmailLanguage, + onEmailLanguageChange = { emailLanguage.set(it) }, ) NOTIFICATIONS, DISCOVER_INFOMANIAK, @@ -142,7 +180,12 @@ private fun NoSelectionEmptyState() { private fun SettingsScreenWrapperPreview() { SwissTransferTheme { Surface(color = MaterialTheme.colorScheme.background) { - SettingsScreenWrapper() + SettingsScreenWrapper( + theme = GetSetCallbacks(get = { Theme.SYSTEM }, set = {}), + validityPeriod = GetSetCallbacks(get = { ValidityPeriod.THIRTY }, set = {}), + downloadLimit = GetSetCallbacks(get = { DownloadLimit.TWOHUNDREDFIFTY }, set = {}), + emailLanguage = GetSetCallbacks(get = { EmailLanguage.ENGLISH }, set = {}), + ) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt index e54fd4f3..a9b995fa 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt @@ -25,10 +25,6 @@ import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color -import androidx.hilt.navigation.compose.hiltViewModel -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.infomaniak.multiplatform_swisstransfer.common.models.Theme -import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsViewModel val LocalCustomTypography = staticCompositionLocalOf { Typography } val LocalCustomColorScheme: ProvidableCompositionLocal = staticCompositionLocalOf { CustomColorScheme() } @@ -36,11 +32,10 @@ val LocalWindowAdaptiveInfo = staticCompositionLocalOf { err @Composable fun SwissTransferTheme( - settingsViewModel: SettingsViewModel = hiltViewModel(), - darkTheme: Boolean = isDarkTheme(settingsViewModel), + isDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit, ) { - val customColors = if (darkTheme) CustomDarkColorScheme else CustomLightColorScheme + val customColors = if (isDarkTheme) CustomDarkColorScheme else CustomLightColorScheme CompositionLocalProvider( LocalCustomTypography provides Typography, LocalTextStyle provides Typography.bodyRegular, @@ -48,21 +43,13 @@ fun SwissTransferTheme( LocalWindowAdaptiveInfo provides currentWindowAdaptiveInfo(), ) { MaterialTheme( - colorScheme = if (darkTheme) DarkColorScheme else LightColorScheme, + colorScheme = if (isDarkTheme) DarkColorScheme else LightColorScheme, shapes = Shapes, content = content, ) } } -@Composable -fun isDarkTheme(settingsViewModel: SettingsViewModel): Boolean { - val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) - return appSettings?.let { - if (it.theme == Theme.SYSTEM) isSystemInDarkTheme() else it.theme == Theme.DARK - } ?: isSystemInDarkTheme() -} - object SwissTransferTheme { val typography: CustomTypography @Composable From b4d5ea1885f67fd7df6c81be10b8c8bc6e9c4211 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Thu, 26 Sep 2024 14:32:44 +0200 Subject: [PATCH 3/3] Code review --- .../swisstransfer/ui/MainActivity.kt | 14 +++++----- .../ui/screen/main/settings/SettingsScreen.kt | 1 + .../main/settings/SettingsScreenWrapper.kt | 10 +------ .../swisstransfer/ui/utils/GetSetCallbacks.kt | 26 +++++++++++++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/infomaniak/swisstransfer/ui/utils/GetSetCallbacks.kt diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt index 41a7cf22..e05e1ba0 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt @@ -21,11 +21,10 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.activity.viewModels import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.infomaniak.multiplatform_swisstransfer.common.models.Theme @@ -37,11 +36,14 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class MainActivity : ComponentActivity() { + private val settingsViewModel: SettingsViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { - SwissTransferTheme(isDarkTheme = isDarkTheme()) { + val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) + SwissTransferTheme(isDarkTheme = isDarkTheme(getTheme = { appSettings?.theme })) { MainScreen() } } @@ -49,11 +51,11 @@ class MainActivity : ComponentActivity() { } @Composable -fun isDarkTheme(): Boolean { +fun isDarkTheme(getTheme: () -> Theme?): Boolean { val settingsViewModel = hiltViewModel() val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) - return appSettings?.let { - if (it.theme == Theme.SYSTEM) isSystemInDarkTheme() else it.theme == Theme.DARK + return getTheme()?.let { + if (it == Theme.SYSTEM) isSystemInDarkTheme() else it== Theme.DARK } ?: isSystemInDarkTheme() } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index df06f4d4..ee21aa19 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt @@ -46,6 +46,7 @@ import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingIt import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingTitle import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme +import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow @Composable diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt index c80be976..395d59c3 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreenWrapper.kt @@ -60,32 +60,24 @@ fun SettingsScreenWrapper( val emailLanguage = GetSetCallbacks(get = { safeAppSettings.emailLanguage }, set = { settingsViewModel.setEmailLanguage(it) }) - SettingsScreenWrapper(windowAdaptiveInfo, theme, validityPeriod, downloadLimit, emailLanguage) + SettingsScreenWrapper(theme, validityPeriod, downloadLimit, emailLanguage) } } @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable fun SettingsScreenWrapper( - windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo(), theme: GetSetCallbacks, validityPeriod: GetSetCallbacks, downloadLimit: GetSetCallbacks, emailLanguage: GetSetCallbacks, ) { TwoPaneScaffold( - windowAdaptiveInfo = windowAdaptiveInfo, listPane = { ListPane(navigator = this, theme, validityPeriod, downloadLimit, emailLanguage) }, detailPane = { DetailPane(navigator = this, theme, validityPeriod, downloadLimit, emailLanguage) }, ) } -@Immutable -class GetSetCallbacks( - val get: () -> T, - val set: (T) -> Unit, -) - @OptIn(ExperimentalMaterial3AdaptiveApi::class) @Composable private fun ListPane( diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/GetSetCallbacks.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/GetSetCallbacks.kt new file mode 100644 index 00000000..28ed3b91 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/GetSetCallbacks.kt @@ -0,0 +1,26 @@ +/* + * 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 . + */ +package com.infomaniak.swisstransfer.ui.utils + +import androidx.compose.runtime.Immutable + +@Immutable +class GetSetCallbacks( + val get: () -> T, + val set: (T) -> Unit, +)