Skip to content

Commit 4db2bd9

Browse files
committed
Settings: Add scan speed setting to General Settings
Expose the existing IPC parallelisation DataStore value as a user-facing setting under a new Advanced category. Pro-gated to match the theme settings pattern.
1 parent 51e3f6b commit 4db2bd9

3 files changed

Lines changed: 77 additions & 8 deletions

File tree

app/src/main/java/eu/darken/myperm/settings/ui/general/GeneralSettingsScreen.kt

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.material.icons.twotone.ColorLens
1212
import androidx.compose.material.icons.twotone.Contrast
1313
import androidx.compose.material.icons.twotone.DarkMode
1414
import androidx.compose.material.icons.twotone.Lock
15+
import androidx.compose.material.icons.twotone.Speed
1516
import androidx.compose.material3.FilledTonalButton
1617
import androidx.compose.material3.Icon
1718
import androidx.compose.material3.IconButton
@@ -59,6 +60,7 @@ fun GeneralSettingsScreenHost() {
5960
val themeColor by vm.themeColor.collectAsState(initial = ThemeColor.BLUE)
6061
val isDynamicColorActive = LocalIsDynamicColorActive.current
6162
val isPro by vm.isPro.collectAsState()
63+
val ipcParallelisation by vm.ipcParallelisation.collectAsState(initial = 0)
6264

6365
GeneralSettingsScreen(
6466
onBack = { navCtrl?.up() },
@@ -67,14 +69,16 @@ fun GeneralSettingsScreenHost() {
6769
themeColor = themeColor,
6870
isDynamicColorActive = isDynamicColorActive,
6971
isPro = isPro,
72+
ipcParallelisation = ipcParallelisation,
7073
onThemeModeSelected = { vm.setThemeMode(it) },
7174
onThemeStyleSelected = { vm.setThemeStyle(it) },
7275
onThemeColorSelected = { vm.setThemeColor(it) },
76+
onIpcParallelisationSelected = { vm.setIpcParallelisation(it) },
7377
onUpgrade = { vm.onUpgrade() },
7478
)
7579
}
7680

77-
private enum class ThemeDialog { MODE, STYLE, COLOR }
81+
private enum class SettingsDialog { THEME_MODE, THEME_STYLE, THEME_COLOR, SCAN_SPEED }
7882

7983
@Composable
8084
fun GeneralSettingsScreen(
@@ -84,12 +88,14 @@ fun GeneralSettingsScreen(
8488
themeColor: ThemeColor = ThemeColor.BLUE,
8589
isDynamicColorActive: Boolean = false,
8690
isPro: Boolean = true,
91+
ipcParallelisation: Int = 0,
8792
onThemeModeSelected: (ThemeMode) -> Unit = {},
8893
onThemeStyleSelected: (ThemeStyle) -> Unit = {},
8994
onThemeColorSelected: (ThemeColor) -> Unit = {},
95+
onIpcParallelisationSelected: (Int) -> Unit = {},
9096
onUpgrade: () -> Unit = {},
9197
) {
92-
var openDialog by remember { mutableStateOf<ThemeDialog?>(null) }
98+
var openDialog by remember { mutableStateOf<SettingsDialog?>(null) }
9399

94100
Scaffold(
95101
topBar = {
@@ -132,15 +138,15 @@ fun GeneralSettingsScreen(
132138
subtitle = stringResource(themeMode.labelRes),
133139
icon = Icons.TwoTone.DarkMode,
134140
enabled = isPro,
135-
onClick = { openDialog = ThemeDialog.MODE },
141+
onClick = { openDialog = SettingsDialog.THEME_MODE },
136142
)
137143
SettingsDivider()
138144
SettingsBaseItem(
139145
title = stringResource(R.string.ui_theme_style_label),
140146
subtitle = stringResource(themeStyle.labelRes),
141147
icon = Icons.TwoTone.Contrast,
142148
enabled = isPro,
143-
onClick = { openDialog = ThemeDialog.STYLE },
149+
onClick = { openDialog = SettingsDialog.THEME_STYLE },
144150
)
145151
SettingsDivider()
146152

@@ -154,13 +160,45 @@ fun GeneralSettingsScreen(
154160
},
155161
icon = Icons.TwoTone.ColorLens,
156162
enabled = colorEnabled,
157-
onClick = { openDialog = ThemeDialog.COLOR },
163+
onClick = { openDialog = SettingsDialog.THEME_COLOR },
164+
)
165+
166+
SettingsCategoryHeader(
167+
text = stringResource(R.string.settings_category_advanced_label),
168+
action = if (!isPro) {{
169+
FilledTonalButton(onClick = onUpgrade) {
170+
Icon(
171+
Icons.TwoTone.Lock,
172+
contentDescription = null,
173+
modifier = Modifier.size(16.dp),
174+
)
175+
Text(
176+
text = stringResource(R.string.upgrade_required_subtitle),
177+
modifier = Modifier.padding(start = 6.dp),
178+
style = MaterialTheme.typography.labelMedium,
179+
)
180+
}
181+
}} else null,
182+
)
183+
184+
SettingsBaseItem(
185+
title = stringResource(R.string.general_settings_scan_speed_label),
186+
subtitle = when (ipcParallelisation) {
187+
1 -> stringResource(R.string.general_settings_scan_speed_1)
188+
2 -> stringResource(R.string.general_settings_scan_speed_2)
189+
3 -> stringResource(R.string.general_settings_scan_speed_3)
190+
4 -> stringResource(R.string.general_settings_scan_speed_4)
191+
else -> stringResource(R.string.general_settings_scan_speed_auto)
192+
},
193+
icon = Icons.TwoTone.Speed,
194+
enabled = isPro,
195+
onClick = { openDialog = SettingsDialog.SCAN_SPEED },
158196
)
159197
}
160198
}
161199

162200
when (openDialog) {
163-
ThemeDialog.MODE -> SingleChoiceSortDialog(
201+
SettingsDialog.THEME_MODE -> SingleChoiceSortDialog(
164202
title = stringResource(R.string.ui_theme_mode_label),
165203
options = ThemeMode.entries.map { LabeledOption(it, it.labelRes) },
166204
selected = themeMode,
@@ -171,7 +209,7 @@ fun GeneralSettingsScreen(
171209
onDismiss = { openDialog = null },
172210
)
173211

174-
ThemeDialog.STYLE -> SingleChoiceSortDialog(
212+
SettingsDialog.THEME_STYLE -> SingleChoiceSortDialog(
175213
title = stringResource(R.string.ui_theme_style_label),
176214
options = ThemeStyle.entries.map { LabeledOption(it, it.labelRes) },
177215
selected = themeStyle,
@@ -182,7 +220,7 @@ fun GeneralSettingsScreen(
182220
onDismiss = { openDialog = null },
183221
)
184222

185-
ThemeDialog.COLOR -> ThemeColorSelectorDialog(
223+
SettingsDialog.THEME_COLOR -> ThemeColorSelectorDialog(
186224
selectedColor = themeColor,
187225
onColorSelected = {
188226
onThemeColorSelected(it)
@@ -191,6 +229,23 @@ fun GeneralSettingsScreen(
191229
onDismiss = { openDialog = null },
192230
)
193231

232+
SettingsDialog.SCAN_SPEED -> SingleChoiceSortDialog(
233+
title = stringResource(R.string.general_settings_scan_speed_label),
234+
options = listOf(
235+
LabeledOption(0, R.string.general_settings_scan_speed_auto),
236+
LabeledOption(1, R.string.general_settings_scan_speed_1),
237+
LabeledOption(2, R.string.general_settings_scan_speed_2),
238+
LabeledOption(3, R.string.general_settings_scan_speed_3),
239+
LabeledOption(4, R.string.general_settings_scan_speed_4),
240+
),
241+
selected = ipcParallelisation,
242+
onSelect = {
243+
onIpcParallelisationSelected(it)
244+
openDialog = null
245+
},
246+
onDismiss = { openDialog = null },
247+
)
248+
194249
null -> {}
195250
}
196251
}

app/src/main/java/eu/darken/myperm/settings/ui/general/GeneralSettingsViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class GeneralSettingsViewModel @Inject constructor(
4343
generalSettings.themeColor.value(color)
4444
}
4545

46+
val ipcParallelisation: Flow<Int> = generalSettings.ipcParallelisation.flow
47+
48+
fun setIpcParallelisation(value: Int) = launch {
49+
generalSettings.ipcParallelisation.value(value)
50+
}
51+
4652
fun onUpgrade() {
4753
navTo(Nav.Main.Upgrade)
4854
}

app/src/main/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@
2222
<string name="settings_category_other_label">Other</string>
2323
<string name="settings_category_gethelp_label">Get help</string>
2424
<string name="settings_category_debug_label">Debug</string>
25+
<string name="settings_category_advanced_label">Advanced</string>
2526

2627
<string name="general_settings_label">General</string>
2728
<string name="general_settings_desc">General tweaks that affect the whole app.</string>
29+
<string name="general_settings_scan_speed_label">Scan speed</string>
30+
<string name="general_settings_scan_speed_desc">Controls parallel operations when scanning apps. Higher values are faster but may cause crashes on some devices.</string>
31+
<string name="general_settings_scan_speed_auto">Auto (recommended)</string>
32+
<string name="general_settings_scan_speed_1">1 (safest)</string>
33+
<string name="general_settings_scan_speed_2">2</string>
34+
<string name="general_settings_scan_speed_3">3</string>
35+
<string name="general_settings_scan_speed_4">4 (fastest)</string>
2836

2937
<string name="changelog_label">Changelog</string>
3038
<string name="settings_acknowledgements_label">Acknowledgements</string>

0 commit comments

Comments
 (0)