feat(NetworkWarningDialog): add option to never show again
This commit is contained in:
parent
4d1b21acf0
commit
89dee2ab0b
5 changed files with 56 additions and 17 deletions
|
|
@ -12,4 +12,5 @@ class PreferencesManager(preferences: SharedPreferences) : BasePreferenceManager
|
|||
var devMode by booleanPreference("dev_mode", false)
|
||||
var installer by enumPreference<InstallerSetting>("installer", InstallerSetting.PM)
|
||||
var keepPatchedApks by booleanPreference("keep_patched_apks", false)
|
||||
var showNetworkWarning by booleanPreference("show_network_warning", true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.aliucord.manager.ui.components.dialogs
|
||||
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
|
@ -13,41 +17,69 @@ import com.aliucord.manager.R
|
|||
|
||||
@Composable
|
||||
fun NetworkWarningDialog(
|
||||
onConfirm: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (neverShow: Boolean) -> Unit,
|
||||
onDismiss: (neverShow: Boolean) -> Unit,
|
||||
) {
|
||||
val interactionSource = remember(::MutableInteractionSource)
|
||||
var neverShow by rememberSaveable { mutableStateOf(false) }
|
||||
val rememberedNeverShow by rememberUpdatedState(neverShow)
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
onDismissRequest = { onDismiss(rememberedNeverShow) },
|
||||
properties = DialogProperties(
|
||||
dismissOnClickOutside = false,
|
||||
),
|
||||
confirmButton = {
|
||||
FilledTonalButton(
|
||||
onClick = onConfirm,
|
||||
onClick = { onConfirm(rememberedNeverShow) },
|
||||
colors = ButtonDefaults.filledTonalButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.error,
|
||||
contentColor = MaterialTheme.colorScheme.onError,
|
||||
),
|
||||
) {
|
||||
Text(stringResource(R.string.action_confirm))
|
||||
Text(stringResource(R.string.action_continue))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = onDismiss,
|
||||
onClick = { onDismiss(rememberedNeverShow) },
|
||||
colors = ButtonDefaults.textButtonColors(
|
||||
contentColor = MaterialTheme.colorScheme.onErrorContainer
|
||||
),
|
||||
) {
|
||||
Text(stringResource(R.string.action_cancel))
|
||||
Text(stringResource(R.string.navigation_back))
|
||||
}
|
||||
},
|
||||
title = { Text(stringResource(R.string.network_warning_title)) },
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.network_warning_body),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.network_warning_body),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null,
|
||||
onClick = { neverShow = !rememberedNeverShow },
|
||||
)
|
||||
.padding(end = 16.dp)
|
||||
) {
|
||||
Checkbox(
|
||||
checked = neverShow,
|
||||
onCheckedChange = { neverShow = it },
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
|
||||
Text(stringResource(R.string.network_warning_disable))
|
||||
}
|
||||
}
|
||||
},
|
||||
icon = {
|
||||
Icon(
|
||||
|
|
|
|||
|
|
@ -53,9 +53,10 @@ class PatchOptionsModel(
|
|||
var showNetworkWarningDialog by mutableStateOf(!alreadyShownNetworkWarning && isNetworkDangerous())
|
||||
private set
|
||||
|
||||
fun hideNetworkWarning() {
|
||||
fun hideNetworkWarning(neverShow: Boolean) {
|
||||
showNetworkWarningDialog = false
|
||||
alreadyShownNetworkWarning = true
|
||||
prefs.showNetworkWarning = !neverShow
|
||||
}
|
||||
|
||||
// ---------- Config generation ----------
|
||||
|
|
@ -133,6 +134,9 @@ class PatchOptionsModel(
|
|||
|
||||
init {
|
||||
screenModelScope.launch { fetchPkgNameState() }
|
||||
|
||||
if (!prefs.showNetworkWarning)
|
||||
showNetworkWarningDialog = false
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ class PatchOptionsScreen(
|
|||
if (model.showNetworkWarningDialog) {
|
||||
NetworkWarningDialog(
|
||||
onConfirm = model::hideNetworkWarning,
|
||||
onDismiss = {
|
||||
model.hideNetworkWarning()
|
||||
onDismiss = { neverShow ->
|
||||
model.hideNetworkWarning(neverShow)
|
||||
navigator.pop()
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<string name="action_cancel">Cancel</string>
|
||||
<string name="action_retry">Retry</string>
|
||||
<string name="action_continue">Continue</string>
|
||||
<string name="action_retry_install">Retry installation</string>
|
||||
<string name="action_open_error_log">Open error log</string>
|
||||
<string name="action_apply">Apply</string>
|
||||
|
|
@ -80,7 +81,8 @@
|
|||
|
||||
<string name="network_load_fail">Failed to load</string>
|
||||
<string name="network_warning_title">Metered network</string>
|
||||
<string name="network_warning_body">It appears you are connected to mobile data or a potentially metered network. In order to continue with the installation, several hundred megabytes could be downloaded. Are you sure you want to continue?</string>
|
||||
<string name="network_warning_body">It appears you are connected to mobile data or a potentially metered network. Continuing with the installation may result in several hundred megabytes being downloaded. Are you sure you want to continue?</string>
|
||||
<string name="network_warning_disable">Don\'t show this again</string>
|
||||
|
||||
<string name="version_supported">Supported version:</string>
|
||||
<string name="version_none">None</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue