fix: show network warning dialog for all ui paths
Previously this dialog could only be seen on the home screen when the patch options screen is about launched due to pressing the Install button. This did not include updating existing installations which also launched the patch options screen. I moved the warning dialog to the patch options screen directly instead.
This commit is contained in:
parent
b7f2e7abe5
commit
0c43b3f0b6
5 changed files with 53 additions and 61 deletions
|
|
@ -5,6 +5,7 @@ import androidx.compose.material.icons.filled.Warning
|
|||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.aliucord.manager.R
|
||||
|
||||
@Composable
|
||||
|
|
@ -14,6 +15,9 @@ fun NetworkWarningDialog(
|
|||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
properties = DialogProperties(
|
||||
dismissOnClickOutside = false,
|
||||
),
|
||||
confirmButton = {
|
||||
FilledTonalButton(
|
||||
onClick = onConfirm,
|
||||
|
|
|
|||
|
|
@ -4,14 +4,11 @@ import android.app.Application
|
|||
import android.content.Intent
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.provider.Settings
|
||||
import android.telephony.TelephonyManager
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.core.net.toUri
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
|
|
@ -71,37 +68,6 @@ class HomeModel(
|
|||
application.startActivity(launchIntent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the device is connected on a metered WIFI connection or through any type of mobile data,
|
||||
* to avoid unknowingly downloading a lot of stuff through a potentially metered network.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
fun isNetworkDangerous(): Boolean {
|
||||
val connectivity = application.getSystemService<ConnectivityManager>()
|
||||
?: error("Unable to get system connectivity service")
|
||||
|
||||
if (connectivity.isActiveNetworkMetered) return true
|
||||
|
||||
when (val info = connectivity.activeNetworkInfo) {
|
||||
null -> return false
|
||||
else -> {
|
||||
if (info.isRoaming) return true
|
||||
if (info.type == ConnectivityManager.TYPE_WIFI) return false
|
||||
}
|
||||
}
|
||||
|
||||
val telephony = application.getSystemService<TelephonyManager>()
|
||||
?: error("Unable to get system telephony service")
|
||||
|
||||
val dangerousMobileDataStates = arrayOf(
|
||||
/* TelephonyManager.DATA_DISCONNECTING */ 4,
|
||||
TelephonyManager.DATA_CONNECTED,
|
||||
TelephonyManager.DATA_CONNECTING,
|
||||
)
|
||||
|
||||
return dangerousMobileDataStates.contains(telephony.dataState)
|
||||
}
|
||||
|
||||
fun fetchInstallations() = screenModelScope.launchBlock {
|
||||
installations = InstallsState.Fetching
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
|
|||
import com.aliucord.manager.R
|
||||
import com.aliucord.manager.ui.components.AnimatedVersionDisplay
|
||||
import com.aliucord.manager.ui.components.ProjectHeader
|
||||
import com.aliucord.manager.ui.components.dialogs.NetworkWarningDialog
|
||||
import com.aliucord.manager.ui.screens.home.components.*
|
||||
import com.aliucord.manager.ui.screens.patchopts.PatchOptionsScreen
|
||||
import com.aliucord.manager.ui.screens.plugins.PluginsScreen
|
||||
|
|
@ -51,30 +50,6 @@ class HomeScreen : Screen {
|
|||
onPauseOrDispose {}
|
||||
}
|
||||
|
||||
var showNetworkWarningDialog by remember { mutableStateOf(false) }
|
||||
val onClickInstall: () -> Unit = remember {
|
||||
{
|
||||
if (model.isNetworkDangerous()) {
|
||||
showNetworkWarningDialog = true
|
||||
} else {
|
||||
navigator.push(PatchOptionsScreen(supportedVersion = model.supportedVersion))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: trigger this for updates too?
|
||||
if (showNetworkWarningDialog) {
|
||||
NetworkWarningDialog(
|
||||
onConfirm = {
|
||||
showNetworkWarningDialog = false
|
||||
navigator.push(PatchOptionsScreen(supportedVersion = model.supportedVersion))
|
||||
},
|
||||
onDismiss = {
|
||||
showNetworkWarningDialog = false
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = { HomeAppBar() },
|
||||
) { padding ->
|
||||
|
|
@ -82,13 +57,13 @@ class HomeScreen : Screen {
|
|||
is InstallsState.Fetched -> PresentInstallsContent(
|
||||
model = model,
|
||||
padding = padding,
|
||||
onClickInstall = onClickInstall,
|
||||
onClickInstall = { navigator.push(PatchOptionsScreen(supportedVersion = model.supportedVersion)) },
|
||||
)
|
||||
|
||||
InstallsState.Fetching -> LoadingInstallsContent(padding = padding)
|
||||
|
||||
InstallsState.None -> NoInstallsContent(
|
||||
onClickInstall = onClickInstall,
|
||||
onClickInstall = { navigator.push(PatchOptionsScreen(supportedVersion = model.supportedVersion)) },
|
||||
modifier = Modifier
|
||||
.padding(padding.exclude(PaddingValuesSides.Bottom)),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ package com.aliucord.manager.ui.screens.patchopts
|
|||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import android.net.ConnectivityManager
|
||||
import android.telephony.TelephonyManager
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.core.content.getSystemService
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
import cafe.adriel.voyager.core.model.screenModelScope
|
||||
import com.aliucord.manager.manager.PreferencesManager
|
||||
|
|
@ -97,6 +100,37 @@ class PatchOptionsModel(
|
|||
val isDevMode: Boolean
|
||||
get() = prefs.devMode
|
||||
|
||||
/**
|
||||
* Check whether the device is connected on a metered WIFI connection or through any type of mobile data,
|
||||
* to avoid unknowingly downloading a lot of stuff through a potentially metered network.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
fun isNetworkDangerous(): Boolean {
|
||||
val connectivity = context.getSystemService<ConnectivityManager>()
|
||||
?: error("Unable to get system connectivity service")
|
||||
|
||||
if (connectivity.isActiveNetworkMetered) return true
|
||||
|
||||
when (val info = connectivity.activeNetworkInfo) {
|
||||
null -> return false
|
||||
else -> {
|
||||
if (info.isRoaming) return true
|
||||
if (info.type == ConnectivityManager.TYPE_WIFI) return false
|
||||
}
|
||||
}
|
||||
|
||||
val telephony = context.getSystemService<TelephonyManager>()
|
||||
?: error("Unable to get system telephony service")
|
||||
|
||||
val dangerousMobileDataStates = arrayOf(
|
||||
/* TelephonyManager.DATA_DISCONNECTING */ 4,
|
||||
TelephonyManager.DATA_CONNECTED,
|
||||
TelephonyManager.DATA_CONNECTING,
|
||||
)
|
||||
|
||||
return dangerousMobileDataStates.contains(telephony.dataState)
|
||||
}
|
||||
|
||||
// A throttled variant of fetchPkgNameState()
|
||||
private val fetchPkgNameStateDebounced: () -> Unit =
|
||||
screenModelScope.debounce(100L, function = ::fetchPkgNameState)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.compose.foundation.rememberScrollState
|
|||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
|
|
@ -20,6 +21,7 @@ import cafe.adriel.voyager.navigator.currentOrThrow
|
|||
import com.aliucord.manager.R
|
||||
import com.aliucord.manager.ui.components.AnimatedVersionDisplay
|
||||
import com.aliucord.manager.ui.components.TextDivider
|
||||
import com.aliucord.manager.ui.components.dialogs.NetworkWarningDialog
|
||||
import com.aliucord.manager.ui.screens.patching.PatchingScreen
|
||||
import com.aliucord.manager.ui.screens.patchopts.components.PackageNameState
|
||||
import com.aliucord.manager.ui.screens.patchopts.components.PatchOptionsAppBar
|
||||
|
|
@ -54,6 +56,17 @@ class PatchOptionsScreen(
|
|||
context.requestNoBatteryOptimizations()
|
||||
}
|
||||
|
||||
var showNetworkWarningDialog by rememberSaveable { mutableStateOf(model.isNetworkDangerous()) }
|
||||
if (showNetworkWarningDialog) {
|
||||
NetworkWarningDialog(
|
||||
onConfirm = { showNetworkWarningDialog = false },
|
||||
onDismiss = {
|
||||
showNetworkWarningDialog = false
|
||||
navigator.pop()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = { PatchOptionsAppBar() },
|
||||
) { paddingValues ->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue