manager: Optimize ModuleScreen UI (#51)
* manager: fix moduleList is empty cannot parse to jsonArray * manager: Optimize ModuleScreen UI * manager: Optimize switch position
This commit is contained in:
@@ -16,6 +16,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
@@ -101,6 +102,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(innerPadding)
|
.padding(innerPadding)
|
||||||
|
.padding(16.dp)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
val isEmpty = viewModel.moduleList.isEmpty()
|
val isEmpty = viewModel.moduleList.isEmpty()
|
||||||
@@ -110,7 +112,9 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
Text(stringResource(R.string.module_empty))
|
Text(stringResource(R.string.module_empty))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LazyColumn {
|
LazyColumn(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(15.dp)
|
||||||
|
) {
|
||||||
items(viewModel.moduleList) { module ->
|
items(viewModel.moduleList) { module ->
|
||||||
var isChecked by rememberSaveable(module) { mutableStateOf(module.enabled) }
|
var isChecked by rememberSaveable(module) { mutableStateOf(module.enabled) }
|
||||||
ModuleItem(module,
|
ModuleItem(module,
|
||||||
@@ -141,11 +145,13 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
val message = if (isChecked) failedDisable else failedEnable
|
val message = if (isChecked) failedDisable else failedEnable
|
||||||
snackBarHost.showSnackbar(message.format(module.name))
|
snackBarHost.showSnackbar(message.format(module.name))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
// fix last item shadow incomplete in LazyColumn
|
||||||
|
Spacer(Modifier.height(1.dp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,62 +172,69 @@ private fun ModuleItem(
|
|||||||
onCheckChanged: (Boolean) -> Unit
|
onCheckChanged: (Boolean) -> Unit
|
||||||
) {
|
) {
|
||||||
ElevatedCard(
|
ElevatedCard(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
colors = CardDefaults.elevatedCardColors(containerColor = MaterialTheme.colorScheme.surface)
|
||||||
.padding(8.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.elevatedCardColors(containerColor = MaterialTheme.colorScheme.surface)
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val textDecoration = if (!module.remove) null else TextDecoration.LineThrough
|
val textDecoration = if (!module.remove) null else TextDecoration.LineThrough
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(16.dp, 16.dp, 16.dp, 0.dp)) {
|
Column(modifier = Modifier.padding(24.dp, 16.dp, 24.dp, 0.dp)) {
|
||||||
Row {
|
Row(
|
||||||
Column {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
val moduleVersion = stringResource(id = R.string.module_version)
|
||||||
|
val moduleAuthor = stringResource(id = R.string.module_author)
|
||||||
|
|
||||||
|
Column(modifier = Modifier.fillMaxWidth(0.8f)) {
|
||||||
Text(
|
Text(
|
||||||
text = module.name,
|
text = module.name,
|
||||||
fontSize = MaterialTheme.typography.titleLarge.fontSize,
|
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
||||||
fontFamily = MaterialTheme.typography.titleLarge.fontFamily,
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
lineHeight = MaterialTheme.typography.bodySmall.lineHeight,
|
||||||
|
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
||||||
textDecoration = textDecoration,
|
textDecoration = textDecoration,
|
||||||
)
|
)
|
||||||
|
|
||||||
Row {
|
Text(
|
||||||
Text(
|
text = "$moduleVersion: ${module.version}",
|
||||||
text = module.version,
|
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||||
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
lineHeight = MaterialTheme.typography.bodySmall.lineHeight,
|
||||||
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
||||||
textDecoration = textDecoration
|
textDecoration = textDecoration
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Text(
|
||||||
|
text = "$moduleAuthor: ${module.author}",
|
||||||
Text(
|
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||||
text = module.author,
|
lineHeight = MaterialTheme.typography.bodySmall.lineHeight,
|
||||||
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
||||||
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
textDecoration = textDecoration
|
||||||
textDecoration = textDecoration
|
)
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
Switch(
|
Row(
|
||||||
enabled = !module.update,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
checked = isChecked,
|
horizontalArrangement = Arrangement.End,
|
||||||
onCheckedChange = onCheckChanged
|
) {
|
||||||
)
|
Switch(
|
||||||
|
enabled = !module.update,
|
||||||
|
checked = isChecked,
|
||||||
|
onCheckedChange = onCheckChanged
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = module.description,
|
text = module.description,
|
||||||
fontFamily = MaterialTheme.typography.bodyMedium.fontFamily,
|
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
||||||
lineHeight = MaterialTheme.typography.bodyMedium.lineHeight,
|
lineHeight = MaterialTheme.typography.bodySmall.lineHeight,
|
||||||
fontWeight = MaterialTheme.typography.bodyMedium.fontWeight,
|
fontWeight = MaterialTheme.typography.bodySmall.fontWeight,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 4,
|
maxLines = 4,
|
||||||
textDecoration = textDecoration
|
textDecoration = textDecoration
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ fun listModules(): String {
|
|||||||
val shell = createRootShell()
|
val shell = createRootShell()
|
||||||
|
|
||||||
val out = shell.newJob().add("${getKsuDaemonPath()} module list").to(ArrayList(), null).exec().out
|
val out = shell.newJob().add("${getKsuDaemonPath()} module list").to(ArrayList(), null).exec().out
|
||||||
return out.joinToString("\n")
|
return out.joinToString("\n").ifBlank { "[]" }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleModule(id: String, enable: Boolean): Boolean {
|
fun toggleModule(id: String, enable: Boolean): Boolean {
|
||||||
|
|||||||
@@ -36,4 +36,8 @@
|
|||||||
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
||||||
<string name="about">关于</string>
|
<string name="about">关于</string>
|
||||||
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
||||||
|
<string name="module_uninstall_success">%s 已卸载</string>
|
||||||
|
<string name="module_uninstall_failed">卸载失败: %s</string>
|
||||||
|
<string name="module_version">版本</string>
|
||||||
|
<string name="module_author">作者</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -36,4 +36,8 @@
|
|||||||
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
||||||
<string name="about">关于</string>
|
<string name="about">关于</string>
|
||||||
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
||||||
|
<string name="module_uninstall_success">%s 已卸載</string>
|
||||||
|
<string name="module_uninstall_failed">卸載失敗: %s</string>
|
||||||
|
<string name="module_version">版本</string>
|
||||||
|
<string name="module_author">作者</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -36,4 +36,8 @@
|
|||||||
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
<string name="settings_system_rw_summary">使用 overlayfs 使系统分区可写, 重启生效</string>
|
||||||
<string name="about">关于</string>
|
<string name="about">关于</string>
|
||||||
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
<string name="require_kernel_version_8">需要 KernelSU 版本 8+</string>
|
||||||
|
<string name="module_uninstall_success">%s 已卸載</string>
|
||||||
|
<string name="module_uninstall_failed">卸載失敗: %s</string>
|
||||||
|
<string name="module_version">版本</string>
|
||||||
|
<string name="module_author">作者</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -42,5 +42,7 @@
|
|||||||
<string name="require_kernel_version_8">Require KernelSU version 8+</string>
|
<string name="require_kernel_version_8">Require KernelSU version 8+</string>
|
||||||
<string name="module_uninstall_success">%s uninstalled</string>
|
<string name="module_uninstall_success">%s uninstalled</string>
|
||||||
<string name="module_uninstall_failed">Failed to uninstall: %s</string>
|
<string name="module_uninstall_failed">Failed to uninstall: %s</string>
|
||||||
|
<string name="module_version">Version</string>
|
||||||
|
<string name="module_author">Author</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user