updates: switch frequency slider to discrete preset chooser
Replace the 1-24h slider with a SingleChoiceDialog listing 7 presets (3h, 6h, 12h, 24h, 3d, 7d, 15d). Storage stays as an Int hour count under the same preference key, so old values keep working; off-preset values display as the nearest preset but are only overwritten when the user picks something new.
This commit is contained in:
@@ -18,21 +18,18 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -65,7 +62,7 @@ import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK_INTERVAL
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||
import com.aurora.store.util.save
|
||||
import com.aurora.store.viewmodel.all.UpdatesViewModel
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.abs
|
||||
|
||||
@Composable
|
||||
fun UpdatesPreferenceScreen(viewModel: UpdatesViewModel = hiltViewModel()) {
|
||||
@@ -93,10 +90,9 @@ private fun ScreenContent(
|
||||
val autoEnabled = autoMode != UpdateMode.DISABLED.ordinal
|
||||
|
||||
var checkInterval by remember {
|
||||
mutableFloatStateOf(
|
||||
Preferences.getInteger(context, PREFERENCE_UPDATES_CHECK_INTERVAL, 3).toFloat()
|
||||
)
|
||||
mutableIntStateOf(Preferences.getInteger(context, PREFERENCE_UPDATES_CHECK_INTERVAL, 3))
|
||||
}
|
||||
val frequencyEntries = stringArrayResource(R.array.pref_updates_check_frequency_options)
|
||||
var filterFDroid by remember {
|
||||
mutableStateOf(Preferences.getBoolean(context, PREFERENCE_FILTER_FDROID, true))
|
||||
}
|
||||
@@ -107,6 +103,7 @@ private fun ScreenContent(
|
||||
mutableStateOf(Preferences.getBoolean(context, PREFERENCE_UPDATES_EXTENDED))
|
||||
}
|
||||
var showAutoDialog by remember { mutableStateOf(false) }
|
||||
var showFrequencyDialog by remember { mutableStateOf(false) }
|
||||
var showRestrictionsDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val notifPermissionLauncher = rememberLauncherForActivityResult(
|
||||
@@ -179,6 +176,22 @@ private fun ScreenContent(
|
||||
)
|
||||
}
|
||||
|
||||
if (showFrequencyDialog) {
|
||||
SingleChoiceDialog(
|
||||
title = stringResource(R.string.pref_updates_check_frequency),
|
||||
options = frequencyEntries.toList(),
|
||||
selected = selectedFrequencyIndex(checkInterval),
|
||||
onSelect = { index ->
|
||||
showFrequencyDialog = false
|
||||
val hours = UPDATE_INTERVAL_HOURS[index]
|
||||
checkInterval = hours
|
||||
context.save(PREFERENCE_UPDATES_CHECK_INTERVAL, hours)
|
||||
onUpdateAutomatedCheck()
|
||||
},
|
||||
onDismiss = { showFrequencyDialog = false }
|
||||
)
|
||||
}
|
||||
|
||||
if (showRestrictionsDialog) {
|
||||
UpdatesRestrictionsDialog(
|
||||
onUpdateAutomatedCheck = onUpdateAutomatedCheck,
|
||||
@@ -208,32 +221,12 @@ private fun ScreenContent(
|
||||
if (autoEnabled) {
|
||||
item {
|
||||
ListItem(
|
||||
modifier = Modifier.clickable { showFrequencyDialog = true },
|
||||
headlineContent = {
|
||||
Text(stringResource(R.string.pref_updates_check_frequency))
|
||||
},
|
||||
supportingContent = {
|
||||
Column {
|
||||
Text(stringResource(R.string.pref_updates_check_frequency_desc))
|
||||
Spacer(Modifier.height(dimensionResource(R.dimen.margin_small)))
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Slider(
|
||||
value = checkInterval,
|
||||
onValueChange = { checkInterval = it },
|
||||
onValueChangeFinished = {
|
||||
context.save(
|
||||
PREFERENCE_UPDATES_CHECK_INTERVAL,
|
||||
checkInterval.roundToInt()
|
||||
)
|
||||
onUpdateAutomatedCheck()
|
||||
},
|
||||
valueRange = 1f..24f,
|
||||
steps = 22,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Spacer(Modifier.width(dimensionResource(R.dimen.margin_small)))
|
||||
Text(checkInterval.roundToInt().toString())
|
||||
}
|
||||
}
|
||||
Text(frequencyEntries[selectedFrequencyIndex(checkInterval)])
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -448,6 +441,23 @@ private fun UpdatesRestrictionsDialog(onUpdateAutomatedCheck: () -> Unit, onDism
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Discrete preset intervals (in hours) shown in the frequency chooser. Order matches
|
||||
* `R.array.pref_updates_check_frequency_options`.
|
||||
*
|
||||
* Storage stays as a free-form `Int` hour count for backward compatibility with the
|
||||
* old slider, which let users pick any value in 1..24. Existing values that don't
|
||||
* match a preset are mapped to the nearest one for display via [selectedFrequencyIndex],
|
||||
* but the stored value is left untouched until the user actively picks a new option.
|
||||
*/
|
||||
private val UPDATE_INTERVAL_HOURS = intArrayOf(3, 6, 12, 24, 72, 168, 360)
|
||||
|
||||
private fun selectedFrequencyIndex(storedHours: Int): Int {
|
||||
val exact = UPDATE_INTERVAL_HOURS.indexOf(storedHours)
|
||||
if (exact >= 0) return exact
|
||||
return UPDATE_INTERVAL_HOURS.indices.minBy { abs(UPDATE_INTERVAL_HOURS[it] - storedHours) }
|
||||
}
|
||||
|
||||
@PreviewWrapper(ThemePreviewProvider::class)
|
||||
@Preview
|
||||
@Composable
|
||||
|
||||
@@ -25,6 +25,16 @@
|
||||
<item>@string/pref_updates_auto_install</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_updates_check_frequency_options">
|
||||
<item>@string/pref_updates_check_frequency_3h</item>
|
||||
<item>@string/pref_updates_check_frequency_6h</item>
|
||||
<item>@string/pref_updates_check_frequency_12h</item>
|
||||
<item>@string/pref_updates_check_frequency_24h</item>
|
||||
<item>@string/pref_updates_check_frequency_3d</item>
|
||||
<item>@string/pref_updates_check_frequency_7d</item>
|
||||
<item>@string/pref_updates_check_frequency_15d</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="link_urls">
|
||||
<item>https://auroraoss.com/</item>
|
||||
<item>https://gitlab.com/AuroraOSS/AuroraStore/-/wikis/home</item>
|
||||
|
||||
@@ -341,7 +341,14 @@
|
||||
<string name="pref_updates_auto_notify">Check & notify for available updates</string>
|
||||
<string name="pref_updates_auto_install">Check & install available updates automatically</string>
|
||||
<string name="pref_updates_check_frequency">Automatic updates frequency</string>
|
||||
<string name="pref_updates_check_frequency_desc">Configure time interval for automatic updates, in hour.</string>
|
||||
<string name="pref_updates_check_frequency_desc">How often Aurora checks for app updates.</string>
|
||||
<string name="pref_updates_check_frequency_3h">Every 3 hours</string>
|
||||
<string name="pref_updates_check_frequency_6h">Every 6 hours</string>
|
||||
<string name="pref_updates_check_frequency_12h">Every 12 hours</string>
|
||||
<string name="pref_updates_check_frequency_24h">Every 24 hours</string>
|
||||
<string name="pref_updates_check_frequency_3d">Every 3 days</string>
|
||||
<string name="pref_updates_check_frequency_7d">Every 7 days</string>
|
||||
<string name="pref_updates_check_frequency_15d">Every 15 days</string>
|
||||
<string name="failed_to_fetch_report">Failed to fetch privacy report</string>
|
||||
<string name="access_denied_using_vpn">Access denied! Are you using VPN or Tor?</string>
|
||||
<string name="bad_request">Internal error! Please retry after sometime</string>
|
||||
|
||||
Reference in New Issue
Block a user