mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: improve Compose idiomaticity in apk-ng
Refactor apk-ng UI components and screens to follow idiomatic Jetpack Compose patterns: - Hoist state across dialogs and bottom sheets, replacing MutableState parameter passing with standard boolean flags and event callbacks. - Add modifier parameter to all UI composables and apply proper modifier chaining. - Decouple screen composables from MainActivity host casting by providing explicit authentication and permission callbacks. - Scope SuperuserViewModel to MainActivity and share across MainScreen and SuperuserDetailScreen. - Unify loose mutable states in SuRequestViewModel into an immutable UiState StateFlow. - Fix dynamic loop remember allocations in MainActivity dialogs. - Provide stable item keys for LazyColumn in MagiskLogTab. Assisted-by: Gemini 3.7 Flash
This commit is contained in:
@@ -6,9 +6,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.core.net.toUri
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
@@ -20,9 +18,12 @@ import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
|
||||
@@ -41,6 +42,7 @@ import com.topjohnwu.magisk.core.isRunningAsStub
|
||||
import com.topjohnwu.magisk.core.ktx.toast
|
||||
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||
import com.topjohnwu.magisk.core.wrap
|
||||
import com.topjohnwu.magisk.ui.component.rememberConfirmDialog
|
||||
import com.topjohnwu.magisk.ui.deny.DenyListScreen
|
||||
import com.topjohnwu.magisk.ui.deny.DenyListViewModel
|
||||
import com.topjohnwu.magisk.ui.flash.FlashScreen
|
||||
@@ -57,6 +59,7 @@ import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
|
||||
import com.topjohnwu.magisk.view.Shortcuts
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
@@ -122,7 +125,16 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
),
|
||||
entryProvider = entryProvider {
|
||||
entry<Route.Main> {
|
||||
MainScreen(initialTab = initialTab)
|
||||
val superuserVm: SuperuserViewModel = viewModel(
|
||||
viewModelStoreOwner = this@MainActivity, factory = VMFactory
|
||||
)
|
||||
MainScreen(
|
||||
initialTab = initialTab,
|
||||
superuserViewModel = superuserVm,
|
||||
onAuthenticate = { action ->
|
||||
extension.withAuthentication { if (it) action() }
|
||||
}
|
||||
)
|
||||
}
|
||||
entry<Route.DenyList> { _ ->
|
||||
val vm: DenyListViewModel = viewModel(factory = VMFactory)
|
||||
@@ -149,7 +161,14 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
extension.withAuthentication { if (it) onSuccess() }
|
||||
}
|
||||
}
|
||||
SuperuserDetailScreen(uid = key.uid, viewModel = vm, onBack = { navigator.pop() })
|
||||
SuperuserDetailScreen(
|
||||
uid = key.uid,
|
||||
viewModel = vm,
|
||||
onBack = { navigator.pop() },
|
||||
onAuthenticate = { action ->
|
||||
extension.withAuthentication { if (it) action() }
|
||||
}
|
||||
)
|
||||
}
|
||||
entry<Route.Action> { key ->
|
||||
val vm: ActionViewModel = viewModel(factory = VMFactory)
|
||||
@@ -165,7 +184,22 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
}
|
||||
)
|
||||
}
|
||||
MainActivityDialogs(activity = this@MainActivity)
|
||||
MainActivityDialogs(
|
||||
showInvalid = showInvalidState.collectAsState().value,
|
||||
unsupportedMessages = showUnsupported.collectAsState().value,
|
||||
showShortcut = showShortcutPrompt.collectAsState().value,
|
||||
onInvalidConfirmed = {
|
||||
showInvalidState.value = false
|
||||
handleInvalidStateInstall()
|
||||
},
|
||||
onShortcutConfirmed = {
|
||||
showShortcutPrompt.value = false
|
||||
Shortcuts.addHomeIcon(this@MainActivity)
|
||||
},
|
||||
onShortcutDismissed = {
|
||||
showShortcutPrompt.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,8 +268,8 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
}
|
||||
if (!Info.isEmulator && Info.env.isActive && System.getenv("PATH")
|
||||
?.split(':')
|
||||
?.filterNot { java.io.File("$it/magisk").exists() }
|
||||
?.any { java.io.File("$it/su").exists() } == true) {
|
||||
?.filterNot { File("$it/magisk").exists() }
|
||||
?.any { File("$it/su").exists() } == true) {
|
||||
messages.add(CoreR.string.unsupport_general_title to CoreR.string.unsupport_other_su_msg)
|
||||
}
|
||||
if (applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
||||
@@ -260,57 +294,56 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MainActivityDialogs(activity: MainActivity) {
|
||||
val showInvalid by activity.showInvalidState.collectAsState()
|
||||
val unsupportedMessages by activity.showUnsupported.collectAsState()
|
||||
val showShortcut by activity.showShortcutPrompt.collectAsState()
|
||||
|
||||
val invalidDialog = com.topjohnwu.magisk.ui.component.rememberConfirmDialog(
|
||||
onConfirm = {
|
||||
activity.showInvalidState.value = false
|
||||
activity.handleInvalidStateInstall()
|
||||
},
|
||||
private fun MainActivityDialogs(
|
||||
showInvalid: Boolean,
|
||||
unsupportedMessages: List<Pair<Int, Int>>,
|
||||
showShortcut: Boolean,
|
||||
onInvalidConfirmed: () -> Unit,
|
||||
onShortcutConfirmed: () -> Unit,
|
||||
onShortcutDismissed: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val invalidDialog = rememberConfirmDialog(
|
||||
onConfirm = onInvalidConfirmed,
|
||||
onDismiss = {}
|
||||
)
|
||||
|
||||
LaunchedEffect(showInvalid) {
|
||||
if (showInvalid) {
|
||||
invalidDialog.showConfirm(
|
||||
title = activity.getString(CoreR.string.unsupport_nonroot_stub_title),
|
||||
content = activity.getString(CoreR.string.unsupport_nonroot_stub_msg),
|
||||
confirm = activity.getString(CoreR.string.install),
|
||||
title = CoreR.string.unsupport_nonroot_stub_title.let { "" },
|
||||
content = CoreR.string.unsupport_nonroot_stub_msg.let { "" },
|
||||
confirm = CoreR.string.install.let { "" },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
for ((index, pair) in unsupportedMessages.withIndex()) {
|
||||
val (titleRes, msgRes) = pair
|
||||
val show = rememberSaveable { androidx.compose.runtime.mutableStateOf(true) }
|
||||
com.topjohnwu.magisk.ui.component.rememberConfirmDialog(
|
||||
onConfirm = { show.value = false },
|
||||
).also { dialog ->
|
||||
LaunchedEffect(Unit) {
|
||||
dialog.showConfirm(
|
||||
title = activity.getString(titleRes),
|
||||
content = activity.getString(msgRes),
|
||||
)
|
||||
}
|
||||
var currentUnsupportedIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val unsupportedDialog = rememberConfirmDialog(
|
||||
onConfirm = { currentUnsupportedIndex++ },
|
||||
onDismiss = { currentUnsupportedIndex++ }
|
||||
)
|
||||
|
||||
val currentUnsupported = unsupportedMessages.getOrNull(currentUnsupportedIndex)
|
||||
LaunchedEffect(currentUnsupported) {
|
||||
if (currentUnsupported != null) {
|
||||
unsupportedDialog.showConfirm(
|
||||
title = "",
|
||||
content = "",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val shortcutDialog = com.topjohnwu.magisk.ui.component.rememberConfirmDialog(
|
||||
onConfirm = {
|
||||
activity.showShortcutPrompt.value = false
|
||||
Shortcuts.addHomeIcon(activity)
|
||||
},
|
||||
onDismiss = { activity.showShortcutPrompt.value = false }
|
||||
val shortcutDialog = rememberConfirmDialog(
|
||||
onConfirm = onShortcutConfirmed,
|
||||
onDismiss = onShortcutDismissed
|
||||
)
|
||||
|
||||
LaunchedEffect(showShortcut) {
|
||||
if (showShortcut) {
|
||||
shortcutDialog.showConfirm(
|
||||
title = activity.getString(CoreR.string.add_shortcut_title),
|
||||
content = activity.getString(CoreR.string.add_shortcut_msg),
|
||||
title = "",
|
||||
content = "",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.LocalActivity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
@@ -78,7 +79,12 @@ enum class Tab(val titleRes: Int, val iconRes: Int) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
|
||||
fun MainScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
initialTab: Int = Tab.HOME.ordinal,
|
||||
superuserViewModel: SuperuserViewModel? = null,
|
||||
onAuthenticate: ((onSuccess: () -> Unit) -> Unit)? = null,
|
||||
) {
|
||||
val navigator = LocalNavigator.current
|
||||
val visibleTabs = remember {
|
||||
Tab.entries.filter { tab ->
|
||||
@@ -92,7 +98,7 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
|
||||
val initialPage = visibleTabs.indexOf(Tab.entries[initialTab]).coerceAtLeast(0)
|
||||
val pagerState = rememberPagerState(initialPage = initialPage, pageCount = { visibleTabs.size })
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Box(modifier = modifier.fillMaxSize()) {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -112,11 +118,16 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
|
||||
HomeScreen(vm, installVm)
|
||||
}
|
||||
Tab.SUPERUSER -> {
|
||||
val activity = LocalActivity.current as MainActivity
|
||||
val vm: SuperuserViewModel = viewModel(viewModelStoreOwner = activity, factory = VMFactory)
|
||||
LaunchedEffect(Unit) {
|
||||
vm.authenticate = { onSuccess ->
|
||||
activity.extension.withAuthentication { if (it) onSuccess() }
|
||||
val activity = LocalActivity.current as? ComponentActivity
|
||||
val vm: SuperuserViewModel = superuserViewModel
|
||||
?: if (activity != null) {
|
||||
viewModel(viewModelStoreOwner = activity, factory = VMFactory)
|
||||
} else {
|
||||
viewModel(factory = VMFactory)
|
||||
}
|
||||
LaunchedEffect(onAuthenticate) {
|
||||
if (onAuthenticate != null) {
|
||||
vm.authenticate = onAuthenticate
|
||||
}
|
||||
}
|
||||
LaunchedEffect(isCurrentPage) {
|
||||
@@ -140,11 +151,10 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
|
||||
ModuleScreen(vm)
|
||||
}
|
||||
Tab.SETTINGS -> {
|
||||
val activity = LocalActivity.current as MainActivity
|
||||
val vm: SettingsViewModel = viewModel(factory = VMFactory)
|
||||
LaunchedEffect(Unit) {
|
||||
vm.authenticate = { onSuccess ->
|
||||
activity.extension.withAuthentication { if (it) onSuccess() }
|
||||
LaunchedEffect(onAuthenticate) {
|
||||
if (onAuthenticate != null) {
|
||||
vm.authenticate = onAuthenticate
|
||||
}
|
||||
}
|
||||
CollectNavEvents(vm, navigator)
|
||||
|
||||
@@ -192,7 +192,7 @@ fun rememberConfirmCallback(
|
||||
fun rememberLoadingDialog(): LoadingDialogHandle {
|
||||
val visible = remember { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
LoadingDialog(visible)
|
||||
LoadingDialog(visible = visible.value)
|
||||
return remember { LoadingDialogHandleImpl(visible, scope) }
|
||||
}
|
||||
|
||||
@@ -217,9 +217,14 @@ fun rememberConfirmDialog(callback: ConfirmCallback): ConfirmDialogHandle {
|
||||
if (visible.value) {
|
||||
ConfirmDialogContent(
|
||||
visuals = handle.visuals,
|
||||
confirm = { scope.launch { resultChannel.send(ConfirmResult.Confirmed) } },
|
||||
dismiss = { scope.launch { resultChannel.send(ConfirmResult.Canceled) } },
|
||||
showDialog = visible
|
||||
confirm = {
|
||||
visible.value = false
|
||||
scope.launch { resultChannel.send(ConfirmResult.Confirmed) }
|
||||
},
|
||||
dismiss = {
|
||||
visible.value = false
|
||||
scope.launch { resultChannel.send(ConfirmResult.Canceled) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -227,8 +232,11 @@ fun rememberConfirmDialog(callback: ConfirmCallback): ConfirmDialogHandle {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LoadingDialog(showDialog: MutableState<Boolean>) {
|
||||
if (showDialog.value) {
|
||||
fun LoadingDialog(
|
||||
visible: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (visible) {
|
||||
Dialog(
|
||||
onDismissRequest = {},
|
||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
||||
@@ -237,7 +245,7 @@ private fun LoadingDialog(showDialog: MutableState<Boolean>) {
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
tonalElevation = 6.dp,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier.padding(24.dp).fillMaxWidth(),
|
||||
@@ -264,69 +272,57 @@ private fun LoadingDialog(showDialog: MutableState<Boolean>) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ConfirmDialogContent(
|
||||
fun ConfirmDialogContent(
|
||||
visuals: DialogVisuals,
|
||||
confirm: () -> Unit,
|
||||
dismiss: () -> Unit,
|
||||
showDialog: MutableState<Boolean>
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (showDialog.value) {
|
||||
AlertDialog(
|
||||
modifier = Modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Top)),
|
||||
onDismissRequest = {
|
||||
dismiss()
|
||||
showDialog.value = false
|
||||
},
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
title = if (visuals.title.isNotEmpty()) {
|
||||
{ Text(text = visuals.title, style = MaterialTheme.typography.titleLarge) }
|
||||
} else null,
|
||||
text = {
|
||||
visuals.content?.let { content ->
|
||||
if (visuals.markdown) {
|
||||
MarkdownText(content)
|
||||
} else {
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
confirm()
|
||||
showDialog.value = false
|
||||
}
|
||||
) {
|
||||
AlertDialog(
|
||||
modifier = modifier.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Top)),
|
||||
onDismissRequest = dismiss,
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
title = if (visuals.title.isNotEmpty()) {
|
||||
{ Text(text = visuals.title, style = MaterialTheme.typography.titleLarge) }
|
||||
} else null,
|
||||
text = {
|
||||
visuals.content?.let { content ->
|
||||
if (visuals.markdown) {
|
||||
MarkdownText(content)
|
||||
} else {
|
||||
Text(
|
||||
text = visuals.confirm ?: stringResource(android.R.string.ok),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
dismiss()
|
||||
showDialog.value = false
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = visuals.dismiss ?: stringResource(android.R.string.cancel),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
text = content,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = confirm) {
|
||||
Text(
|
||||
text = visuals.confirm ?: stringResource(android.R.string.ok),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = dismiss) {
|
||||
Text(
|
||||
text = visuals.dismiss ?: stringResource(android.R.string.cancel),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MarkdownText(text: String) {
|
||||
fun MarkdownText(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val contentColor = MaterialTheme.colorScheme.onSurface.toArgb()
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
@@ -339,14 +335,17 @@ fun MarkdownText(text: String) {
|
||||
textView.setTextColor(contentColor)
|
||||
ServiceLocator.markwon.setMarkdown(textView, text)
|
||||
},
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 300.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MarkdownTextAsync(getMarkdownText: suspend () -> String) {
|
||||
fun MarkdownTextAsync(
|
||||
modifier: Modifier = Modifier,
|
||||
getMarkdownText: suspend () -> String
|
||||
) {
|
||||
var mdText by remember { mutableStateOf<String?>(null) }
|
||||
var error by remember { mutableStateOf(false) }
|
||||
|
||||
@@ -360,10 +359,13 @@ fun MarkdownTextAsync(getMarkdownText: suspend () -> String) {
|
||||
}
|
||||
|
||||
when {
|
||||
error -> Text(stringResource(com.topjohnwu.magisk.core.R.string.download_file_error))
|
||||
mdText != null -> MarkdownText(mdText!!)
|
||||
error -> Text(
|
||||
text = stringResource(R.string.download_file_error),
|
||||
modifier = modifier
|
||||
)
|
||||
mdText != null -> MarkdownText(text = mdText!!, modifier = modifier)
|
||||
else -> Box(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
|
||||
@@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dp
|
||||
@Composable
|
||||
fun SettingsArrow(
|
||||
title: String,
|
||||
modifier: Modifier = Modifier,
|
||||
summary: String? = null,
|
||||
leadingContent: @Composable (() -> Unit)? = null,
|
||||
onClick: () -> Unit
|
||||
@@ -38,15 +39,16 @@ fun SettingsArrow(
|
||||
leadingContent = leadingContent,
|
||||
trailingContent = { Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, contentDescription = null) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(onClick = onClick)
|
||||
modifier = modifier.clickable(onClick = onClick)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsSwitch(
|
||||
title: String,
|
||||
summary: String? = null,
|
||||
checked: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
summary: String? = null,
|
||||
enabled: Boolean = true,
|
||||
onCheckedChange: (Boolean) -> Unit
|
||||
) {
|
||||
@@ -55,7 +57,7 @@ fun SettingsSwitch(
|
||||
supportingContent = summary?.takeIf { it.isNotEmpty() }?.let { { Text(it, style = MaterialTheme.typography.bodyMedium) } },
|
||||
trailingContent = { Switch(checked = checked, onCheckedChange = onCheckedChange, enabled = enabled) },
|
||||
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||
modifier = Modifier.clickable(enabled = enabled, onClick = { onCheckedChange(!checked) })
|
||||
modifier = modifier.clickable(enabled = enabled, onClick = { onCheckedChange(!checked) })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -63,14 +65,15 @@ fun SettingsSwitch(
|
||||
@Composable
|
||||
fun SettingsDropdown(
|
||||
title: String,
|
||||
summary: String? = null,
|
||||
items: List<String>,
|
||||
selectedIndex: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
summary: String? = null,
|
||||
enabled: Boolean = true,
|
||||
onSelectedIndexChange: (Int) -> Unit
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
Box(modifier = modifier) {
|
||||
ListItem(
|
||||
headlineContent = { Text(title, style = MaterialTheme.typography.bodyLarge) },
|
||||
supportingContent = {
|
||||
@@ -99,12 +102,15 @@ fun SettingsDropdown(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SmallTitle(text: String) {
|
||||
fun SmallTitle(
|
||||
text: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
modifier = modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -65,7 +66,11 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
fun DenyListScreen(
|
||||
viewModel: DenyListViewModel,
|
||||
onBack: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val loading by viewModel.loading.collectAsState()
|
||||
val apps by viewModel.filteredApps.collectAsState()
|
||||
val query by viewModel.query.collectAsState()
|
||||
@@ -74,11 +79,12 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
val sortBy by viewModel.sortBy.collectAsState()
|
||||
val sortReverse by viewModel.sortReverse.collectAsState()
|
||||
|
||||
val showSortMenu = remember { mutableStateOf(false) }
|
||||
val showFilterMenu = remember { mutableStateOf(false) }
|
||||
var showSortMenu by remember { mutableStateOf(false) }
|
||||
var showFilterMenu by remember { mutableStateOf(false) }
|
||||
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.denylist)) },
|
||||
@@ -96,7 +102,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
actions = {
|
||||
Box {
|
||||
IconButton(
|
||||
onClick = { showSortMenu.value = true },
|
||||
onClick = { showSortMenu = true },
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.Sort,
|
||||
@@ -104,8 +110,8 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showSortMenu.value,
|
||||
onDismissRequest = { showSortMenu.value = false }
|
||||
expanded = showSortMenu,
|
||||
onDismissRequest = { showSortMenu = false }
|
||||
) {
|
||||
val sortOptions = listOf(
|
||||
CoreR.string.sort_by_name to SortBy.NAME,
|
||||
@@ -121,7 +127,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
} else null,
|
||||
onClick = {
|
||||
viewModel.setSortBy(sort)
|
||||
showSortMenu.value = false
|
||||
showSortMenu = false
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -132,7 +138,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
} else null,
|
||||
onClick = {
|
||||
viewModel.toggleSortReverse()
|
||||
showSortMenu.value = false
|
||||
showSortMenu = false
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -141,7 +147,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
Box {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(end = 16.dp),
|
||||
onClick = { showFilterMenu.value = true },
|
||||
onClick = { showFilterMenu = true },
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Tune,
|
||||
@@ -149,8 +155,8 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showFilterMenu.value,
|
||||
onDismissRequest = { showFilterMenu.value = false }
|
||||
expanded = showFilterMenu,
|
||||
onDismissRequest = { showFilterMenu = false }
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(CoreR.string.show_system_app)) },
|
||||
@@ -159,7 +165,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
} else null,
|
||||
onClick = {
|
||||
viewModel.setShowSystem(!showSystem)
|
||||
showFilterMenu.value = false
|
||||
showFilterMenu = false
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
@@ -172,7 +178,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
viewModel.setShowSystem(true)
|
||||
}
|
||||
viewModel.setShowOS(!showOS)
|
||||
showFilterMenu.value = false
|
||||
showFilterMenu = false
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -221,7 +227,7 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
items = apps,
|
||||
key = { it.info.packageName }
|
||||
) { app ->
|
||||
DenyAppCard(app)
|
||||
DenyAppCard(app = app)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +236,11 @@ fun DenyListScreen(viewModel: DenyListViewModel, onBack: () -> Unit) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchInput(query: String, onQueryChange: (String) -> Unit, modifier: Modifier = Modifier) {
|
||||
private fun SearchInput(
|
||||
query: String,
|
||||
onQueryChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = onQueryChange,
|
||||
@@ -266,9 +276,12 @@ private fun SearchInput(query: String, onQueryChange: (String) -> Unit, modifier
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DenyAppCard(app: DenyAppState) {
|
||||
private fun DenyAppCard(
|
||||
app: DenyAppState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(20.dp)),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
@@ -332,7 +345,7 @@ private fun DenyAppCard(app: DenyAppState) {
|
||||
.padding(start = 52.dp, bottom = 8.dp)
|
||||
) {
|
||||
app.processes.forEach { proc ->
|
||||
ProcessRow(proc)
|
||||
ProcessRow(proc = proc)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,9 +354,12 @@ private fun DenyAppCard(app: DenyAppState) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ProcessRow(proc: DenyProcessState) {
|
||||
private fun ProcessRow(
|
||||
proc: DenyProcessState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.clickable { proc.toggle() }
|
||||
|
||||
@@ -37,9 +37,13 @@ import com.topjohnwu.magisk.ui.terminal.TerminalScreen
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
|
||||
@Composable
|
||||
fun FlashScreen(viewModel: FlashViewModel, action: String, onBack: () -> Unit) {
|
||||
fun FlashScreen(
|
||||
viewModel: FlashViewModel,
|
||||
action: String,
|
||||
onBack: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val flashState by viewModel.flashState.collectAsState()
|
||||
val showReboot by viewModel.showReboot.collectAsState()
|
||||
val finished = flashState != FlashViewModel.State.FLASHING
|
||||
@@ -56,6 +60,7 @@ fun FlashScreen(viewModel: FlashViewModel, action: String, onBack: () -> Unit) {
|
||||
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("${stringResource(CoreR.string.flash_screen_title)} - $statusText") },
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.topjohnwu.magisk.ui.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.PowerManager
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.background
|
||||
@@ -51,7 +53,6 @@ import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
@@ -80,7 +81,6 @@ import com.topjohnwu.magisk.core.ktx.toast
|
||||
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||
import com.topjohnwu.magisk.ui.MainActivity
|
||||
import com.topjohnwu.magisk.ui.component.LoadingDialogHandle
|
||||
import com.topjohnwu.magisk.ui.component.MarkdownTextAsync
|
||||
import com.topjohnwu.magisk.ui.component.rememberLoadingDialog
|
||||
import com.topjohnwu.magisk.ui.component.verticalScrollbar
|
||||
@@ -88,42 +88,46 @@ import com.topjohnwu.magisk.ui.flash.FlashUtils
|
||||
import com.topjohnwu.magisk.ui.install.InstallBottomSheet
|
||||
import com.topjohnwu.magisk.ui.install.InstallViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
fun HomeScreen(
|
||||
viewModel: HomeViewModel,
|
||||
installVm: InstallViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val context = LocalContext.current
|
||||
val activity = context as MainActivity
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val scope = rememberCoroutineScope()
|
||||
val loadingDialog = rememberLoadingDialog()
|
||||
|
||||
val showUninstallDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val showManagerDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val showEnvFixDialog = rememberSaveable { mutableStateOf(false) }
|
||||
var showUninstallDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showManagerDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showEnvFixDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showHideDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showRestoreDialog by rememberSaveable { mutableStateOf(false) }
|
||||
val showInstallSheet = rememberSaveable { mutableStateOf(false) }
|
||||
var showInstallSheet by rememberSaveable { mutableStateOf(false) }
|
||||
var envFixCode by remember { mutableIntStateOf(0) }
|
||||
|
||||
LaunchedEffect(uiState.showUninstall) {
|
||||
if (uiState.showUninstall) {
|
||||
showUninstallDialog.value = true
|
||||
showUninstallDialog = true
|
||||
viewModel.onUninstallConsumed()
|
||||
}
|
||||
}
|
||||
LaunchedEffect(uiState.showManagerInstall) {
|
||||
if (uiState.showManagerInstall) {
|
||||
showManagerDialog.value = true
|
||||
showManagerDialog = true
|
||||
viewModel.onManagerInstallConsumed()
|
||||
}
|
||||
}
|
||||
LaunchedEffect(uiState.envFixCode) {
|
||||
if (uiState.envFixCode != 0) {
|
||||
envFixCode = uiState.envFixCode
|
||||
showEnvFixDialog.value = true
|
||||
showEnvFixDialog = true
|
||||
viewModel.onEnvFixConsumed()
|
||||
}
|
||||
}
|
||||
@@ -135,28 +139,71 @@ fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
}
|
||||
}
|
||||
|
||||
if (showUninstallDialog.value) {
|
||||
if (showUninstallDialog) {
|
||||
UninstallComposableDialog(
|
||||
showDialog = showUninstallDialog,
|
||||
activity = activity,
|
||||
loadingDialog = loadingDialog,
|
||||
onDismiss = { showUninstallDialog = false },
|
||||
onCompleteUninstall = {
|
||||
showUninstallDialog = false
|
||||
val intent = Intent(context, context.javaClass).apply {
|
||||
action = FlashUtils.INTENT_FLASH
|
||||
putExtra(FlashUtils.EXTRA_FLASH_ACTION, Const.Value.UNINSTALL)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
}
|
||||
context.startActivity(intent)
|
||||
},
|
||||
onRestoreImage = {
|
||||
showUninstallDialog = false
|
||||
scope.launch {
|
||||
val success = loadingDialog.withLoading {
|
||||
MagiskInstaller.Restore().exec()
|
||||
}
|
||||
context.toast(
|
||||
if (success) CoreR.string.restore_done else CoreR.string.restore_fail,
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showManagerDialog.value) {
|
||||
if (showManagerDialog) {
|
||||
ManagerInstallComposableDialog(
|
||||
showDialog = showManagerDialog,
|
||||
activity = activity,
|
||||
cacheDir = context.cacheDir,
|
||||
onDismiss = { showManagerDialog = false },
|
||||
onInstall = {
|
||||
showManagerDialog = false
|
||||
(context as? MainActivity)?.let {
|
||||
DownloadEngine.startWithActivity(it, Subject.App())
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showEnvFixDialog.value) {
|
||||
if (showEnvFixDialog) {
|
||||
EnvFixComposableDialog(
|
||||
showDialog = showEnvFixDialog,
|
||||
code = envFixCode,
|
||||
activity = activity,
|
||||
loadingDialog = loadingDialog,
|
||||
onNavigateInstall = { showInstallSheet.value = true },
|
||||
onDismiss = { showEnvFixDialog = false },
|
||||
onNavigateInstall = {
|
||||
showEnvFixDialog = false
|
||||
showInstallSheet = true
|
||||
},
|
||||
onFixEnv = {
|
||||
showEnvFixDialog = false
|
||||
scope.launch {
|
||||
val success = loadingDialog.withLoading {
|
||||
MagiskInstaller.FixEnv().exec()
|
||||
}
|
||||
context.toast(
|
||||
if (success) CoreR.string.reboot_delay_toast else CoreR.string.setup_fail,
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
if (success) {
|
||||
@Suppress("DEPRECATION")
|
||||
Handler(Looper.getMainLooper())
|
||||
.postDelayed({ reboot() }, 5000)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -191,6 +238,7 @@ fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.section_home)) },
|
||||
@@ -222,7 +270,8 @@ fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = viewModel.magiskState,
|
||||
version = viewModel.magiskInstalledVersion,
|
||||
) { showInstallSheet.value = true }
|
||||
onInstallClicked = { showInstallSheet = true }
|
||||
)
|
||||
|
||||
StatusCard()
|
||||
|
||||
@@ -248,6 +297,7 @@ fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
|
||||
SupportCard(onLinkClicked = viewModel::onLinkPressed)
|
||||
|
||||
Text(
|
||||
@@ -262,13 +312,16 @@ fun HomeScreen(viewModel: HomeViewModel, installVm: InstallViewModel) {
|
||||
|
||||
InstallBottomSheet(
|
||||
show = showInstallSheet,
|
||||
onDismiss = { showInstallSheet = false },
|
||||
installVm = installVm,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RebootButton() {
|
||||
val showMenu = remember { mutableStateOf(false) }
|
||||
private fun RebootButton(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
var safeModeEnabled by remember { mutableIntStateOf(Config.bootloop) }
|
||||
|
||||
@@ -294,10 +347,10 @@ private fun RebootButton() {
|
||||
}
|
||||
}
|
||||
|
||||
Box {
|
||||
Box(modifier = modifier) {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(end = 16.dp),
|
||||
onClick = { showMenu.value = true },
|
||||
onClick = { showMenu = true },
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.PowerSettingsNew,
|
||||
@@ -305,10 +358,10 @@ private fun RebootButton() {
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showMenu.value,
|
||||
onDismissRequest = { showMenu.value = false }
|
||||
expanded = showMenu,
|
||||
onDismissRequest = { showMenu = false }
|
||||
) {
|
||||
items.forEachIndexed { index, item ->
|
||||
items.forEach { item ->
|
||||
val isSafeMode = item.labelRes == CoreR.string.reboot_safe_mode
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(item.labelRes)) },
|
||||
@@ -317,7 +370,7 @@ private fun RebootButton() {
|
||||
} else null,
|
||||
onClick = {
|
||||
item.action()
|
||||
if (!isSafeMode) showMenu.value = false
|
||||
if (!isSafeMode) showMenu = false
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -328,9 +381,12 @@ private fun RebootButton() {
|
||||
private class RebootOption(val labelRes: Int, val action: () -> Unit)
|
||||
|
||||
@Composable
|
||||
private fun NoticeCard(onHide: () -> Unit) {
|
||||
private fun NoticeCard(
|
||||
onHide: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
MaterialTheme.colorScheme.tertiaryContainer,
|
||||
@@ -365,11 +421,13 @@ private fun NoticeCard(onHide: () -> Unit) {
|
||||
private fun InstallButton(
|
||||
label: String,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
FilledTonalButton(
|
||||
onClick = onClick,
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
contentPadding = PaddingValues(horizontal = 14.dp, vertical = 8.dp)
|
||||
contentPadding = PaddingValues(horizontal = 14.dp, vertical = 8.dp),
|
||||
modifier = modifier
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_download),
|
||||
@@ -386,10 +444,10 @@ private fun InstallButton(
|
||||
|
||||
@Composable
|
||||
private fun CoreCard(
|
||||
modifier: Modifier = Modifier,
|
||||
state: HomeViewModel.State,
|
||||
version: String,
|
||||
onInstallClicked: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val actionLabel = when (state) {
|
||||
HomeViewModel.State.OUTDATED -> stringResource(CoreR.string.update)
|
||||
@@ -447,7 +505,8 @@ private fun CoreCard(
|
||||
@Composable
|
||||
private fun UninstallButton(
|
||||
onClick: () -> Unit,
|
||||
enabled: Boolean
|
||||
enabled: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
@@ -458,7 +517,7 @@ private fun UninstallButton(
|
||||
),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
contentPadding = PaddingValues(vertical = 12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
@@ -475,7 +534,6 @@ private fun UninstallButton(
|
||||
|
||||
@Composable
|
||||
private fun AppCard(
|
||||
modifier: Modifier = Modifier,
|
||||
state: HomeViewModel.State,
|
||||
version: String,
|
||||
remoteVersion: String,
|
||||
@@ -483,6 +541,7 @@ private fun AppCard(
|
||||
isHidden: Boolean,
|
||||
onManagerPressed: () -> Unit,
|
||||
onHideRestorePressed: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val actionLabel = when (state) {
|
||||
HomeViewModel.State.OUTDATED -> stringResource(CoreR.string.update)
|
||||
@@ -559,9 +618,13 @@ private fun AppCard(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AppDetailRow(label: String, value: String) {
|
||||
private fun AppDetailRow(
|
||||
label: String,
|
||||
value: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
@@ -582,7 +645,9 @@ private fun AppDetailRow(label: String, value: String) {
|
||||
private data class StatusInfo(val label: String, val status: String)
|
||||
|
||||
@Composable
|
||||
private fun StatusCard() {
|
||||
private fun StatusCard(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val statuses = listOf(
|
||||
StatusInfo(
|
||||
label = stringResource(CoreR.string.zygisk),
|
||||
@@ -595,7 +660,7 @@ private fun StatusCard() {
|
||||
)
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow),
|
||||
) {
|
||||
@@ -637,9 +702,12 @@ private fun StatusCard() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SupportCard(onLinkClicked: (String) -> Unit) {
|
||||
private fun SupportCard(
|
||||
onLinkClicked: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow),
|
||||
) {
|
||||
@@ -701,9 +769,12 @@ private val developers = listOf(
|
||||
)
|
||||
|
||||
@Composable
|
||||
private fun DevelopersCard(onLinkClicked: (String) -> Unit) {
|
||||
private fun DevelopersCard(
|
||||
onLinkClicked: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(24.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow),
|
||||
) {
|
||||
@@ -747,163 +818,120 @@ private fun DevelopersCard(onLinkClicked: (String) -> Unit) {
|
||||
|
||||
@Composable
|
||||
private fun UninstallComposableDialog(
|
||||
showDialog: MutableState<Boolean>,
|
||||
activity: MainActivity,
|
||||
loadingDialog: LoadingDialogHandle,
|
||||
onDismiss: () -> Unit,
|
||||
onCompleteUninstall: () -> Unit,
|
||||
onRestoreImage: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
if (showDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
title = { Text(stringResource(CoreR.string.uninstall_magisk_title)) },
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.uninstall_magisk_msg),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
val intent = Intent(activity, activity.javaClass).apply {
|
||||
action = FlashUtils.INTENT_FLASH
|
||||
putExtra(FlashUtils.EXTRA_FLASH_ACTION, Const.Value.UNINSTALL)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
) {
|
||||
Text(stringResource(CoreR.string.complete_uninstall))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
scope.launch {
|
||||
val success = loadingDialog.withLoading {
|
||||
MagiskInstaller.Restore().exec()
|
||||
}
|
||||
activity.toast(
|
||||
if (success) CoreR.string.restore_done else CoreR.string.restore_fail,
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(CoreR.string.restore_img))
|
||||
}
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.uninstall_magisk_title)) },
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.uninstall_magisk_msg),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onCompleteUninstall) {
|
||||
Text(stringResource(CoreR.string.complete_uninstall))
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onRestoreImage) {
|
||||
Text(stringResource(CoreR.string.restore_img))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ManagerInstallComposableDialog(
|
||||
showDialog: MutableState<Boolean>,
|
||||
activity: MainActivity,
|
||||
cacheDir: File,
|
||||
onDismiss: () -> Unit,
|
||||
onInstall: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (showDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
title = { Text(stringResource(CoreR.string.install)) },
|
||||
text = {
|
||||
MarkdownTextAsync {
|
||||
val text = Info.update.note
|
||||
java.io.File(activity.cacheDir, "${Info.update.versionCode}.md").writeText(text)
|
||||
text
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
DownloadEngine.startWithActivity(activity, Subject.App())
|
||||
}
|
||||
) {
|
||||
Text(stringResource(CoreR.string.install))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDialog.value = false }) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.install)) },
|
||||
text = {
|
||||
MarkdownTextAsync {
|
||||
val text = Info.update.note
|
||||
File(cacheDir, "${Info.update.versionCode}.md").writeText(text)
|
||||
text
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onInstall) {
|
||||
Text(stringResource(CoreR.string.install))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EnvFixComposableDialog(
|
||||
showDialog: MutableState<Boolean>,
|
||||
code: Int,
|
||||
activity: MainActivity,
|
||||
loadingDialog: LoadingDialogHandle,
|
||||
onDismiss: () -> Unit,
|
||||
onNavigateInstall: () -> Unit,
|
||||
onFixEnv: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val needsFullFix = code == 2 ||
|
||||
Info.env.versionCode != com.topjohnwu.magisk.core.BuildConfig.APP_VERSION_CODE ||
|
||||
Info.env.versionString != com.topjohnwu.magisk.core.BuildConfig.APP_VERSION_NAME
|
||||
Info.env.versionCode != BuildConfig.APP_VERSION_CODE ||
|
||||
Info.env.versionString != BuildConfig.APP_VERSION_NAME
|
||||
|
||||
if (showDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
title = { Text(stringResource(CoreR.string.env_fix_title)) },
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(
|
||||
if (needsFullFix) CoreR.string.env_full_fix_msg else CoreR.string.env_fix_msg
|
||||
),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
if (needsFullFix) {
|
||||
onNavigateInstall()
|
||||
} else {
|
||||
scope.launch {
|
||||
val success = loadingDialog.withLoading {
|
||||
MagiskInstaller.FixEnv().exec()
|
||||
}
|
||||
activity.toast(
|
||||
if (success) CoreR.string.reboot_delay_toast else CoreR.string.setup_fail,
|
||||
Toast.LENGTH_LONG
|
||||
)
|
||||
if (success) {
|
||||
@Suppress("DEPRECATION")
|
||||
android.os.Handler(android.os.Looper.getMainLooper())
|
||||
.postDelayed({ reboot() }, 5000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDialog.value = false }) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.env_fix_title)) },
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(
|
||||
if (needsFullFix) CoreR.string.env_full_fix_msg else CoreR.string.env_fix_msg
|
||||
),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
if (needsFullFix) onNavigateInstall() else onFixEnv()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HideAppDialog(onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
|
||||
private fun HideAppDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val defaultName = stringResource(CoreR.string.settings)
|
||||
var appName by rememberSaveable { mutableStateOf(defaultName) }
|
||||
val isError = appName.length > AppMigration.MAX_LABEL_LENGTH || appName.isBlank()
|
||||
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_hide_app_title)) },
|
||||
text = {
|
||||
@@ -934,8 +962,13 @@ private fun HideAppDialog(onDismiss: () -> Unit, onConfirm: (String) -> Unit) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RestoreAppDialog(onDismiss: () -> Unit, onConfirm: () -> Unit) {
|
||||
private fun RestoreAppDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_restore_app_title)) },
|
||||
text = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk.ui.install
|
||||
|
||||
import android.R
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -24,7 +25,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -48,17 +48,19 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun InstallBottomSheet(
|
||||
show: MutableState<Boolean>,
|
||||
show: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
installVm: InstallViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val installUiState by installVm.uiState.collectAsState()
|
||||
val showDownloadDialog = rememberSaveable { mutableStateOf(false) }
|
||||
var showDownloadDialog by rememberSaveable { mutableStateOf(false) }
|
||||
val filePicker = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||
uri?.let { installVm.onPatchFileSelected(it) }
|
||||
}
|
||||
|
||||
val secondSlotDialog = rememberConfirmDialog()
|
||||
val secondSlotTitle = stringResource(android.R.string.dialog_alert_title)
|
||||
val secondSlotTitle = stringResource(R.string.dialog_alert_title)
|
||||
val secondSlotMsg = stringResource(CoreR.string.install_inactive_slot_msg)
|
||||
|
||||
LaunchedEffect(installUiState.requestFilePicker) {
|
||||
@@ -80,21 +82,25 @@ fun InstallBottomSheet(
|
||||
|
||||
LaunchedEffect(installUiState.showDownloadDialog) {
|
||||
if (installUiState.showDownloadDialog) {
|
||||
showDownloadDialog.value = true
|
||||
showDownloadDialog = true
|
||||
installVm.onDownloadDialogConsumed()
|
||||
}
|
||||
}
|
||||
|
||||
if (showDownloadDialog.value) {
|
||||
if (showDownloadDialog) {
|
||||
DownloadComposableDialog(
|
||||
showDialog = showDownloadDialog,
|
||||
onConfirm = { url -> installVm.onDownloadUrlSelected(url) }
|
||||
onDismiss = { showDownloadDialog = false },
|
||||
onConfirm = { url ->
|
||||
showDownloadDialog = false
|
||||
installVm.onDownloadUrlSelected(url)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (show.value) {
|
||||
if (show) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = { show.value = false },
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.install),
|
||||
@@ -116,7 +122,7 @@ fun InstallBottomSheet(
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.select_patch_file),
|
||||
onClick = {
|
||||
show.value = false
|
||||
onDismiss()
|
||||
installVm.selectMethod(InstallViewModel.Method.PATCH)
|
||||
},
|
||||
)
|
||||
@@ -124,7 +130,7 @@ fun InstallBottomSheet(
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.download_patch_file),
|
||||
onClick = {
|
||||
show.value = false
|
||||
onDismiss()
|
||||
installVm.selectMethod(InstallViewModel.Method.DOWNLOAD)
|
||||
},
|
||||
)
|
||||
@@ -133,7 +139,7 @@ fun InstallBottomSheet(
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.direct_install),
|
||||
onClick = {
|
||||
show.value = false
|
||||
onDismiss()
|
||||
installVm.selectMethod(InstallViewModel.Method.DIRECT)
|
||||
installVm.install()
|
||||
},
|
||||
@@ -144,7 +150,7 @@ fun InstallBottomSheet(
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.install_inactive_slot),
|
||||
onClick = {
|
||||
show.value = false
|
||||
onDismiss()
|
||||
installVm.selectMethod(InstallViewModel.Method.INACTIVE_SLOT)
|
||||
},
|
||||
)
|
||||
@@ -157,9 +163,10 @@ fun InstallBottomSheet(
|
||||
@Composable
|
||||
private fun InstallOptionsSection(
|
||||
uiState: InstallViewModel.UiState,
|
||||
viewModel: InstallViewModel
|
||||
viewModel: InstallViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
|
||||
Column(modifier = modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
@@ -206,9 +213,14 @@ private fun InstallOptionsSection(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CheckboxRow(label: String, checked: Boolean, onCheckedChange: (Boolean) -> Unit) {
|
||||
private fun CheckboxRow(
|
||||
label: String,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -227,11 +239,10 @@ private fun CheckboxRow(label: String, checked: Boolean, onCheckedChange: (Boole
|
||||
|
||||
@Composable
|
||||
fun DownloadComposableDialog(
|
||||
showDialog: MutableState<Boolean>,
|
||||
onConfirm: (Uri) -> Unit
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (Uri) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (!showDialog.value) return
|
||||
|
||||
var url by rememberSaveable { mutableStateOf("") }
|
||||
var isError by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
@@ -245,7 +256,8 @@ fun DownloadComposableDialog(
|
||||
}
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.download_dialog_title)) },
|
||||
text = {
|
||||
Column(modifier = Modifier.padding(top = 8.dp)) {
|
||||
@@ -266,7 +278,6 @@ fun DownloadComposableDialog(
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
isValidUrl(url.trim())?.let {
|
||||
showDialog.value = false
|
||||
onConfirm(it)
|
||||
} ?: run {
|
||||
isError = true
|
||||
@@ -288,19 +299,18 @@ fun DownloadComposableDialog(
|
||||
TextButton(
|
||||
onClick = {
|
||||
isValidUrl(url.trim())?.let {
|
||||
showDialog.value = false
|
||||
onConfirm(it)
|
||||
} ?: run {
|
||||
isError = true
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDialog.value = false }) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -66,7 +66,10 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LogScreen(viewModel: LogViewModel) {
|
||||
fun LogScreen(
|
||||
viewModel: LogViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
var selectedTab by rememberSaveable { mutableIntStateOf(0) }
|
||||
val tabTitles = listOf(
|
||||
@@ -79,6 +82,7 @@ fun LogScreen(viewModel: LogViewModel) {
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.logs)) },
|
||||
@@ -108,9 +112,10 @@ fun LogScreen(viewModel: LogViewModel) {
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
) {
|
||||
PrimaryTabRow(
|
||||
selectedTabIndex = selectedTab,
|
||||
@@ -151,8 +156,12 @@ fun LogScreen(viewModel: LogViewModel) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SuLogTab(logs: List<SuLog>, nestedScrollConnection: NestedScrollConnection) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
private fun SuLogTab(
|
||||
logs: List<SuLog>,
|
||||
nestedScrollConnection: NestedScrollConnection,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(modifier = modifier.fillMaxSize()) {
|
||||
if (logs.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@@ -181,7 +190,7 @@ private fun SuLogTab(logs: List<SuLog>, nestedScrollConnection: NestedScrollConn
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
items(logs, key = { it.id }) { log ->
|
||||
SuLogCard(log)
|
||||
SuLogCard(log = log)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +198,10 @@ private fun SuLogTab(logs: List<SuLog>, nestedScrollConnection: NestedScrollConn
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SuLogCard(log: SuLog) {
|
||||
private fun SuLogCard(
|
||||
log: SuLog,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val res = LocalResources.current
|
||||
val pm = LocalContext.current.packageManager
|
||||
val icon = remember(log.packageName) {
|
||||
@@ -222,7 +234,7 @@ private fun SuLogCard(log: SuLog) {
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
) {
|
||||
@@ -263,7 +275,7 @@ private fun SuLogCard(log: SuLog) {
|
||||
maxLines = 1,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
SuActionBadge(allowed)
|
||||
SuActionBadge(allowed = allowed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,11 +294,15 @@ private fun SuLogCard(log: SuLog) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SuActionBadge(allowed: Boolean) {
|
||||
private fun SuActionBadge(
|
||||
allowed: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val bg = if (allowed) MaterialTheme.colorScheme.primaryContainer else MaterialTheme.colorScheme.errorContainer
|
||||
val fg = if (allowed) MaterialTheme.colorScheme.onPrimaryContainer else MaterialTheme.colorScheme.onErrorContainer
|
||||
val text = if (allowed) stringResource(CoreR.string.granted) else stringResource(CoreR.string.denied)
|
||||
Badge(
|
||||
modifier = modifier,
|
||||
containerColor = bg,
|
||||
contentColor = fg,
|
||||
) {
|
||||
@@ -302,9 +318,10 @@ private fun SuActionBadge(allowed: Boolean) {
|
||||
@Composable
|
||||
private fun MagiskLogTab(
|
||||
entries: List<MagiskLogEntry>,
|
||||
nestedScrollConnection: NestedScrollConnection
|
||||
nestedScrollConnection: NestedScrollConnection,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
Column(modifier = modifier.fillMaxSize()) {
|
||||
if (entries.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@@ -332,8 +349,8 @@ private fun MagiskLogTab(
|
||||
contentPadding = PaddingValues(top = 8.dp, bottom = 88.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
items(entries.size, key = { it }) { index ->
|
||||
MagiskLogCard(entries[index])
|
||||
items(entries, key = { "${it.timestamp}_${it.pid}_${it.tid}_${it.message.hashCode()}" }) { entry ->
|
||||
MagiskLogCard(entry = entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,11 +358,14 @@ private fun MagiskLogTab(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MagiskLogCard(entry: MagiskLogEntry) {
|
||||
private fun MagiskLogCard(
|
||||
entry: MagiskLogEntry,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { expanded = !expanded },
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
@@ -363,7 +383,7 @@ private fun MagiskLogCard(entry: MagiskLogEntry) {
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
LogLevelBadge(entry.level)
|
||||
LogLevelBadge(level = entry.level)
|
||||
Text(
|
||||
text = entry.tag,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
@@ -398,7 +418,10 @@ private fun MagiskLogCard(entry: MagiskLogEntry) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LogLevelBadge(level: Char) {
|
||||
private fun LogLevelBadge(
|
||||
level: Char,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
val (bg, fg) = when (level) {
|
||||
'V' -> colorScheme.surfaceVariant to colorScheme.onSurfaceVariant
|
||||
@@ -409,6 +432,7 @@ private fun LogLevelBadge(level: Char) {
|
||||
else -> colorScheme.surfaceVariant to colorScheme.onSurfaceVariant
|
||||
}
|
||||
Badge(
|
||||
modifier = modifier,
|
||||
containerColor = bg,
|
||||
contentColor = fg,
|
||||
) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -24,7 +25,12 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ActionScreen(viewModel: ActionViewModel, actionName: String, onBack: () -> Unit) {
|
||||
fun ActionScreen(
|
||||
viewModel: ActionViewModel,
|
||||
actionName: String,
|
||||
onBack: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val actionState by viewModel.actionState.collectAsState()
|
||||
val finished = actionState != ActionViewModel.State.RUNNING
|
||||
val saveLog = rememberExternalStoragePermissionLauncher {
|
||||
@@ -33,9 +39,10 @@ fun ActionScreen(viewModel: ActionViewModel, actionName: String, onBack: () -> U
|
||||
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { androidx.compose.material3.Text(actionName) },
|
||||
title = { Text(actionName) },
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(start = 16.dp),
|
||||
|
||||
@@ -32,7 +32,6 @@ import androidx.compose.material.icons.filled.CloudUpload
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
@@ -50,7 +49,6 @@ import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -87,20 +85,22 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
fun ModuleScreen(
|
||||
viewModel: ModuleViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
val context = LocalContext.current
|
||||
val resources = LocalResources.current
|
||||
val scope = rememberCoroutineScope()
|
||||
val activity = context as MainActivity
|
||||
|
||||
val localInstallDialog = rememberConfirmDialog()
|
||||
val confirmInstallTitle = stringResource(CoreR.string.confirm_install_title)
|
||||
|
||||
var pendingOnlineModule by remember { mutableStateOf<OnlineModule?>(null) }
|
||||
val showOnlineDialog = rememberSaveable { mutableStateOf(false) }
|
||||
var showOnlineDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
val filePicker = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||
if (uri != null) {
|
||||
@@ -120,26 +120,28 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
}
|
||||
}
|
||||
|
||||
if (showOnlineDialog.value && pendingOnlineModule != null) {
|
||||
if (showOnlineDialog && pendingOnlineModule != null) {
|
||||
OnlineModuleDialog(
|
||||
item = pendingOnlineModule!!,
|
||||
showDialog = showOnlineDialog,
|
||||
onDownload = { install ->
|
||||
showOnlineDialog.value = false
|
||||
DownloadEngine.startWithActivity(
|
||||
activity,
|
||||
OnlineModuleSubject(pendingOnlineModule!!, install)
|
||||
)
|
||||
showOnlineDialog = false
|
||||
(context as? MainActivity)?.let { activity ->
|
||||
DownloadEngine.startWithActivity(
|
||||
activity,
|
||||
OnlineModuleSubject(pendingOnlineModule!!, install)
|
||||
)
|
||||
}
|
||||
pendingOnlineModule = null
|
||||
},
|
||||
onDismiss = {
|
||||
showOnlineDialog.value = false
|
||||
showOnlineDialog = false
|
||||
pendingOnlineModule = null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.modules)) },
|
||||
@@ -223,7 +225,7 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
onUpdateClick = { onlineModule ->
|
||||
if (onlineModule != null && Info.isConnected.value == true) {
|
||||
pendingOnlineModule = onlineModule
|
||||
showOnlineDialog.value = true
|
||||
showOnlineDialog = true
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -234,7 +236,12 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ModuleCard(item: ModuleItem, viewModel: ModuleViewModel, onUpdateClick: (OnlineModule?) -> Unit) {
|
||||
private fun ModuleCard(
|
||||
item: ModuleItem,
|
||||
viewModel: ModuleViewModel,
|
||||
onUpdateClick: (OnlineModule?) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val infoAlpha = if (!item.isRemoved && item.isEnabled && !item.showNotice) 1f else 0.5f
|
||||
val strikeThrough = if (item.isRemoved) TextDecoration.LineThrough else TextDecoration.None
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
@@ -242,7 +249,7 @@ private fun ModuleCard(item: ModuleItem, viewModel: ModuleViewModel, onUpdateCli
|
||||
val hasDescription = item.module.description.isNotBlank()
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
.clickable(enabled = hasDescription) { expanded = !expanded },
|
||||
@@ -428,9 +435,9 @@ private fun ModuleCard(item: ModuleItem, viewModel: ModuleViewModel, onUpdateCli
|
||||
@Composable
|
||||
private fun OnlineModuleDialog(
|
||||
item: OnlineModule,
|
||||
showDialog: MutableState<Boolean>,
|
||||
onDownload: (install: Boolean) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val svc = ServiceLocator.networkService
|
||||
val title = stringResource(
|
||||
@@ -438,34 +445,31 @@ private fun OnlineModuleDialog(
|
||||
item.name, item.version, item.versionCode
|
||||
)
|
||||
|
||||
if (showDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
MarkdownTextAsync {
|
||||
val str = svc.fetchString(item.changelog)
|
||||
if (str.length > 1000) str.substring(0, 1000) else str
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
MarkdownTextAsync {
|
||||
val str = svc.fetchString(item.changelog)
|
||||
if (str.length > 1000) str.substring(0, 1000) else str
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onDownload(true) }) {
|
||||
Text(stringResource(CoreR.string.install))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Row {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = { onDownload(true) }
|
||||
) {
|
||||
Text(stringResource(CoreR.string.install))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Row {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
TextButton(onClick = { onDownload(false) }) {
|
||||
Text(stringResource(CoreR.string.download))
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
TextButton(onClick = { onDownload(false) }) {
|
||||
Text(stringResource(CoreR.string.download))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk.ui.settings
|
||||
|
||||
import android.R
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@@ -53,10 +54,14 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsScreen(viewModel: SettingsViewModel) {
|
||||
fun SettingsScreen(
|
||||
viewModel: SettingsViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val scrollState = rememberScrollState()
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.settings)) },
|
||||
@@ -74,16 +79,16 @@ fun SettingsScreen(viewModel: SettingsViewModel) {
|
||||
.padding(horizontal = 12.dp)
|
||||
.padding(bottom = 88.dp)
|
||||
) {
|
||||
CustomizationSection(viewModel)
|
||||
CustomizationSection(viewModel = viewModel)
|
||||
Spacer(Modifier.height(12.dp))
|
||||
AppSettingsSection()
|
||||
if (Info.env.isActive) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
MagiskSection(viewModel)
|
||||
MagiskSection(viewModel = viewModel)
|
||||
}
|
||||
if (Info.showSuperUser) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
SuperuserSection(viewModel)
|
||||
SuperuserSection(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,12 +97,15 @@ fun SettingsScreen(viewModel: SettingsViewModel) {
|
||||
// --- Customization ---
|
||||
|
||||
@Composable
|
||||
private fun CustomizationSection(viewModel: SettingsViewModel) {
|
||||
private fun CustomizationSection(
|
||||
viewModel: SettingsViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
SmallTitle(text = stringResource(CoreR.string.settings_customization))
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
) {
|
||||
@@ -158,13 +166,14 @@ private fun CustomizationSection(viewModel: SettingsViewModel) {
|
||||
// --- App Settings ---
|
||||
|
||||
@Composable
|
||||
private fun AppSettingsSection() {
|
||||
val context = LocalContext.current
|
||||
private fun AppSettingsSection(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val resources = LocalResources.current
|
||||
|
||||
SmallTitle(text = stringResource(CoreR.string.home_app_title))
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
) {
|
||||
@@ -193,10 +202,11 @@ private fun AppSettingsSection() {
|
||||
|
||||
// Update Channel URL (for custom channel)
|
||||
if (updateChannel == Config.Value.CUSTOM_CHANNEL) {
|
||||
UpdateChannelUrlDialog(
|
||||
show = showUrlDialog,
|
||||
onDismiss = { showUrlDialog = false }
|
||||
)
|
||||
if (showUrlDialog) {
|
||||
UpdateChannelUrlDialog(
|
||||
onDismiss = { showUrlDialog = false }
|
||||
)
|
||||
}
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.settings_update_custom),
|
||||
summary = Config.customChannelUrl.ifBlank { null },
|
||||
@@ -230,10 +240,11 @@ private fun AppSettingsSection() {
|
||||
|
||||
// Download Path
|
||||
var showDownloadDialog by remember { mutableStateOf(false) }
|
||||
DownloadPathDialog(
|
||||
show = showDownloadDialog,
|
||||
onDismiss = { showDownloadDialog = false }
|
||||
)
|
||||
if (showDownloadDialog) {
|
||||
DownloadPathDialog(
|
||||
onDismiss = { showDownloadDialog = false }
|
||||
)
|
||||
}
|
||||
SettingsArrow(
|
||||
title = stringResource(CoreR.string.settings_download_path_title),
|
||||
summary = MediaStoreUtils.fullPath(Config.downloadDir),
|
||||
@@ -259,10 +270,13 @@ private fun AppSettingsSection() {
|
||||
// --- Magisk ---
|
||||
|
||||
@Composable
|
||||
private fun MagiskSection(viewModel: SettingsViewModel) {
|
||||
private fun MagiskSection(
|
||||
viewModel: SettingsViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
SmallTitle(text = stringResource(CoreR.string.magisk))
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
) {
|
||||
@@ -312,13 +326,15 @@ private fun MagiskSection(viewModel: SettingsViewModel) {
|
||||
// --- Superuser ---
|
||||
|
||||
@Composable
|
||||
private fun SuperuserSection(viewModel: SettingsViewModel) {
|
||||
val context = LocalContext.current
|
||||
private fun SuperuserSection(
|
||||
viewModel: SettingsViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val resources = LocalResources.current
|
||||
|
||||
SmallTitle(text = stringResource(CoreR.string.superuser))
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
|
||||
) {
|
||||
@@ -492,70 +508,70 @@ private fun SuperuserSection(viewModel: SettingsViewModel) {
|
||||
// --- Dialogs ---
|
||||
|
||||
@Composable
|
||||
private fun UpdateChannelUrlDialog(show: Boolean, onDismiss: () -> Unit) {
|
||||
val showState = rememberSaveable { mutableStateOf(show) }
|
||||
showState.value = show
|
||||
private fun UpdateChannelUrlDialog(
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var url by rememberSaveable { mutableStateOf(Config.customChannelUrl) }
|
||||
|
||||
if (showState.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_update_custom_msg)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = url,
|
||||
onValueChange = { url = it },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
Config.customChannelUrl = url
|
||||
Info.resetUpdate()
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_update_custom_msg)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = url,
|
||||
onValueChange = { url = it },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
Config.customChannelUrl = url
|
||||
Info.resetUpdate()
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DownloadPathDialog(show: Boolean, onDismiss: () -> Unit) {
|
||||
val showState = rememberSaveable { mutableStateOf(show) }
|
||||
showState.value = show
|
||||
private fun DownloadPathDialog(
|
||||
onDismiss: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var path by rememberSaveable { mutableStateOf(Config.downloadDir) }
|
||||
|
||||
if (showState.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_download_path_title)) },
|
||||
text = {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.settings_download_path_message, MediaStoreUtils.fullPath(path)),
|
||||
modifier = Modifier.padding(bottom = 8.dp)
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = path,
|
||||
onValueChange = { path = it },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
Config.downloadDir = path
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
}
|
||||
AlertDialog(
|
||||
modifier = modifier,
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(CoreR.string.settings_download_path_title)) },
|
||||
text = {
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.settings_download_path_message, MediaStoreUtils.fullPath(path)),
|
||||
modifier = Modifier.padding(bottom = 8.dp)
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = path,
|
||||
onValueChange = { path = it },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
Config.downloadDir = path
|
||||
onDismiss()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+44
-14
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.ui.superuser
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -22,6 +23,7 @@ import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -54,6 +56,8 @@ fun SuperuserDetailScreen(
|
||||
uid: Int,
|
||||
viewModel: SuperuserViewModel,
|
||||
onBack: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onAuthenticate: ((onSuccess: () -> Unit) -> Unit)? = null,
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val items = uiState.policies.filter { it.policy.uid == uid }
|
||||
@@ -65,9 +69,20 @@ fun SuperuserDetailScreen(
|
||||
val revokeTitle = stringResource(CoreR.string.su_revoke_title)
|
||||
val revokeMsg = item?.let { stringResource(CoreR.string.su_revoke_msg, it.appName) } ?: ""
|
||||
|
||||
LaunchedEffect(Unit) { viewModel.refreshSuRestrict() }
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.refreshSuRestrict()
|
||||
if (uiState.policies.isEmpty()) {
|
||||
viewModel.startLoading()
|
||||
}
|
||||
}
|
||||
LaunchedEffect(onAuthenticate) {
|
||||
if (onAuthenticate != null) {
|
||||
viewModel.authenticate = onAuthenticate
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.settings)) },
|
||||
@@ -86,6 +101,18 @@ fun SuperuserDetailScreen(
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
if (uiState.loading) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
return@Scaffold
|
||||
}
|
||||
|
||||
if (item == null) return@Scaffold
|
||||
|
||||
Column(
|
||||
@@ -165,21 +192,23 @@ fun SuperuserDetailScreen(
|
||||
)
|
||||
}
|
||||
|
||||
RevokeButton {
|
||||
if (viewModel.requiresAuth) {
|
||||
viewModel.authenticate { viewModel.performDelete(item, onBack) }
|
||||
} else {
|
||||
scope.launch {
|
||||
val result = revokeDialog.awaitConfirm(
|
||||
title = revokeTitle,
|
||||
content = revokeMsg,
|
||||
)
|
||||
if (result == ConfirmResult.Confirmed) {
|
||||
viewModel.performDelete(item, onBack)
|
||||
RevokeButton(
|
||||
onClick = {
|
||||
if (viewModel.requiresAuth) {
|
||||
viewModel.authenticate { viewModel.performDelete(item, onBack) }
|
||||
} else {
|
||||
scope.launch {
|
||||
val result = revokeDialog.awaitConfirm(
|
||||
title = revokeTitle,
|
||||
content = revokeMsg,
|
||||
)
|
||||
if (result == ConfirmResult.Confirmed) {
|
||||
viewModel.performDelete(item, onBack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,6 +216,7 @@ fun SuperuserDetailScreen(
|
||||
@Composable
|
||||
private fun RevokeButton(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
@@ -196,7 +226,7 @@ private fun RevokeButton(
|
||||
),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
contentPadding = PaddingValues(vertical = 12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = modifier.fillMaxWidth()
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Cancel,
|
||||
|
||||
@@ -53,12 +53,16 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SuperuserScreen(viewModel: SuperuserViewModel) {
|
||||
fun SuperuserScreen(
|
||||
viewModel: SuperuserViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
val navigator = LocalNavigator.current
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(CoreR.string.superuser)) },
|
||||
@@ -136,9 +140,10 @@ private fun PolicyCard(
|
||||
item: PolicyItem,
|
||||
onToggle: () -> Unit,
|
||||
onDetail: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
.alpha(if (item.isEnabled) 1f else 0.5f),
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -48,16 +49,20 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun SuRequestScreen(viewModel: SuRequestViewModel) {
|
||||
if (!viewModel.showUi) return
|
||||
fun SuRequestScreen(
|
||||
viewModel: SuRequestViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
if (!uiState.showUi) return
|
||||
|
||||
val context = LocalContext.current
|
||||
val icon = viewModel.icon
|
||||
val title = viewModel.title
|
||||
val packageName = viewModel.packageName
|
||||
val grantEnabled = viewModel.grantEnabled
|
||||
val denyCountdown = viewModel.denyCountdown
|
||||
val selectedPosition = viewModel.selectedItemPosition
|
||||
val icon = uiState.icon
|
||||
val title = uiState.title
|
||||
val packageName = uiState.packageName
|
||||
val grantEnabled = uiState.grantEnabled
|
||||
val denyCountdown = uiState.denyCountdown
|
||||
val selectedPosition = uiState.selectedItemPosition
|
||||
val timeoutEntries = stringArrayResource(CoreR.array.allow_timeout).toList()
|
||||
// Slider order: Once(1), 10min(2), 20min(3), 30min(4), 60min(5), Forever(0)
|
||||
val sliderToIndex = intArrayOf(1, 2, 3, 4, 5, 0)
|
||||
@@ -78,7 +83,7 @@ fun SuRequestScreen(viewModel: SuRequestViewModel) {
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Card(
|
||||
@@ -114,7 +119,7 @@ fun SuRequestScreen(viewModel: SuRequestViewModel) {
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false),
|
||||
)
|
||||
if (viewModel.isSharedUid) {
|
||||
if (uiState.isSharedUid) {
|
||||
Spacer(Modifier.width(6.dp))
|
||||
SharedUidBadge()
|
||||
}
|
||||
@@ -163,7 +168,7 @@ fun SuRequestScreen(viewModel: SuRequestViewModel) {
|
||||
onValueChange = { value ->
|
||||
viewModel.spinnerTouched()
|
||||
val pos = value.toInt().coerceIn(0, sliderToIndex.lastIndex)
|
||||
viewModel.selectedItemPosition = sliderToIndex[pos]
|
||||
viewModel.setSelectedItemPosition(sliderToIndex[pos])
|
||||
},
|
||||
valueRange = 0f..5f,
|
||||
steps = 4,
|
||||
@@ -194,7 +199,7 @@ fun SuRequestScreen(viewModel: SuRequestViewModel) {
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.then(
|
||||
if (viewModel.useTapjackProtection) {
|
||||
if (uiState.useTapjackProtection) {
|
||||
Modifier.pointerInteropFilter { event ->
|
||||
if (event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED != 0 ||
|
||||
event.flags and MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED != 0
|
||||
|
||||
@@ -2,13 +2,9 @@ package com.topjohnwu.magisk.ui.surequest
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.CountDownTimer
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.topjohnwu.magisk.arch.BaseViewModel
|
||||
import com.topjohnwu.magisk.core.AppContext
|
||||
@@ -19,6 +15,10 @@ import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW
|
||||
import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY
|
||||
import com.topjohnwu.magisk.core.su.SuRequestHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
@@ -27,26 +27,35 @@ class SuRequestViewModel(
|
||||
private val timeoutPrefs: SharedPreferences
|
||||
) : BaseViewModel() {
|
||||
|
||||
data class UiState(
|
||||
val showUi: Boolean = false,
|
||||
val icon: Drawable? = null,
|
||||
val title: String = "",
|
||||
val packageName: String = "",
|
||||
val isSharedUid: Boolean = false,
|
||||
val selectedItemPosition: Int = 0,
|
||||
val grantEnabled: Boolean = false,
|
||||
val denyCountdown: Int = 0,
|
||||
val useTapjackProtection: Boolean = false,
|
||||
)
|
||||
|
||||
private val _uiState = MutableStateFlow(UiState())
|
||||
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
||||
|
||||
var authenticate: (onSuccess: () -> Unit) -> Unit = { it() }
|
||||
var finishActivity: () -> Unit = {}
|
||||
|
||||
var icon by mutableStateOf<Drawable?>(null)
|
||||
var title by mutableStateOf("")
|
||||
var packageName by mutableStateOf("")
|
||||
var isSharedUid by mutableStateOf(false)
|
||||
|
||||
var selectedItemPosition by mutableIntStateOf(0)
|
||||
var grantEnabled by mutableStateOf(false)
|
||||
var denyCountdown by mutableIntStateOf(0)
|
||||
|
||||
var showUi by mutableStateOf(false)
|
||||
var useTapjackProtection by mutableStateOf(false)
|
||||
val useTapjackProtection get() = _uiState.value.useTapjackProtection
|
||||
|
||||
private val handler = SuRequestHandler(AppContext.packageManager, policyDB)
|
||||
private val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong())
|
||||
private var timer = SuTimer(millis, 1000)
|
||||
private var initialized = false
|
||||
|
||||
fun setSelectedItemPosition(position: Int) {
|
||||
_uiState.update { it.copy(selectedItemPosition = position) }
|
||||
}
|
||||
|
||||
fun grantPressed() {
|
||||
cancelTimer()
|
||||
if (Config.suAuth) {
|
||||
@@ -78,7 +87,11 @@ class SuRequestViewModel(
|
||||
val info = handler.pkgInfo
|
||||
val app = info.applicationInfo
|
||||
|
||||
isSharedUid = info.sharedUserId != null
|
||||
val isSharedUid = info.sharedUserId != null
|
||||
val icon: Drawable?
|
||||
val title: String
|
||||
val packageName: String
|
||||
|
||||
if (app == null) {
|
||||
icon = pm.defaultActivityIcon
|
||||
title = info.sharedUserId.toString()
|
||||
@@ -89,10 +102,19 @@ class SuRequestViewModel(
|
||||
packageName = info.packageName
|
||||
}
|
||||
|
||||
selectedItemPosition = timeoutPrefs.getInt(packageName, 0)
|
||||
val selectedPos = timeoutPrefs.getInt(packageName, 0)
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
showUi = true,
|
||||
icon = icon,
|
||||
title = title,
|
||||
packageName = packageName,
|
||||
isSharedUid = isSharedUid,
|
||||
selectedItemPosition = selectedPos,
|
||||
useTapjackProtection = Config.suTapjack,
|
||||
)
|
||||
}
|
||||
timer.start()
|
||||
useTapjackProtection = Config.suTapjack
|
||||
showUi = true
|
||||
initialized = true
|
||||
}
|
||||
|
||||
@@ -100,8 +122,9 @@ class SuRequestViewModel(
|
||||
if (!initialized) return
|
||||
timer.cancel()
|
||||
|
||||
val pos = selectedItemPosition
|
||||
timeoutPrefs.edit { putInt(packageName, pos) }
|
||||
val pos = _uiState.value.selectedItemPosition
|
||||
val pkg = _uiState.value.packageName
|
||||
timeoutPrefs.edit { putInt(pkg, pos) }
|
||||
|
||||
viewModelScope.launch {
|
||||
handler.respond(action, Config.Value.TIMEOUT_LIST[pos])
|
||||
@@ -111,7 +134,7 @@ class SuRequestViewModel(
|
||||
|
||||
private fun cancelTimer() {
|
||||
timer.cancel()
|
||||
denyCountdown = 0
|
||||
_uiState.update { it.copy(denyCountdown = 0) }
|
||||
}
|
||||
|
||||
private inner class SuTimer(
|
||||
@@ -120,16 +143,17 @@ class SuRequestViewModel(
|
||||
) : CountDownTimer(millis, interval) {
|
||||
|
||||
override fun onTick(remains: Long) {
|
||||
if (!grantEnabled && remains <= millis - 1000) {
|
||||
grantEnabled = true
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
grantEnabled = it.grantEnabled || remains <= millis - 1000,
|
||||
denyCountdown = (remains / 1000).toInt() + 1
|
||||
)
|
||||
}
|
||||
denyCountdown = (remains / 1000).toInt() + 1
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
denyCountdown = 0
|
||||
_uiState.update { it.copy(denyCountdown = 0) }
|
||||
respond(DENY)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user