You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: show module update count as badge in bottom bar instead of status card
This commit is contained in:
@@ -24,6 +24,8 @@ import androidx.compose.foundation.layout.only
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.systemBars
|
import androidx.compose.foundation.layout.systemBars
|
||||||
import androidx.compose.foundation.layout.union
|
import androidx.compose.foundation.layout.union
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.BadgedBox
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.NavigationBar
|
import androidx.compose.material3.NavigationBar
|
||||||
import androidx.compose.material3.NavigationBarItem
|
import androidx.compose.material3.NavigationBarItem
|
||||||
@@ -38,6 +40,7 @@ import androidx.compose.runtime.remember
|
|||||||
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.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
@@ -59,6 +62,7 @@ import com.rifsxd.ksunext.ui.util.rootAvailable
|
|||||||
import com.rifsxd.ksunext.ui.util.install
|
import com.rifsxd.ksunext.ui.util.install
|
||||||
import com.rifsxd.ksunext.ui.util.isSuCompatDisabled
|
import com.rifsxd.ksunext.ui.util.isSuCompatDisabled
|
||||||
import com.rifsxd.ksunext.ui.screen.FlashIt
|
import com.rifsxd.ksunext.ui.screen.FlashIt
|
||||||
|
import com.rifsxd.ksunext.ui.viewmodel.ModuleViewModel
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@@ -104,6 +108,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
val prefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
val prefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||||
val amoledMode = prefs.getBoolean("enable_amoled", false)
|
val amoledMode = prefs.getBoolean("enable_amoled", false)
|
||||||
|
|
||||||
|
val moduleViewModel: ModuleViewModel = viewModel()
|
||||||
|
val moduleUpdateCount = moduleViewModel.moduleList.count {
|
||||||
|
moduleViewModel.checkUpdate(it).first.isNotEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
KernelSUTheme (
|
KernelSUTheme (
|
||||||
amoledMode = amoledMode
|
amoledMode = amoledMode
|
||||||
) {
|
) {
|
||||||
@@ -137,7 +146,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
|
enter = slideInVertically(initialOffsetY = { it }) + fadeIn(),
|
||||||
exit = slideOutVertically(targetOffsetY = { it }) + fadeOut()
|
exit = slideOutVertically(targetOffsetY = { it }) + fadeOut()
|
||||||
) {
|
) {
|
||||||
BottomBar(navController)
|
BottomBar(navController, moduleUpdateCount)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||||
@@ -164,7 +173,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun BottomBar(navController: NavHostController) {
|
private fun BottomBar(navController: NavHostController, moduleUpdateCount: Int) {
|
||||||
val navigator = navController.rememberDestinationsNavigator()
|
val navigator = navController.rememberDestinationsNavigator()
|
||||||
val isManager = Natives.becomeManager(ksuApp.packageName)
|
val isManager = Natives.becomeManager(ksuApp.packageName)
|
||||||
val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable()
|
val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable()
|
||||||
@@ -208,10 +217,21 @@ private fun BottomBar(navController: NavHostController) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon = {
|
icon = {
|
||||||
if (isCurrentDestOnBackStack) {
|
// Show badge for Module icon if moduleUpdateCount > 0
|
||||||
Icon(destination.iconSelected, stringResource(destination.label))
|
if (destination == BottomBarDestination.Module && moduleUpdateCount > 0) {
|
||||||
|
BadgedBox(badge = { Badge { Text(moduleUpdateCount.toString()) } }) {
|
||||||
|
if (isCurrentDestOnBackStack) {
|
||||||
|
Icon(destination.iconSelected, stringResource(destination.label))
|
||||||
|
} else {
|
||||||
|
Icon(destination.iconNotSelected, stringResource(destination.label))
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Icon(destination.iconNotSelected, stringResource(destination.label))
|
if (isCurrentDestOnBackStack) {
|
||||||
|
Icon(destination.iconSelected, stringResource(destination.label))
|
||||||
|
} else {
|
||||||
|
Icon(destination.iconNotSelected, stringResource(destination.label))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label = { Text(stringResource(destination.label)) },
|
label = { Text(stringResource(destination.label)) },
|
||||||
|
|||||||
@@ -111,11 +111,7 @@ fun HomeScreen(navigator: DestinationsNavigator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val moduleUpdateCount = moduleViewModel.moduleList.count {
|
StatusCard(kernelVersion, ksuVersion, lkmMode) {
|
||||||
moduleViewModel.checkUpdate(it).first.isNotEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusCard(kernelVersion, ksuVersion, lkmMode, moduleUpdateCount) {
|
|
||||||
navigator.navigate(InstallScreenDestination)
|
navigator.navigate(InstallScreenDestination)
|
||||||
}
|
}
|
||||||
if (isManager && Natives.requireNewKernel()) {
|
if (isManager && Natives.requireNewKernel()) {
|
||||||
@@ -429,14 +425,6 @@ private fun StatusCard(
|
|||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium
|
||||||
)
|
)
|
||||||
|
|
||||||
if (moduleUpdateCount > 0) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.home_module_update_count, moduleUpdateCount),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val suSFS = getSuSFS()
|
val suSFS = getSuSFS()
|
||||||
if (suSFS == "Supported") {
|
if (suSFS == "Supported") {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -1012,7 +1012,7 @@ fun ModuleItem(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f, true))
|
Spacer(modifier = Modifier.weight(1f, true))
|
||||||
|
|
||||||
if (updateUrl.isNotEmpty()) {
|
if (updateUrl.isNotEmpty() && !module.remove && !module.update) {
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
|
modifier = Modifier.defaultMinSize(52.dp, 32.dp),
|
||||||
enabled = !module.remove,
|
enabled = !module.remove,
|
||||||
|
|||||||
Reference in New Issue
Block a user