manager: show module state
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.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
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
@@ -111,7 +112,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onCheckChanged = {
|
onCheckChanged = {
|
||||||
val success = toggleModule(module.id, isChecked)
|
val success = toggleModule(module.id, !isChecked)
|
||||||
if (success) {
|
if (success) {
|
||||||
isChecked = it
|
isChecked = it
|
||||||
} else scope.launch {
|
} else scope.launch {
|
||||||
@@ -149,28 +150,34 @@ private fun ModuleItem(
|
|||||||
colors =
|
colors =
|
||||||
CardDefaults.elevatedCardColors(containerColor = MaterialTheme.colorScheme.surface)
|
CardDefaults.elevatedCardColors(containerColor = MaterialTheme.colorScheme.surface)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
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(16.dp, 16.dp, 16.dp, 0.dp)) {
|
||||||
Row {
|
Row {
|
||||||
Column {
|
Column {
|
||||||
Text(
|
Text(
|
||||||
|
text = module.name,
|
||||||
fontSize = MaterialTheme.typography.titleLarge.fontSize,
|
fontSize = MaterialTheme.typography.titleLarge.fontSize,
|
||||||
fontFamily = MaterialTheme.typography.titleLarge.fontFamily,
|
fontFamily = MaterialTheme.typography.titleLarge.fontFamily,
|
||||||
text = module.name,
|
textDecoration = textDecoration,
|
||||||
)
|
)
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
Text(
|
Text(
|
||||||
|
text = module.version,
|
||||||
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
||||||
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
||||||
text = module.version
|
textDecoration = textDecoration
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
text = module.author,
|
||||||
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
fontFamily = MaterialTheme.typography.titleMedium.fontFamily,
|
||||||
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
fontSize = MaterialTheme.typography.titleMedium.fontSize,
|
||||||
text = module.author
|
textDecoration = textDecoration
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -178,17 +185,24 @@ private fun ModuleItem(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
Switch(checked = isChecked, 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,
|
||||||
fontFamily = MaterialTheme.typography.bodyMedium.fontFamily,
|
fontFamily = MaterialTheme.typography.bodyMedium.fontFamily,
|
||||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
||||||
text = module.description,
|
lineHeight = MaterialTheme.typography.bodyMedium.lineHeight,
|
||||||
|
fontWeight = MaterialTheme.typography.bodyMedium.fontWeight,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 4,
|
maxLines = 4,
|
||||||
|
textDecoration = textDecoration
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -203,6 +217,7 @@ private fun ModuleItem(
|
|||||||
Spacer(modifier = Modifier.weight(1f, true))
|
Spacer(modifier = Modifier.weight(1f, true))
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
|
enabled = !module.update && !module.remove,
|
||||||
onClick = { onUninstall(module) },
|
onClick = { onUninstall(module) },
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
@@ -225,8 +240,10 @@ fun ModuleItemPreview() {
|
|||||||
version = "version",
|
version = "version",
|
||||||
versionCode = 1,
|
versionCode = 1,
|
||||||
author = "author",
|
author = "author",
|
||||||
description = "a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a ",
|
description = "I am a test module and i do nothing but show a very long description",
|
||||||
enabled = true
|
enabled = true,
|
||||||
|
update = true,
|
||||||
|
remove = true,
|
||||||
)
|
)
|
||||||
ModuleItem(module, true, {}, {})
|
ModuleItem(module, true, {}, {})
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ fun execKsud(args: String): Boolean {
|
|||||||
|
|
||||||
fun install() {
|
fun install() {
|
||||||
val result = execKsud("install")
|
val result = execKsud("install")
|
||||||
Log.w("KernelSU", "install ksud result: $result")
|
Log.w(TAG, "install ksud result: $result")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun listModules(): String {
|
fun listModules(): String {
|
||||||
@@ -55,7 +55,7 @@ fun toggleModule(id: String, enable: Boolean): Boolean {
|
|||||||
"module disable $id"
|
"module disable $id"
|
||||||
}
|
}
|
||||||
val result = execKsud(cmd)
|
val result = execKsud(cmd)
|
||||||
Log.i(TAG, "toggle module $id result: $result")
|
Log.i(TAG, "$cmd result: $result")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.weishu.kernelsu.ui.viewmodel
|
package me.weishu.kernelsu.ui.viewmodel
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
@@ -28,7 +29,9 @@ class ModuleViewModel : ViewModel() {
|
|||||||
val version: String,
|
val version: String,
|
||||||
val versionCode: Int,
|
val versionCode: Int,
|
||||||
val description: String,
|
val description: String,
|
||||||
val enabled: Boolean
|
val enabled: Boolean,
|
||||||
|
val update: Boolean,
|
||||||
|
val remove: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
var isRefreshing by mutableStateOf(false)
|
var isRefreshing by mutableStateOf(false)
|
||||||
@@ -64,7 +67,9 @@ class ModuleViewModel : ViewModel() {
|
|||||||
obj.getString("version"),
|
obj.getString("version"),
|
||||||
obj.getInt("versionCode"),
|
obj.getInt("versionCode"),
|
||||||
obj.getString("description"),
|
obj.getString("description"),
|
||||||
obj.getBoolean("enabled")
|
obj.getBoolean("enabled"),
|
||||||
|
obj.getBoolean("update"),
|
||||||
|
obj.getBoolean("remove"),
|
||||||
)
|
)
|
||||||
}.toList()
|
}.toList()
|
||||||
}.onFailure { e ->
|
}.onFailure { e ->
|
||||||
|
|||||||
Reference in New Issue
Block a user