This commit is contained in:
tiann
2022-12-09 22:03:03 +08:00
parent fa71c6cfe1
commit 51c84400cf
76 changed files with 2579 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
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.material.icons.Icons
import androidx.compose.material.icons.filled.*
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.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
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
) {
Greeting()
}
}
}
}
}
@Composable
fun Greeting() {
val items = listOf(
Screen.Home,
Screen.SuperUser,
Screen.Module
)
val navController = rememberNavController()
var showAboutDialog by remember { mutableStateOf(false) }
AboutDialog(openDialog = showAboutDialog, onDismiss = {
showAboutDialog = false
})
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")
}
}
)
},
bottomBar = {
BottomNavigation(
backgroundColor = MaterialTheme.colors.background,
) {
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
}
}
)
}
}
}
) { 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() }
}
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
KernelSUTheme {
Greeting()
}
}
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)
}