Skip to content

Commit 22f8dde

Browse files
author
ponces
authored
feat: hide bottom pages that need su if apd is not installed (#96)
* feat: hide bottom pages depending on the state of kpatch and apatch availability * chore: add vscode tasks for clean and build
1 parent 298c593 commit 22f8dde

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Build (Release)",
6+
"type": "shell",
7+
"command": "./gradlew assembleRelease",
8+
"problemMatcher": [],
9+
"group": {
10+
"kind": "build",
11+
"isDefault": true
12+
}
13+
},
14+
{
15+
"label": "Build (Debug)",
16+
"type": "shell",
17+
"command": "./gradlew assembleDebug",
18+
"problemMatcher": [],
19+
},
20+
{
21+
"label": "Clean",
22+
"type": "shell",
23+
"command": "./gradlew clean",
24+
"problemMatcher": [],
25+
},
26+
]
27+
}

app/src/main/java/me/bmax/apatch/APatchApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class APApplication : Application() {
155155
private set(value) {
156156
field = value
157157
val ready = Natives.nativeReady(value)
158-
_apStateLiveData.value = if(ready) State.KERNELPATCH_READY else State.UNKNOWN_STATE
158+
_apStateLiveData.value = if(ready) State.KERNELPATCH_READY else State.UNKNOWN_STATE
159159
Log.d(TAG, "state: " + _apStateLiveData.value)
160160
sharedPreferences.edit().putString(SUPER_KEY, value).apply()
161161

app/src/main/java/me/bmax/apatch/ui/MainActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.material3.Text
1515
import androidx.compose.runtime.Composable
1616
import androidx.compose.runtime.CompositionLocalProvider
1717
import androidx.compose.runtime.getValue
18+
import androidx.compose.runtime.livedata.observeAsState
1819
import androidx.compose.runtime.remember
1920
import androidx.compose.ui.Modifier
2021
import androidx.compose.ui.res.stringResource
@@ -24,6 +25,7 @@ import com.google.accompanist.navigation.animation.rememberAnimatedNavController
2425
import com.ramcosta.composedestinations.DestinationsNavHost
2526
import com.ramcosta.composedestinations.navigation.popBackStack
2627
import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState
28+
import me.bmax.apatch.APApplication
2729
import me.bmax.apatch.ui.component.rememberDialogHostState
2830
import me.bmax.apatch.ui.screen.BottomBarDestination
2931
import me.bmax.apatch.ui.screen.NavGraphs
@@ -64,6 +66,14 @@ class MainActivity : AppCompatActivity() {
6466
private fun BottomBar(navController: NavHostController) {
6567
NavigationBar(tonalElevation = 8.dp) {
6668
BottomBarDestination.values().forEach { destination ->
69+
val state by APApplication.apStateLiveData.observeAsState(APApplication.State.UNKNOWN_STATE)
70+
val kPatchReady = !state.equals(APApplication.State.UNKNOWN_STATE)
71+
val aPatchReady = (state.equals(APApplication.State.ANDROIDPATCH_INSTALLING) ||
72+
state.equals(APApplication.State.ANDROIDPATCH_INSTALLED) ||
73+
state.equals(APApplication.State.ANDROIDPATCH_NEED_UPDATE))
74+
val hideDestination = (destination.kPatchRequired && !kPatchReady) ||
75+
(destination.aPatchRequired && !aPatchReady)
76+
if (hideDestination) return@forEach
6777
val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction)
6878
NavigationBarItem(
6979
selected = isCurrentDestOnBackStack,

app/src/main/java/me/bmax/apatch/ui/screen/BottomBarDestination.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ enum class BottomBarDestination(
1717
@StringRes val label: Int,
1818
val iconSelected: ImageVector,
1919
val iconNotSelected: ImageVector,
20+
val kPatchRequired: Boolean,
21+
val aPatchRequired: Boolean,
2022
) {
21-
Home(HomeScreenDestination, R.string.home, Icons.Filled.Home, Icons.Outlined.Home),
22-
KModule(KPModuleScreenDestination, R.string.kpm, Icons.Filled.Build, Icons.Outlined.Build),
23-
SuperUser(SuperUserScreenDestination, R.string.su_title, Icons.Filled.Security, Icons.Outlined.Security),
24-
AModule(APModuleScreenDestination, R.string.apm, Icons.Filled.Apps, Icons.Outlined.Apps)
23+
Home(HomeScreenDestination, R.string.home, Icons.Filled.Home, Icons.Outlined.Home, false, false),
24+
KModule(KPModuleScreenDestination, R.string.kpm, Icons.Filled.Build, Icons.Outlined.Build, true, false),
25+
SuperUser(SuperUserScreenDestination, R.string.su_title, Icons.Filled.Security, Icons.Outlined.Security, true, false),
26+
AModule(APModuleScreenDestination, R.string.apm, Icons.Filled.Apps, Icons.Outlined.Apps, false, true)
2527
}

0 commit comments

Comments
 (0)