From b42d367a49b5fd0c5349adcf8974543bc5a19ac1 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Thu, 11 Jan 2024 01:31:35 +0000 Subject: [PATCH 1/2] feat: hide bottom pages depending on the state of kpatch and apatch availability --- app/src/main/java/me/bmax/apatch/APatchApp.kt | 2 +- app/src/main/java/me/bmax/apatch/ui/MainActivity.kt | 10 ++++++++++ .../me/bmax/apatch/ui/screen/BottomBarDestination.kt | 10 ++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/me/bmax/apatch/APatchApp.kt b/app/src/main/java/me/bmax/apatch/APatchApp.kt index 169e44f3f..f6e11ab59 100644 --- a/app/src/main/java/me/bmax/apatch/APatchApp.kt +++ b/app/src/main/java/me/bmax/apatch/APatchApp.kt @@ -155,7 +155,7 @@ class APApplication : Application() { private set(value) { field = value val ready = Natives.nativeReady(value) - _apStateLiveData.value = if(ready) State.KERNELPATCH_READY else State.UNKNOWN_STATE + _apStateLiveData.value = if(ready) State.KERNELPATCH_READY else State.UNKNOWN_STATE Log.d(TAG, "state: " + _apStateLiveData.value) sharedPreferences.edit().putString(SUPER_KEY, value).apply() diff --git a/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt b/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt index 400e56a23..1d92da115 100644 --- a/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt +++ b/app/src/main/java/me/bmax/apatch/ui/MainActivity.kt @@ -15,6 +15,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -24,6 +25,7 @@ import com.google.accompanist.navigation.animation.rememberAnimatedNavController import com.ramcosta.composedestinations.DestinationsNavHost import com.ramcosta.composedestinations.navigation.popBackStack import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState +import me.bmax.apatch.APApplication import me.bmax.apatch.ui.component.rememberDialogHostState import me.bmax.apatch.ui.screen.BottomBarDestination import me.bmax.apatch.ui.screen.NavGraphs @@ -64,6 +66,14 @@ class MainActivity : AppCompatActivity() { private fun BottomBar(navController: NavHostController) { NavigationBar(tonalElevation = 8.dp) { BottomBarDestination.values().forEach { destination -> + val state by APApplication.apStateLiveData.observeAsState(APApplication.State.UNKNOWN_STATE) + val kPatchReady = !state.equals(APApplication.State.UNKNOWN_STATE) + val aPatchReady = (state.equals(APApplication.State.ANDROIDPATCH_INSTALLING) || + state.equals(APApplication.State.ANDROIDPATCH_INSTALLED) || + state.equals(APApplication.State.ANDROIDPATCH_NEED_UPDATE)) + val hideDestination = (destination.kPatchRequired && !kPatchReady) || + (destination.aPatchRequired && !aPatchReady) + if (hideDestination) return@forEach val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction) NavigationBarItem( selected = isCurrentDestOnBackStack, diff --git a/app/src/main/java/me/bmax/apatch/ui/screen/BottomBarDestination.kt b/app/src/main/java/me/bmax/apatch/ui/screen/BottomBarDestination.kt index aff4ae5fd..59c75e0ac 100644 --- a/app/src/main/java/me/bmax/apatch/ui/screen/BottomBarDestination.kt +++ b/app/src/main/java/me/bmax/apatch/ui/screen/BottomBarDestination.kt @@ -17,9 +17,11 @@ enum class BottomBarDestination( @StringRes val label: Int, val iconSelected: ImageVector, val iconNotSelected: ImageVector, + val kPatchRequired: Boolean, + val aPatchRequired: Boolean, ) { - Home(HomeScreenDestination, R.string.home, Icons.Filled.Home, Icons.Outlined.Home), - KModule(KPModuleScreenDestination, R.string.kpm, Icons.Filled.Build, Icons.Outlined.Build), - SuperUser(SuperUserScreenDestination, R.string.su_title, Icons.Filled.Security, Icons.Outlined.Security), - AModule(APModuleScreenDestination, R.string.apm, Icons.Filled.Apps, Icons.Outlined.Apps) + Home(HomeScreenDestination, R.string.home, Icons.Filled.Home, Icons.Outlined.Home, false, false), + KModule(KPModuleScreenDestination, R.string.kpm, Icons.Filled.Build, Icons.Outlined.Build, true, false), + SuperUser(SuperUserScreenDestination, R.string.su_title, Icons.Filled.Security, Icons.Outlined.Security, true, false), + AModule(APModuleScreenDestination, R.string.apm, Icons.Filled.Apps, Icons.Outlined.Apps, false, true) } From 7fae9dd9fb2281ac66be952cbf4b60b701d28070 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Thu, 11 Jan 2024 21:53:10 +0000 Subject: [PATCH 2/2] chore: add vscode tasks for clean and build --- .vscode/tasks.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..42b83755c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,27 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build (Release)", + "type": "shell", + "command": "./gradlew assembleRelease", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build (Debug)", + "type": "shell", + "command": "./gradlew assembleDebug", + "problemMatcher": [], + }, + { + "label": "Clean", + "type": "shell", + "command": "./gradlew clean", + "problemMatcher": [], + }, + ] +}