mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
feat: Add BootBehaviorTile to SettingsScreen
This commit is contained in:
parent
a0bf2d03eb
commit
bd4af5f26a
@ -9,12 +9,16 @@ import androidx.compose.material.icons.filled.Smartphone
|
|||||||
import androidx.compose.material.icons.filled.Translate
|
import androidx.compose.material.icons.filled.Translate
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import app.myzel394.alibi.R
|
import app.myzel394.alibi.R
|
||||||
import app.myzel394.alibi.SUPPORTED_LOCALES
|
import app.myzel394.alibi.SUPPORTED_LOCALES
|
||||||
|
import app.myzel394.alibi.dataStore
|
||||||
import app.myzel394.alibi.db.AppSettings
|
import app.myzel394.alibi.db.AppSettings
|
||||||
import app.myzel394.alibi.ui.components.atoms.SettingsTile
|
import app.myzel394.alibi.ui.components.atoms.SettingsTile
|
||||||
import app.myzel394.alibi.ui.utils.IconResource
|
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.ListDialog
|
||||||
import com.maxkeppeler.sheets.list.models.ListOption
|
import com.maxkeppeler.sheets.list.models.ListOption
|
||||||
import com.maxkeppeler.sheets.list.models.ListSelection
|
import com.maxkeppeler.sheets.list.models.ListSelection
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
/*
|
|
||||||
val BOOT_BEHAVIOR_TITLE_MAP = mapOf<AppSettings.BootBehavior, Int>(
|
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.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)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun BootBehaviorTile() {
|
fun BootBehaviorTile(
|
||||||
|
settings: AppSettings,
|
||||||
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
val showDialog = rememberUseCaseState()
|
val showDialog = rememberUseCaseState()
|
||||||
|
val dataStore = LocalContext.current.dataStore
|
||||||
|
|
||||||
|
fun updateValue(behavior: AppSettings.BootBehavior?) {
|
||||||
|
scope.launch {
|
||||||
|
dataStore.updateData {
|
||||||
|
it.setBootBehavior(
|
||||||
|
behavior
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ListDialog(
|
ListDialog(
|
||||||
state = showDialog,
|
state = showDialog,
|
||||||
header = Header.Default(
|
header = Header.Default(
|
||||||
title = stringResource(R.string.ui_settings_bootBehavior_title),
|
title = stringResource(R.string.ui_settings_bootBehavior_help),
|
||||||
icon = IconSource(
|
icon = IconSource(
|
||||||
painter = IconResource.fromImageVector(Icons.Default.Smartphone)
|
painter = IconResource.fromImageVector(Icons.Default.Smartphone)
|
||||||
.asPainterResource(),
|
.asPainterResource(),
|
||||||
@ -53,18 +77,19 @@ fun BootBehaviorTile() {
|
|||||||
showRadioButtons = true,
|
showRadioButtons = true,
|
||||||
options = AppSettings.BootBehavior.entries.map {
|
options = AppSettings.BootBehavior.entries.map {
|
||||||
ListOption(
|
ListOption(
|
||||||
titleText = stringResource("ui_settings_bootBehavior_values_${it.name}_title"),
|
titleText = stringResource(
|
||||||
subtitleText = stringResource("ui_settings_bootBehavior_values_${it.name}_subtitle"),
|
BOOT_BEHAVIOR_TITLE_MAP[it]!!
|
||||||
|
),
|
||||||
|
subtitleText = stringResource(
|
||||||
|
BOOT_BEHAVIOR_DESCRIPTION_MAP[it]!!
|
||||||
|
),
|
||||||
|
selected = settings.bootBehavior == it,
|
||||||
)
|
)
|
||||||
}.toList(),
|
}.toList() + listOf(
|
||||||
options = IntRange(0, AppSettings.BootBehavior.entries.size).map { index ->
|
|
||||||
val locale = locales[index]!!
|
|
||||||
|
|
||||||
ListOption(
|
ListOption(
|
||||||
titleText = locale.displayName,
|
titleText = stringResource(R.string.ui_settings_bootBehavior_values_nothing_title),
|
||||||
subtitleText = locale.getDisplayName(Locale.ENGLISH),
|
|
||||||
)
|
)
|
||||||
}.toList(),
|
),
|
||||||
positiveButton = SelectionButton(
|
positiveButton = SelectionButton(
|
||||||
icon = IconSource(
|
icon = IconSource(
|
||||||
painter = IconResource.fromImageVector(Icons.Default.CheckCircle)
|
painter = IconResource.fromImageVector(Icons.Default.CheckCircle)
|
||||||
@ -75,11 +100,8 @@ fun BootBehaviorTile() {
|
|||||||
type = ButtonStyle.TEXT,
|
type = ButtonStyle.TEXT,
|
||||||
)
|
)
|
||||||
) { index, _ ->
|
) { index, _ ->
|
||||||
AppCompatDelegate.setApplicationLocales(
|
val behavior = AppSettings.BootBehavior.values().getOrNull(index)
|
||||||
LocaleListCompat.forLanguageTags(
|
updateValue(behavior)
|
||||||
locales[index]!!.toLanguageTag(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
SettingsTile(
|
SettingsTile(
|
||||||
@ -89,6 +111,9 @@ fun BootBehaviorTile() {
|
|||||||
showDialog.show()
|
showDialog.show()
|
||||||
},
|
},
|
||||||
title = stringResource(R.string.ui_settings_bootBehavior_title),
|
title = stringResource(R.string.ui_settings_bootBehavior_title),
|
||||||
|
description = stringResource(
|
||||||
|
BOOT_BEHAVIOR_TITLE_MAP[settings.bootBehavior] ?: R.string.ui_settings_bootBehavior_help
|
||||||
|
),
|
||||||
leading = {
|
leading = {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Smartphone,
|
Icons.Default.Smartphone,
|
||||||
@ -97,5 +122,3 @@ fun BootBehaviorTile() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
@ -41,6 +41,7 @@ import app.myzel394.alibi.db.AppSettings
|
|||||||
import app.myzel394.alibi.ui.SUPPORTS_DARK_MODE_NATIVELY
|
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.AboutTile
|
||||||
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.BitrateTile
|
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.CustomNotificationTile
|
||||||
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.DeleteRecordingsImmediatelyTile
|
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.DeleteRecordingsImmediatelyTile
|
||||||
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.EncoderTile
|
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.EncoderTile
|
||||||
@ -149,6 +150,7 @@ fun SettingsScreen(
|
|||||||
InAppLanguagePicker()
|
InAppLanguagePicker()
|
||||||
DeleteRecordingsImmediatelyTile(settings = settings)
|
DeleteRecordingsImmediatelyTile(settings = settings)
|
||||||
CustomNotificationTile(navController = navController, settings = settings)
|
CustomNotificationTile(navController = navController, settings = settings)
|
||||||
|
BootBehaviorTile(settings = settings)
|
||||||
AboutTile(navController = navController)
|
AboutTile(navController = navController)
|
||||||
AnimatedVisibility(visible = settings.showAdvancedSettings) {
|
AnimatedVisibility(visible = settings.showAdvancedSettings) {
|
||||||
Column(
|
Column(
|
||||||
|
@ -115,4 +115,11 @@
|
|||||||
<string name="notificationChannels_boot_description">If enabled, you\'ll be informed that your recording was interrupted</string>
|
<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_title">Alibi was interrupted</string>
|
||||||
<string name="notification_boot_message">Your device restarted and your recording has been 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>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user