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

Add email language settings UI #36

Merged
merged 8 commits into from
Aug 27, 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 @@ -48,7 +48,8 @@ fun SettingsValidityPeriodScreen() {

enum class ValidityPeriod(
override val title: @Composable () -> String,
override val icon: ImageVector? = null
override val imageVector: ImageVector? = null,
override val imageVectorResId: Int? = null,
) : SettingOption {
THIRTY({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 30, 30) }),
FIFTEEN({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 15, 15) }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

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

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOption
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingTitle
import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SingleSelectOptions
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet

@Composable
fun SettingsEmailLanguageScreen() {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
SettingTitle(titleRes = R.string.settingsEmailLanguageTitle)

val (selectedItem, setSelectedItem) = rememberSaveable { mutableIntStateOf(0) } // TODO: Use DataStore or Realm
SingleSelectOptions(EmailLanguage.entries, { selectedItem }, setSelectedItem)
}
}

enum class EmailLanguage(
override val title: @Composable () -> String,
override val imageVector: ImageVector? = null,
override val imageVectorResId: Int? = null
) : SettingOption {
ENGLISH({ stringResource(R.string.settingsEmailLanguageValueEnglish) }, imageVectorResId = R.drawable.flag_gb),
FRENCH({ stringResource(R.string.settingsEmailLanguageValueFrench) }, imageVectorResId = R.drawable.flag_fr),
GERMAN({ stringResource(R.string.settingsEmailLanguageValueGerman) }, imageVectorResId = R.drawable.flag_ge),
ITALIAN({ stringResource(R.string.settingsEmailLanguageValueItalian) }, imageVectorResId = R.drawable.flag_it),
SPANISH({ stringResource(R.string.settingsEmailLanguageValueSpanish) }, imageVectorResId = R.drawable.flag_es),
}

@PreviewMobile
@PreviewTablet
@Composable
private fun SettingsThemeScreenPreview() {
SwissTransferTheme {
Surface {
SettingsEmailLanguageScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private fun DetailPane(navigator: ThreePaneScaffoldNavigator<SettingsOptionScree
THEME -> SettingsThemeScreen()
VALIDITY_PERIOD -> SettingsValidityPeriodScreen()
DOWNLOAD_LIMIT -> Unit
EMAIL_LANGUAGE -> Unit
EMAIL_LANGUAGE -> SettingsEmailLanguageScreen()
NOTIFICATIONS,
DISCOVER_INFOMANIAK,
SHARE_IDEAS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ fun SettingsThemeScreen() {
}
}

enum class ThemeOption(override val title: @Composable () -> String, override val icon: ImageVector) : SettingOption {
enum class ThemeOption(
override val title: @Composable () -> String,
override val imageVector: ImageVector,
override val imageVectorResId: Int? = null
) : SettingOption {
SYSTEM({ stringResource(R.string.settingsOptionThemeSystem) }, AppIcons.BlackAndWhiteCircle),
LIGHT({ stringResource(R.string.settingsOptionThemeLight) }, AppIcons.WhiteCircle),
DARK({ stringResource(R.string.settingsOptionThemeDark) }, AppIcons.BlackCircle),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.SharpRippleButton
Expand Down Expand Up @@ -91,7 +92,11 @@ private fun SettingOptionItem(item: SettingOption, isSelected: Boolean, onClick:

interface SettingOption {
val title: @Composable () -> String
val imageVector: ImageVector?
val imageVectorResId: Int?

val icon: ImageVector?
@Composable get() = imageVector ?: imageVectorResId?.let { ImageVector.vectorResource(it) }
}

@Preview(name = "Light")
Expand All @@ -103,7 +108,8 @@ private fun SettingOptionItemPreview() {
Column {
val item = object : SettingOption {
override val title: @Composable () -> String = { stringResource(R.string.appName) }
override val icon: ImageVector = AppIcons.Add
override val imageVector: ImageVector = AppIcons.Add
override val imageVectorResId = null
}
SettingOptionItem(item, true) {}
SettingOptionItem(item, false) {}
Expand Down
Loading
Loading