Skip to content

Commit

Permalink
manager: Move modules 'Update' and 'Uninstall' buttons into drop-down…
Browse files Browse the repository at this point in the history
… menu
  • Loading branch information
changhuapeng committed Dec 15, 2024
1 parent 030fe36 commit 7dcb647
Showing 1 changed file with 85 additions and 41 deletions.
126 changes: 85 additions & 41 deletions manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
Expand All @@ -30,15 +31,22 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Wysiwyg
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.PlayArrow
import androidx.compose.material3.Button
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Update
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
Expand All @@ -65,7 +73,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
Expand Down Expand Up @@ -545,8 +552,8 @@ fun ModuleItem(
FilledTonalButton(
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
onClick = {
navigator.navigate(ExecuteModuleActionScreenDestination(module.id))
viewModel.markNeedRefresh()
navigator.navigate(ExecuteModuleActionScreenDestination(module.id))
viewModel.markNeedRefresh()
},
contentPadding = ButtonDefaults.TextButtonContentPadding
) {
Expand All @@ -555,7 +562,7 @@ fun ModuleItem(
.padding(end = 7.dp)
.size(20.dp),
imageVector = Icons.Outlined.PlayArrow,
contentDescription = null
contentDescription = stringResource(R.string.action)
)
Text(
text = stringResource(R.string.action),
Expand All @@ -574,53 +581,90 @@ fun ModuleItem(
interactionSource = interactionSource,
contentPadding = ButtonDefaults.TextButtonContentPadding
) {
if (!module.hasActionScript) {
Icon(
modifier = Modifier
.padding(end = 7.dp)
.size(20.dp),
imageVector = Icons.AutoMirrored.Outlined.Wysiwyg,
contentDescription = null
)
}
Icon(
modifier = Modifier
.padding(end = 7.dp)
.size(20.dp),
imageVector = Icons.AutoMirrored.Outlined.Wysiwyg,
contentDescription = stringResource(R.string.open)
)
Text(
text = stringResource(R.string.open),
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize,
text = stringResource(R.string.open)
fontSize = MaterialTheme.typography.labelMedium.fontSize
)
}
}

Spacer(modifier = Modifier.weight(1f, true))

if (updateUrl.isNotEmpty()) {
Button(
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
onClick = { onUpdate(module) },
shape = ButtonDefaults.textShape,
contentPadding = ButtonDefaults.TextButtonContentPadding
var expanded by remember { mutableStateOf(false) }

Box {
BadgedBox(
badge = {
if (updateUrl.isNotEmpty()) {
Badge(
modifier = Modifier
.offset(x = (-6).dp, y = 6.dp)
.size(7.dp)
)
}
}
) {
Text(
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize,
text = stringResource(R.string.module_update)
IconButton(onClick = { expanded = true }) {
Icon(Icons.Outlined.Settings, contentDescription = "Settings")
}
}
DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
DropdownMenuItem(
enabled = updateUrl.isNotEmpty(),
text = {
Text(
text = stringResource(R.string.module_update),
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize
)
},
onClick = {
expanded = false
onUpdate(module)
viewModel.markNeedRefresh()
},
leadingIcon = {
Icon(
modifier = Modifier
.padding(end = 7.dp)
.size(20.dp),
imageVector = Icons.Outlined.Update,
contentDescription = stringResource(R.string.module_update)
)
}
)
DropdownMenuItem(
enabled = !module.remove,
text = {
Text(
text = stringResource(R.string.uninstall),
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize
)
},
onClick = {
expanded = false
onUninstall(module)
},
leadingIcon = {
Icon(
modifier = Modifier
.padding(end = 7.dp)
.size(20.dp),
imageVector = Icons.Outlined.Delete,
contentDescription = stringResource(R.string.uninstall)
)
}
)
}

Spacer(modifier = Modifier.weight(0.1f, true))
}

FilledTonalButton(
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
enabled = !module.remove,
onClick = { onUninstall(module) },
contentPadding = ButtonDefaults.TextButtonContentPadding
) {
Text(
fontFamily = MaterialTheme.typography.labelMedium.fontFamily,
fontSize = MaterialTheme.typography.labelMedium.fontSize,
text = stringResource(R.string.uninstall)
)
}
}
}
Expand Down

0 comments on commit 7dcb647

Please sign in to comment.