[manager]: Use MD3
This commit is contained in:
@@ -1,31 +1,29 @@
|
||||
@file:OptIn(ExperimentalMaterial3Api::class)
|
||||
|
||||
package me.weishu.kernelsu
|
||||
|
||||
import AboutDialog
|
||||
import Home
|
||||
import Module
|
||||
import SuperUser
|
||||
import SuperUserData
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Color.Companion.Gray
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
@@ -35,14 +33,14 @@ import me.weishu.kernelsu.ui.theme.KernelSUTheme
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
KernelSUTheme {
|
||||
// A surface container using the 'background' color from the theme
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colors.background
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
Greeting()
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +48,68 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Greeting() {
|
||||
fun MainTopAppBar(onMoreClick: () -> Unit) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
"KernelSU",
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = onMoreClick) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
contentDescription = "Localized description"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainBottomNavigation(items: List<Screen>, navController: NavHostController) {
|
||||
|
||||
NavigationBar {
|
||||
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
|
||||
items.forEachIndexed { index, item ->
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = item.icon),
|
||||
contentDescription = ""
|
||||
)
|
||||
},
|
||||
label = { Text(text = stringResource(id = item.resourceId)) },
|
||||
selected = currentDestination?.hierarchy?.any { it.route == item.route } == true,
|
||||
|
||||
onClick = {
|
||||
navController.navigate(item.route) {
|
||||
// Pop up to the start destination of the graph to
|
||||
// avoid building up a large stack of destinations
|
||||
// on the back stack as users select items
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
// Avoid multiple copies of the same destination when
|
||||
// reselecting the same item
|
||||
launchSingleTop = true
|
||||
// Restore state when reselecting a previously selected item
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainScreen() {
|
||||
|
||||
val items = listOf(
|
||||
Screen.Home,
|
||||
@@ -68,68 +127,25 @@ fun Greeting() {
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(text = "KernelSU")
|
||||
},
|
||||
backgroundColor = MaterialTheme.colors.primary,
|
||||
contentColor = Color.White,
|
||||
elevation = 12.dp,
|
||||
actions = {
|
||||
IconButton(onClick = { /*TODO*/ }) {
|
||||
Icon(Icons.Filled.Search, contentDescription = "Search")
|
||||
}
|
||||
IconButton(onClick = {
|
||||
showAboutDialog = true
|
||||
}) {
|
||||
Icon(Icons.Filled.MoreVert, contentDescription = "More")
|
||||
}
|
||||
}
|
||||
)
|
||||
MainTopAppBar {
|
||||
showAboutDialog = true
|
||||
}
|
||||
},
|
||||
bottomBar = {
|
||||
BottomNavigation(
|
||||
backgroundColor = MaterialTheme.colors.background,
|
||||
MainBottomNavigation(items = items, navController = navController)
|
||||
},
|
||||
content = { innerPadding ->
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination = Screen.Home.route,
|
||||
Modifier.padding(innerPadding)
|
||||
) {
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
items.forEach { screen ->
|
||||
BottomNavigationItem(
|
||||
icon = { Icon(painterResource(id = screen.icon), null) },
|
||||
label = { Text(stringResource(screen.resourceId)) },
|
||||
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
||||
selectedContentColor = MaterialTheme.colors.primary,
|
||||
unselectedContentColor = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.medium),
|
||||
onClick = {
|
||||
navController.navigate(screen.route) {
|
||||
// Pop up to the start destination of the graph to
|
||||
// avoid building up a large stack of destinations
|
||||
// on the back stack as users select items
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
// Avoid multiple copies of the same destination when
|
||||
// reselecting the same item
|
||||
launchSingleTop = true
|
||||
// Restore state when reselecting a previously selected item
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(Screen.Home.route) { Home() }
|
||||
composable(Screen.SuperUser.route) { SuperUser() }
|
||||
composable(Screen.Module.route) { Module() }
|
||||
}
|
||||
}
|
||||
) { innerPadding ->
|
||||
NavHost(
|
||||
navController,
|
||||
startDestination = Screen.Home.route,
|
||||
Modifier.padding(innerPadding)
|
||||
) {
|
||||
composable(Screen.Home.route) { Home() }
|
||||
composable(Screen.SuperUser.route) { SuperUser() }
|
||||
composable(Screen.Module.route) { Module() }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -137,13 +153,13 @@ fun Greeting() {
|
||||
@Composable
|
||||
fun DefaultPreview() {
|
||||
KernelSUTheme {
|
||||
Greeting()
|
||||
MainScreen()
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Screen(val route: String, @StringRes val resourceId: Int, val icon: Int) {
|
||||
object Home : Screen("home", R.string.home, R.drawable.ic_home)
|
||||
object SuperUser : Screen("superuser", R.string.superuser, R.drawable.ic_superuser)
|
||||
object Module: Screen("module", R.string.module, R.drawable.ic_module)
|
||||
object Module : Screen("module", R.string.module, R.drawable.ic_module)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user