Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide bottom pages that need su if apd is not installed #96

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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": [],
},
]
}
2 changes: 1 addition & 1 deletion app/src/main/java/me/bmax/apatch/APatchApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/me/bmax/apatch/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}