Skip to content

Commit

Permalink
Global Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
n00byara committed Apr 24, 2024
1 parent 56573c1 commit 1e12d6a
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 139 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdk = 31
targetSdk = 34
versionCode = 1
versionName = "3.0.1"
versionName = "3.0.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ object Terminal {
this.runCommand("killall com.android.systemui")
}

fun restartModule() {
this.runCommand(
"killall ru.n00byara.notificationcode && am start -n ru.n00byara.notificationcode/.ui.activities.SettingsActivity"
)
}

private fun runCommand(cmd: String) {
private fun runCommand(cmd: String): String {
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", cmd))

val reader = BufferedReader(
Expand All @@ -31,5 +25,6 @@ object Terminal {
reader.close()

process.waitFor()
return output.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class GlobalSettingsActivity : ComponentActivity() {
val globalSettingsScreenViewModel = ViewModelProvider(this).get(GlobalSettingsScreenViewModel::class.java)
val globalSettingsActivityViewModel = ViewModelProvider(this, GlobalSettingsActivityViewModelFactory(this::finish)).get(GlobalSettingsActivityViewModel::class.java)

lifecycle.addObserver(globalSettingsScreenViewModel)

setContent {
NotificationCodeTheme {
val topBarModel by globalSettingsActivityViewModel.topBarUiState.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import androidx.navigation.compose.rememberNavController
import ru.n00byara.notificationcode.ui.components.bottomnavigationbar.BottomNavBar
import ru.n00byara.notificationcode.ui.components.bottomnavigationbar.BottomNavBarModel
import ru.n00byara.notificationcode.ui.components.bottomnavigationbar.Screen
import ru.n00byara.notificationcode.ui.components.permissionalertdialog.PermissionAlertDialog
import ru.n00byara.notificationcode.ui.components.topbar.TopBar
import ru.n00byara.notificationcode.ui.components.usecasealertdialog.UseCaseAlertDialog
import ru.n00byara.notificationcode.ui.screens.ApplicationsScreen
import ru.n00byara.notificationcode.ui.screens.SettingsScreen
import ru.n00byara.notificationcode.ui.theme.NotificationCodeTheme
Expand All @@ -38,21 +36,10 @@ class SettingsActivity : ComponentActivity() {
val settingsScreenViewModel = ViewModelProvider(this).get(SettingsScreenViewModel::class.java)
val applicationsScreenViewModel = ViewModelProvider(this).get(ApplicationsScreenViewModel::class.java)

lifecycle.addObserver(settingsScreenViewModel)

setContent {
NotificationCodeTheme {
val openRootDialogState = settingsActivityViewModel.openRootDialogState
if (openRootDialogState.value) {
val useCaseAlertDialogModel by settingsActivityViewModel.useCaseAlertDialogUiState.collectAsState()
UseCaseAlertDialog(useCaseAlertDialogModel)
}

val openNonRootDialogState = settingsActivityViewModel.openNonRootDialogState
if (openNonRootDialogState.value) {
val permissionAlertDialogModel by settingsActivityViewModel.permissionAlertDialogState.collectAsState()
PermissionAlertDialog(permissionAlertDialogModel)
}


val topBarModel by settingsActivityViewModel.topBarUiState.collectAsState()

val navController = rememberNavController()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.n00byara.notificationcode.ui.components.bottomnavigationbar

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand All @@ -14,16 +13,9 @@ import androidx.compose.ui.res.stringResource
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.currentBackStackEntryAsState
import com.google.accompanist.systemuicontroller.rememberSystemUiController

@Composable
fun BottomNavBar(bottomNavBarModel: BottomNavBarModel) {
val systemUiController = rememberSystemUiController()
systemUiController.setNavigationBarColor(
Color.Transparent,
darkIcons = !isSystemInDarkTheme()
)

val items = listOf(Screen.Settings, Screen.ApplicationsList)
val selectedState by remember {
mutableStateOf(bottomNavBarModel.selected)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.n00byara.notificationcode.ui.components.permissioncard

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ru.n00byara.notificationcode.R

@Composable
fun PermissionCard(permissionCardModel: PermissionCardModel) {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp)
.clip(RoundedCornerShape(19.dp))
.clickable {
permissionCardModel.openSettings()
}
) {
Row(
modifier = Modifier.padding(10.dp),
horizontalArrangement = Arrangement.Center
) {
Text(
text = stringResource(R.string.access_notification_listener),
fontSize = 15.sp
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.n00byara.notificationcode.ui.components.permissioncard

data class PermissionCardModel(
val openSettings: () -> Unit
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ fun Switcher(switcherModel: SwitcherModel) {
mutableStateOf(switcherModel.state)
}

if (!switcherModel.moduleActive && switcherModel.isRoot) chechedState.value = false
if (
(!switcherModel.moduleActive.value && switcherModel.useCase.value == 0) ||
(!switcherModel.premissionAccess.value && switcherModel.useCase.value == 1)
) {
chechedState.value = false
}

Card(
Modifier
Expand All @@ -50,7 +55,8 @@ fun Switcher(switcherModel: SwitcherModel) {
chechedState.value,
{
if (
(switcherModel.moduleActive && switcherModel.isRoot) || (!switcherModel.moduleActive && !switcherModel.isRoot)
(switcherModel.moduleActive.value && switcherModel.useCase.value == 0) ||
(switcherModel.premissionAccess.value && switcherModel.useCase.value == 1)
) {
chechedState.value = it
switcherModel.setState(switcherModel.prefName, it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ru.n00byara.notificationcode.ui.components.switcher

import androidx.compose.runtime.MutableState

data class SwitcherModel(
val title: Int,
val prefName: String,
val state: Boolean,
val setState: (String, Boolean) -> Unit,
val moduleActive: Boolean,
val isRoot: Boolean
val useCase: MutableState<Int>,
val moduleActive: MutableState<Boolean>,
val premissionAccess: MutableState<Boolean>
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TopBar(topBarModel: TopBarModel) {

// Edge to Edge
val systemUiController = rememberSystemUiController()
systemUiController.setStatusBarColor(
systemUiController.setSystemBarsColor(
Color.Transparent,
darkIcons = !isSystemInDarkTheme()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ fun UseCaseAlertDialog(useCaseAlertDialogModel: UseCaseAlertDialogModel) {
useCaseAlertDialogModel.openDialogState.value = false
},
) {
val cases = listOf(R.string.alert_dialog_use_case_root, R.string.alert_dialog_use_case_non_root)
val cases = listOf(
"${stringResource(R.string.alert_dialog_use_case_root)} ${stringResource(R.string.alert_dialog_use_case_recommended)}",
stringResource(R.string.alert_dialog_use_case_non_root)
)

Card(
modifier = Modifier
Expand Down Expand Up @@ -70,9 +73,9 @@ fun UseCaseAlertDialog(useCaseAlertDialogModel: UseCaseAlertDialogModel) {

@Composable
fun UseCaseCheckBox(
case: Int,
selectedOption: Int,
onOptionSelected: (Int) -> Unit,
case: String,
selectedOption: String,
onOptionSelected: (String) -> Unit,
setSelectItem: ((Int) -> Unit)?,
index: Int
) {
Expand All @@ -88,7 +91,7 @@ fun UseCaseCheckBox(
}
)
Text(
text = stringResource(case)
text = case
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.n00byara.notificationcode.ui.screens

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -23,6 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import ru.n00byara.notificationcode.R
import ru.n00byara.notificationcode.ui.components.permissioncard.PermissionCard
import ru.n00byara.notificationcode.ui.components.usecasealertdialog.UseCaseAlertDialog
import ru.n00byara.notificationcode.ui.components.usecasealertdialog.UseCaseAlertDialogModel
import ru.n00byara.notificationcode.ui.viewmodels.GlobalSettingsScreenViewModel
Expand All @@ -38,10 +40,19 @@ fun GlobalSettingsScreen(
LazyColumn(
Modifier.padding(paddingValues)
) {
if (globalSettingsScreenViewModel.isRoot) {
item {
val useCaseDialogModel by globalSettingsScreenViewModel.useCaseDialogState.collectAsState()
UseCaseDialog(useCaseDialogModel)
item {
val useCaseDialogModel by globalSettingsScreenViewModel.useCaseDialogState.collectAsState()
UseCaseDialog(useCaseDialogModel)
}

val permissionCardVisibilityUiState = globalSettingsScreenViewModel.permissionCardVisibilityUiState

item {
AnimatedVisibility(
visible = permissionCardVisibilityUiState.value
) {
val permissionCardModel by globalSettingsScreenViewModel.permissionCardModelUiStateFlow.collectAsState()
PermissionCard(permissionCardModel)
}
}
}
Expand Down Expand Up @@ -77,7 +88,8 @@ fun UseCaseDialog(
.wrapContentHeight()
.clip(RoundedCornerShape(19.dp))
.clickable {
useCaseAlertDialogModel.openDialogState.value = !useCaseAlertDialogModel.openDialogState.value
useCaseAlertDialogModel.openDialogState.value =
!useCaseAlertDialogModel.openDialogState.value
}

) {
Expand Down
Loading

0 comments on commit 1e12d6a

Please sign in to comment.