feat: Add BootBehaviorTile to SettingsScreen

This commit is contained in:
Myzel394 2023-10-28 18:40:59 +02:00
parent a0bf2d03eb
commit bd4af5f26a
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 52 additions and 20 deletions

View File

@ -9,12 +9,16 @@ import androidx.compose.material.icons.filled.Smartphone
import androidx.compose.material.icons.filled.Translate
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.core.os.LocaleListCompat
import app.myzel394.alibi.R
import app.myzel394.alibi.SUPPORTED_LOCALES
import app.myzel394.alibi.dataStore
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.components.atoms.SettingsTile
import app.myzel394.alibi.ui.utils.IconResource
@ -26,23 +30,43 @@ import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.list.ListDialog
import com.maxkeppeler.sheets.list.models.ListOption
import com.maxkeppeler.sheets.list.models.ListSelection
import kotlinx.coroutines.launch
import java.util.Locale
/*
val BOOT_BEHAVIOR_TITLE_MAP = mapOf<AppSettings.BootBehavior, Int>(
AppSettings.BootBehavior.SHOW_NOTIFICATION to R.string.ui_settings_bootBehavior_values_SHOW_NOTIFICATION_title,
AppSettings.BootBehavior.START_RECORDING to R.string.ui_settings_bootBehavior_values_START_RECORDING_title
AppSettings.BootBehavior.START_RECORDING to R.string.ui_settings_bootBehavior_values_START_RECORDING_title,
AppSettings.BootBehavior.CONTINUE_RECORDING to R.string.ui_settings_bootBehavior_values_CONTINUE_RECORDING_title,
)
val BOOT_BEHAVIOR_DESCRIPTION_MAP = mapOf<AppSettings.BootBehavior, Int>(
AppSettings.BootBehavior.SHOW_NOTIFICATION to R.string.ui_settings_bootBehavior_values_SHOW_NOTIFICATION_description,
AppSettings.BootBehavior.START_RECORDING to R.string.ui_settings_bootBehavior_values_START_RECORDING_description,
AppSettings.BootBehavior.CONTINUE_RECORDING to R.string.ui_settings_bootBehavior_values_CONTINUE_RECORDING_description,
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BootBehaviorTile() {
fun BootBehaviorTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
fun updateValue(behavior: AppSettings.BootBehavior?) {
scope.launch {
dataStore.updateData {
it.setBootBehavior(
behavior
)
}
}
}
ListDialog(
state = showDialog,
header = Header.Default(
title = stringResource(R.string.ui_settings_bootBehavior_title),
title = stringResource(R.string.ui_settings_bootBehavior_help),
icon = IconSource(
painter = IconResource.fromImageVector(Icons.Default.Smartphone)
.asPainterResource(),
@ -53,18 +77,19 @@ fun BootBehaviorTile() {
showRadioButtons = true,
options = AppSettings.BootBehavior.entries.map {
ListOption(
titleText = stringResource("ui_settings_bootBehavior_values_${it.name}_title"),
subtitleText = stringResource("ui_settings_bootBehavior_values_${it.name}_subtitle"),
titleText = stringResource(
BOOT_BEHAVIOR_TITLE_MAP[it]!!
),
subtitleText = stringResource(
BOOT_BEHAVIOR_DESCRIPTION_MAP[it]!!
),
selected = settings.bootBehavior == it,
)
}.toList(),
options = IntRange(0, AppSettings.BootBehavior.entries.size).map { index ->
val locale = locales[index]!!
}.toList() + listOf(
ListOption(
titleText = locale.displayName,
subtitleText = locale.getDisplayName(Locale.ENGLISH),
titleText = stringResource(R.string.ui_settings_bootBehavior_values_nothing_title),
)
}.toList(),
),
positiveButton = SelectionButton(
icon = IconSource(
painter = IconResource.fromImageVector(Icons.Default.CheckCircle)
@ -75,11 +100,8 @@ fun BootBehaviorTile() {
type = ButtonStyle.TEXT,
)
) { index, _ ->
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(
locales[index]!!.toLanguageTag(),
),
)
val behavior = AppSettings.BootBehavior.values().getOrNull(index)
updateValue(behavior)
},
)
SettingsTile(
@ -89,6 +111,9 @@ fun BootBehaviorTile() {
showDialog.show()
},
title = stringResource(R.string.ui_settings_bootBehavior_title),
description = stringResource(
BOOT_BEHAVIOR_TITLE_MAP[settings.bootBehavior] ?: R.string.ui_settings_bootBehavior_help
),
leading = {
Icon(
Icons.Default.Smartphone,
@ -97,5 +122,3 @@ fun BootBehaviorTile() {
},
)
}
*/

View File

@ -41,6 +41,7 @@ import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.SUPPORTS_DARK_MODE_NATIVELY
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.AboutTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.BitrateTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.BootBehaviorTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.CustomNotificationTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.DeleteRecordingsImmediatelyTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.EncoderTile
@ -149,6 +150,7 @@ fun SettingsScreen(
InAppLanguagePicker()
DeleteRecordingsImmediatelyTile(settings = settings)
CustomNotificationTile(navController = navController, settings = settings)
BootBehaviorTile(settings = settings)
AboutTile(navController = navController)
AnimatedVisibility(visible = settings.showAdvancedSettings) {
Column(

View File

@ -115,4 +115,11 @@
<string name="notificationChannels_boot_description">If enabled, you\'ll be informed that your recording was interrupted</string>
<string name="notification_boot_title">Alibi was interrupted</string>
<string name="notification_boot_message">Your device restarted and your recording has been interrupted</string>
<string name="ui_settings_bootBehavior_values_START_RECORDING_title">Always start recording</string>
<string name="ui_settings_bootBehavior_values_CONTINUE_RECORDING_title">Continue recording</string>
<string name="ui_settings_bootBehavior_values_SHOW_NOTIFICATION_description">Show a notification if recording has been interrupted</string>
<string name="ui_settings_bootBehavior_values_START_RECORDING_description">Continue recording, if interrupted, otherwise start a new recording</string>
<string name="ui_settings_bootBehavior_values_CONTINUE_RECORDING_description">If recording has been interrupted, continue it</string>
<string name="ui_settings_bootBehavior_values_nothing_title">Do nothing</string>
<string name="ui_settings_bootBehavior_help">What should Alibi do when your phone boots up?</string>
</resources>