From f7a3699fe38d7f610f4bbb90be631b39f7e4363a Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Sat, 21 Jun 2025 12:44:29 +0600 Subject: [PATCH] manager: show module update count as badge in bottom bar instead of status card --- .../com/rifsxd/ksunext/ui/MainActivity.kt | 30 +++++++++++++++---- .../java/com/rifsxd/ksunext/ui/screen/Home.kt | 14 +-------- .../com/rifsxd/ksunext/ui/screen/Module.kt | 2 +- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt index 6d60482b..2551cb66 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/MainActivity.kt @@ -24,6 +24,8 @@ import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.systemBars 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.NavigationBar import androidx.compose.material3.NavigationBarItem @@ -38,6 +40,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavBackStackEntry import androidx.navigation.NavHostController 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.isSuCompatDisabled import com.rifsxd.ksunext.ui.screen.FlashIt +import com.rifsxd.ksunext.ui.viewmodel.ModuleViewModel class MainActivity : ComponentActivity() { @@ -104,6 +108,11 @@ class MainActivity : ComponentActivity() { val prefs = getSharedPreferences("settings", Context.MODE_PRIVATE) val amoledMode = prefs.getBoolean("enable_amoled", false) + val moduleViewModel: ModuleViewModel = viewModel() + val moduleUpdateCount = moduleViewModel.moduleList.count { + moduleViewModel.checkUpdate(it).first.isNotEmpty() + } + KernelSUTheme ( amoledMode = amoledMode ) { @@ -137,7 +146,7 @@ class MainActivity : ComponentActivity() { enter = slideInVertically(initialOffsetY = { it }) + fadeIn(), exit = slideOutVertically(targetOffsetY = { it }) + fadeOut() ) { - BottomBar(navController) + BottomBar(navController, moduleUpdateCount) } }, contentWindowInsets = WindowInsets(0, 0, 0, 0) @@ -164,7 +173,7 @@ class MainActivity : ComponentActivity() { } @Composable -private fun BottomBar(navController: NavHostController) { +private fun BottomBar(navController: NavHostController, moduleUpdateCount: Int) { val navigator = navController.rememberDestinationsNavigator() val isManager = Natives.becomeManager(ksuApp.packageName) val fullFeatured = isManager && !Natives.requireNewKernel() && rootAvailable() @@ -208,10 +217,21 @@ private fun BottomBar(navController: NavHostController) { } }, icon = { - if (isCurrentDestOnBackStack) { - Icon(destination.iconSelected, stringResource(destination.label)) + // Show badge for Module icon if moduleUpdateCount > 0 + 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 { - 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)) }, diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt index 7344036f..83fc1212 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Home.kt @@ -111,11 +111,7 @@ fun HomeScreen(navigator: DestinationsNavigator) { } } - val moduleUpdateCount = moduleViewModel.moduleList.count { - moduleViewModel.checkUpdate(it).first.isNotEmpty() - } - - StatusCard(kernelVersion, ksuVersion, lkmMode, moduleUpdateCount) { + StatusCard(kernelVersion, ksuVersion, lkmMode) { navigator.navigate(InstallScreenDestination) } if (isManager && Natives.requireNewKernel()) { @@ -429,14 +425,6 @@ private fun StatusCard( 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() if (suSFS == "Supported") { Text( diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt index 7aa5fb82..d5f5b81d 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt @@ -1012,7 +1012,7 @@ fun ModuleItem( Spacer(modifier = Modifier.weight(1f, true)) - if (updateUrl.isNotEmpty()) { + if (updateUrl.isNotEmpty() && !module.remove && !module.update) { Button( modifier = Modifier.defaultMinSize(52.dp, 32.dp), enabled = !module.remove,