mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Redesign Modules tab and polish various screens
- Replace "Install from storage" button with a FAB matching KernelSU - Redesign module cards with expandable description, divider, and icon-based action/update/remove buttons - Reorder nav bar: Modules, Superuser, Home, Logs, Settings - Make suRestrict reactive in Superuser detail screen - Add horizontal padding to log tab row - Add checkbox left padding in DenyList - Rename Superuser detail title to "Superuser Setting" - Simplify revoke row to a clickable card with error-colored text Made-with: Cursor
This commit is contained in:
@@ -63,15 +63,15 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
enum class Tab(val titleRes: Int, val iconRes: Int) {
|
||||
HOME(CoreR.string.section_home, R.drawable.ic_home_outlined_md2),
|
||||
SUPERUSER(CoreR.string.superuser, R.drawable.ic_superuser_outlined_md2),
|
||||
LOG(CoreR.string.logs, R.drawable.ic_bug_outlined_md2),
|
||||
MODULES(CoreR.string.modules, R.drawable.ic_module_outlined_md2),
|
||||
SUPERUSER(CoreR.string.superuser, R.drawable.ic_superuser_outlined_md2),
|
||||
HOME(CoreR.string.section_home, R.drawable.ic_home_outlined_md2),
|
||||
LOG(CoreR.string.logs, R.drawable.ic_bug_outlined_md2),
|
||||
SETTINGS(CoreR.string.settings, R.drawable.ic_settings_outlined_md2);
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainScreen(initialTab: Int = 0) {
|
||||
fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
|
||||
val navigator = LocalNavigator.current
|
||||
val pagerState = rememberPagerState(initialPage = initialTab, pageCount = { Tab.entries.size })
|
||||
|
||||
|
||||
@@ -270,6 +270,7 @@ private fun DenyAppCard(app: DenyAppState) {
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Checkbox(
|
||||
checked = app.isChecked,
|
||||
onCheckedChange = { app.toggleAll() }
|
||||
@@ -307,6 +308,7 @@ private fun ProcessRow(proc: DenyProcessState) {
|
||||
else MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Checkbox(
|
||||
checked = proc.isEnabled,
|
||||
onCheckedChange = { proc.toggle() }
|
||||
|
||||
@@ -113,7 +113,7 @@ fun LogScreen(viewModel: LogViewModel) {
|
||||
onTabSelected = { selectedTab = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 8.dp)
|
||||
.padding(horizontal = 12.dp, vertical = 8.dp)
|
||||
)
|
||||
|
||||
if (uiState.loading) {
|
||||
|
||||
@@ -1,35 +1,56 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.CircularProgressIndicator
|
||||
import top.yukonga.miuix.kmp.basic.FloatingActionButton
|
||||
import top.yukonga.miuix.kmp.basic.HorizontalDivider
|
||||
import top.yukonga.miuix.kmp.basic.Icon
|
||||
import top.yukonga.miuix.kmp.basic.IconButton
|
||||
import top.yukonga.miuix.kmp.basic.MiuixScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||
import top.yukonga.miuix.kmp.basic.Switch
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TextButton
|
||||
import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.extended.Add
|
||||
import top.yukonga.miuix.kmp.icon.extended.Delete
|
||||
import top.yukonga.miuix.kmp.icon.extended.Play
|
||||
import top.yukonga.miuix.kmp.icon.extended.Undo
|
||||
import top.yukonga.miuix.kmp.icon.extended.UploadCloud
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@@ -37,6 +58,7 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val scrollBehavior = MiuixScrollBehavior()
|
||||
val colorScheme = MiuixTheme.colorScheme
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -45,6 +67,23 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(
|
||||
onClick = { viewModel.installPressed() },
|
||||
shadowElevation = 0.dp,
|
||||
modifier = Modifier
|
||||
.padding(bottom = 88.dp, end = 20.dp)
|
||||
.border(0.05.dp, colorScheme.outline.copy(alpha = 0.5f), CircleShape),
|
||||
content = {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Add,
|
||||
contentDescription = stringResource(CoreR.string.module_action_install_external),
|
||||
modifier = Modifier.size(28.dp),
|
||||
tint = colorScheme.onPrimary
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
popupHost = { }
|
||||
) { padding ->
|
||||
if (uiState.loading) {
|
||||
@@ -59,6 +98,22 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
return@Scaffold
|
||||
}
|
||||
|
||||
if (uiState.modules.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.module_empty),
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
color = colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
return@Scaffold
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -69,36 +124,9 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
|
||||
item {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.module_action_install_external),
|
||||
onClick = { viewModel.installPressed() },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
items(uiState.modules, key = { it.module.id }) { item ->
|
||||
ModuleCard(item = item, viewModel = viewModel)
|
||||
}
|
||||
|
||||
if (uiState.modules.isEmpty()) {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.module_empty),
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items(uiState.modules, key = { it.module.id }) { item ->
|
||||
ModuleCard(item = item, viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
}
|
||||
}
|
||||
@@ -108,92 +136,171 @@ fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
private fun ModuleCard(item: ModuleItem, viewModel: ModuleViewModel) {
|
||||
val cardAlpha = if (!item.isRemoved && item.isEnabled && !item.showNotice) 1f else 0.5f
|
||||
val strikeThrough = if (item.isRemoved) TextDecoration.LineThrough else TextDecoration.None
|
||||
val colorScheme = MiuixTheme.colorScheme
|
||||
val actionIconTint = colorScheme.onSurface.copy(alpha = 0.8f)
|
||||
val actionBg = colorScheme.secondaryContainer.copy(alpha = 0.8f)
|
||||
val updateBg = colorScheme.tertiaryContainer.copy(alpha = 0.6f)
|
||||
val updateTint = colorScheme.onTertiaryContainer.copy(alpha = 0.8f)
|
||||
var expanded by rememberSaveable(item.module.id) { mutableStateOf(false) }
|
||||
val hasDescription = item.module.description.isNotBlank()
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.alpha(cardAlpha)
|
||||
.alpha(cardAlpha),
|
||||
insideMargin = PaddingValues(16.dp),
|
||||
onClick = { if (hasDescription) expanded = !expanded }
|
||||
) {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 4.dp)
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = item.module.name,
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(
|
||||
CoreR.string.module_version_author,
|
||||
item.module.version,
|
||||
item.module.author
|
||||
),
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
}
|
||||
Switch(
|
||||
checked = item.isEnabled,
|
||||
onCheckedChange = { viewModel.toggleEnabled(item) }
|
||||
Text(
|
||||
text = item.module.name,
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(
|
||||
CoreR.string.module_version_author,
|
||||
item.module.version,
|
||||
item.module.author
|
||||
),
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = colorScheme.onSurfaceVariantSummary,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
}
|
||||
Switch(
|
||||
checked = item.isEnabled,
|
||||
onCheckedChange = { viewModel.toggleEnabled(item) }
|
||||
)
|
||||
}
|
||||
|
||||
if (item.module.description.isNotEmpty()) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
if (hasDescription) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(top = 2.dp)
|
||||
.animateContentSize()
|
||||
) {
|
||||
Text(
|
||||
text = item.module.description,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
color = colorScheme.onSurfaceVariantSummary,
|
||||
textDecoration = strikeThrough,
|
||||
maxLines = 5,
|
||||
overflow = if (expanded) TextOverflow.Clip else TextOverflow.Ellipsis,
|
||||
maxLines = if (expanded) Int.MAX_VALUE else 4,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (item.showNotice) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
text = item.noticeText,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
if (item.showNotice) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
text = item.noticeText,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = colorScheme.primary,
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
thickness = 0.5.dp,
|
||||
color = colorScheme.outline.copy(alpha = 0.5f)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
AnimatedVisibility(
|
||||
visible = item.isEnabled && !item.isRemoved,
|
||||
enter = fadeIn(),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
if (item.showAction) {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.module_action),
|
||||
onClick = { viewModel.runAction(item.module.id, item.module.name) },
|
||||
enabled = item.isEnabled
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (item.showAction) {
|
||||
IconButton(
|
||||
backgroundColor = actionBg,
|
||||
minHeight = 35.dp,
|
||||
minWidth = 35.dp,
|
||||
onClick = { viewModel.runAction(item.module.id, item.module.name) },
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.size(20.dp),
|
||||
imageVector = MiuixIcons.Play,
|
||||
tint = actionIconTint,
|
||||
contentDescription = stringResource(CoreR.string.module_action)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = item.showUpdate && item.updateReady,
|
||||
enter = fadeIn(),
|
||||
exit = fadeOut()
|
||||
) {
|
||||
IconButton(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
backgroundColor = updateBg,
|
||||
minHeight = 35.dp,
|
||||
minWidth = 35.dp,
|
||||
onClick = { viewModel.downloadPressed(item.module.updateInfo) },
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.size(20.dp),
|
||||
imageVector = MiuixIcons.UploadCloud,
|
||||
tint = updateTint,
|
||||
contentDescription = stringResource(CoreR.string.update),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(CoreR.string.update),
|
||||
color = updateTint,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IconButton(
|
||||
backgroundColor = actionBg,
|
||||
minHeight = 35.dp,
|
||||
minWidth = 35.dp,
|
||||
onClick = { viewModel.toggleRemove(item) },
|
||||
enabled = !item.isUpdated
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.size(20.dp),
|
||||
imageVector = if (item.isRemoved) MiuixIcons.Undo else MiuixIcons.Delete,
|
||||
tint = actionIconTint,
|
||||
contentDescription = null
|
||||
)
|
||||
Text(
|
||||
text = stringResource(
|
||||
if (item.isRemoved) CoreR.string.module_state_restore
|
||||
else CoreR.string.module_state_remove
|
||||
),
|
||||
color = actionIconTint,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
)
|
||||
}
|
||||
|
||||
if (item.showUpdate) {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.update),
|
||||
onClick = { viewModel.downloadPressed(item.module.updateInfo) },
|
||||
enabled = item.updateReady
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
|
||||
TextButton(
|
||||
text = stringResource(
|
||||
if (item.isRemoved) CoreR.string.module_state_restore
|
||||
else CoreR.string.module_state_remove
|
||||
),
|
||||
onClick = { viewModel.toggleRemove(item) },
|
||||
enabled = !item.isUpdated
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -47,10 +48,12 @@ fun SuperuserDetailScreen(
|
||||
val item = items.firstOrNull()
|
||||
val scrollBehavior = MiuixScrollBehavior()
|
||||
|
||||
LaunchedEffect(Unit) { viewModel.refreshSuRestrict() }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = item?.title ?: "",
|
||||
title = stringResource(CoreR.string.superuser_setting),
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
@@ -114,7 +117,7 @@ fun SuperuserDetailScreen(
|
||||
item {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column {
|
||||
if (item.showSlider) {
|
||||
if (uiState.suRestrict || item.isRestricted) {
|
||||
SwitchRow(
|
||||
title = stringResource(CoreR.string.settings_su_restrict_title),
|
||||
summary = stringResource(
|
||||
|
||||
@@ -57,6 +57,7 @@ class SuperuserViewModel(
|
||||
data class UiState(
|
||||
val loading: Boolean = true,
|
||||
val policies: List<PolicyItem> = emptyList(),
|
||||
val suRestrict: Boolean = Config.suRestrict,
|
||||
)
|
||||
|
||||
private val _uiState = MutableStateFlow(UiState())
|
||||
@@ -106,10 +107,14 @@ class SuperuserViewModel(
|
||||
{ it.appName.lowercase(Locale.ROOT) },
|
||||
{ it.packageName }
|
||||
))
|
||||
_uiState.update { it.copy(loading = false, policies = policies) }
|
||||
_uiState.update { it.copy(loading = false, policies = policies, suRestrict = Config.suRestrict) }
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshSuRestrict() {
|
||||
_uiState.update { it.copy(suRestrict = Config.suRestrict) }
|
||||
}
|
||||
|
||||
fun deletePressed(item: PolicyItem) {
|
||||
fun updateState() = viewModelScope.launch {
|
||||
db.delete(item.policy.uid)
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
<string name="save_log">Save log</string>
|
||||
<string name="clear_log">Clear log</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="superuser_setting">Superuser Setting</string>
|
||||
<string name="enabled">Enabled</string>
|
||||
<string name="disabled">Disabled</string>
|
||||
<string name="pid">PID: %1$d</string>
|
||||
|
||||
Reference in New Issue
Block a user