Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Sep 4, 2024
1 parent e6dd8ad commit fae2b1d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private fun SettingsThemeScreenPreview() {
SettingsDownloadsLimitScreen(
downloadLimit = DownloadLimit.TWOHUNDREDFIFTY,
navigateBack = {},
onDownloadLimitChange = {}
onDownloadLimitChange = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
fun SettingsEmailLanguageScreen(
emailLanguage: EmailLanguage,
navigateBack: (() -> Unit)?,
onEmailLanguageChange: (EmailLanguage) -> Unit
onEmailLanguageChange: (EmailLanguage) -> Unit,
) {
Scaffold(topBar = {
val canDisplayBackButton = navigateBack?.let { TopAppBarButton.backButton(navigateBack) }
Expand Down Expand Up @@ -88,7 +88,7 @@ private fun SettingsThemeScreenPreview() {
SettingsEmailLanguageScreen(
emailLanguage = EmailLanguage.FRENCH,
navigateBack = {},
onEmailLanguageChange = {}
onEmailLanguageChange = {},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fun SettingsScreen(
description = appSettings.theme.getString(),
endIcon = CHEVRON,
onClick = { onItemClick(THEME) },
)
SettingItem(
titleRes = R.string.settingsOptionNotifications,
isSelected = { selectedSetting == NOTIFICATIONS },
Expand All @@ -93,7 +94,7 @@ fun SettingsScreen(
SettingItem(
titleRes = R.string.settingsOptionValidityPeriod,
isSelected = { selectedSetting == VALIDITY_PERIOD },
icon = AppIcons.FileBadgeArrowDown,
icon = AppIcons.ArrowDownFile,
description = appSettings.validityPeriod.getString(),
endIcon = CHEVRON,
onClick = { onItemClick(VALIDITY_PERIOD) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ fun SettingsScreenWrapper(
detailPane = { DetailPane(safeAppSettings, settingsViewModel, navigator = this) },
)
}
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
private fun DetailPane(
settingsViewModel: SettingsViewModel,
navigator: ThreePaneScaffoldNavigator<SettingsOptionScreens>,
appSettings: AppSettings
) {
var lastSelectedScreen by rememberSaveable { mutableStateOf<SettingsOptionScreens?>(null) }
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
private fun ListPane(navigator: ThreePaneScaffoldNavigator<SettingsOptionScreens>, appSettings: AppSettings) {
val context = LocalContext.current
val aboutURL = stringResource(R.string.urlAbout)
val userReportURL = stringResource(R.string.urlUserReportAndroid)

SettingsScreen(
appSettings,
Expand Down Expand Up @@ -103,45 +102,49 @@ private fun DetailPane(
val navigateBack: (() -> Unit)? = if (navigator.canNavigateBack()) navigateBackCallback else null

when (destination) {
THEME -> {
SettingsThemeScreen(appSettings.theme, navigateBack) {
settingsViewModel.setTheme(it)
}
DOWNLOAD_LIMIT -> {
val downloadLimit = appSettings.downloadLimit
SettingsDownloadsLimitScreen(downloadLimit, navigateBack) {
settingsViewModel.setDownloadLimit(it)
}
}
EMAIL_LANGUAGE -> {
val emailLanguage = appSettings.emailLanguage
SettingsEmailLanguageScreen(emailLanguage, navigateBack) {
settingsViewModel.setEmailLanguage(it)
}
}
NOTIFICATIONS,
DISCOVER_INFOMANIAK,
SHARE_IDEAS,
GIVE_FEEDBACK -> Unit
null -> NoSelectionEmptyState()
}
THEME -> SettingsThemeScreen(
theme = appSettings.theme,
navigateBack = navigateBack,
onThemeUpdate = settingsViewModel::setTheme,
)
VALIDITY_PERIOD -> SettingsValidityPeriodScreen(
validityPeriod = appSettings.validityPeriod,
navigateBack = navigateBack,
onValidityPeriodChange = settingsViewModel::setValidityPeriod,
)
DOWNLOAD_LIMIT -> SettingsDownloadsLimitScreen(
downloadLimit = appSettings.downloadLimit,
navigateBack = navigateBack,
onDownloadLimitChange = settingsViewModel::setDownloadLimit,
)
EMAIL_LANGUAGE -> SettingsEmailLanguageScreen(
emailLanguage = appSettings.emailLanguage,
navigateBack = navigateBack,
onEmailLanguageChange = settingsViewModel::setEmailLanguage,
)
NOTIFICATIONS,
DISCOVER_INFOMANIAK,
SHARE_IDEAS,
GIVE_FEEDBACK -> Unit
null -> NoSelectionEmptyState()
}
}

// Show the detail pane content if selected item is available
@Composable
private fun NoSelectionEmptyState() {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Select a setting item", color = SwissTransferTheme.colors.secondaryTextColor)
}
// Show the detail pane content if selected item is available
@Composable
private fun NoSelectionEmptyState() {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Select a setting item", color = SwissTransferTheme.colors.secondaryTextColor)
}
}

@PreviewMobile
@PreviewTablet
@Composable
private fun SettingsScreenWrapperPreview() {
SwissTransferTheme {
Surface(color = MaterialTheme.colorScheme.background) {
SettingsScreenWrapper()
}
@PreviewMobile
@PreviewTablet
@Composable
private fun SettingsScreenWrapperPreview() {
SwissTransferTheme {
Surface(color = MaterialTheme.colorScheme.background) {
SettingsScreenWrapper()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
fun SettingsThemeScreen(
theme: Theme,
navigateBack: (() -> Unit)?,
onThemeUpdate: (Theme) -> Unit
onThemeUpdate: (Theme) -> Unit,
) {
Scaffold(topBar = {
val canDisplayBackButton = navigateBack?.let { TopAppBarButton.backButton(navigateBack) }
Expand Down Expand Up @@ -87,7 +87,7 @@ enum class ThemeOption(
private fun SettingsThemeScreenPreview() {
SwissTransferTheme {
Surface {
SettingsThemeScreen(Theme.SYSTEM, {}, {})
SettingsThemeScreen(theme = Theme.SYSTEM, navigateBack = {}, onThemeUpdate = {})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.infomaniak.swisstransfer.ui.screen.main.settings

import androidx.lifecycle.ViewModel
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
google()
//mavenLocal() TODO Do not put this in production
// mavenLocal() // TODO Do not put this in production
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
Expand Down

0 comments on commit fae2b1d

Please sign in to comment.