From 35145c3630a2dfefd426ec0eab664a3a6dc14687 Mon Sep 17 00:00:00 2001 From: n00byara Date: Mon, 13 May 2024 07:23:12 +0300 Subject: [PATCH] v4.0.0 Removed support nonroot using --- app/build.gradle.kts | 2 +- app/src/main/AndroidManifest.xml | 34 +----- .../ru/n00byara/notificationcode/Constants.kt | 2 - .../application/ApplicationsList.kt | 14 --- .../n00byara/notificationcode/clip/RegExps.kt | 2 +- .../notificationcode/permission/Permission.kt | 20 ---- .../permission/PermissionRequestActivity.kt | 22 ---- .../notificationcode/service/BootReceiver.kt | 13 -- .../service/NotificationService.kt | 59 --------- .../ui/activities/GlobalSettingsActivity.kt | 48 -------- .../ui/activities/SettingsActivity.kt | 13 -- .../ui/components/PermissionAlertDialog.kt | 93 --------------- .../ui/components/PermissionCard.kt | 45 ------- .../ui/components/Switcher.kt | 23 ++-- .../ui/components/UseCaseAlertDialog.kt | 111 ----------------- .../ui/screens/ApplicationsScreen.kt | 1 - .../ui/screens/GlobalSettingsScreen.kt | 112 ------------------ .../ui/screens/SettingsScreen.kt | 49 +------- .../GlobalSettingsActivityViewModel.kt | 46 ------- .../GlobalSettingsScreenViewModel.kt | 73 ------------ .../viewmodels/SettingsActivityViewModel.kt | 32 ++--- .../ui/viewmodels/SettingsScreenViewModel.kt | 112 +----------------- 22 files changed, 26 insertions(+), 900 deletions(-) delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt delete mode 100644 app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 28f91a0..dbf2ec8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -13,7 +13,7 @@ android { minSdk = 30 targetSdk = 34 versionCode = 1 - versionName = "3.0.7" + versionName = "4.0.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f26e0e2..b1ab7a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,10 +2,7 @@ - - + - - - - - - - - - - - - - - { - val result = mutableListOf() - - this.allInstalledApplications.forEach { applicationInfo -> - val appInfo = InstalledAppInfo(this.pm, applicationInfo) - - if (!appInfo.isSystem) { - result.add(appInfo) - } - } - - return result - } } \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt b/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt index 2418961..1993227 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt @@ -11,7 +11,7 @@ object RegExps { val regExpForCompositeCode = ".*?\n?.*?(.*(\\d{3})[-\\s](\\d{3}).*).*?\n?.*?" val regExsForPhone = listOf( - ".*?\n?.*?(\\+\\d?.\\(\\d{3}\\)?.\\d{3}[\\s|\\-]\\d{2}[\\s|\\-]\\d{2}).*?\n?.*?", + ".*?\n?.*?(\\+?\\d?.\\(\\d{3}\\)?.\\d{3}[\\s|\\-]\\d{2}[\\s|\\-]\\d{2}).*?\n?.*?", ".*?\n?.*?(\\d{2}-\\d{2}-\\d{2}).*?\n?.*?" ) diff --git a/app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt b/app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt deleted file mode 100644 index f1cfd4e..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt +++ /dev/null @@ -1,20 +0,0 @@ -package ru.n00byara.notificationcode.permission - -import android.content.Context -import android.content.Intent -import android.provider.Settings - -class Permission(private val context: Context) { - fun requestPermissions() { - val intent = Intent(this.context, PermissionRequestActivity::class.java) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - this.context.startActivity(intent) - } - - fun checkPermission(): Boolean { - val notificationListener = - arrayOf(Settings.Secure.getString(this.context.contentResolver, "enabled_notification_listeners")).joinToString() - - return notificationListener.contains(this.context.packageName) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt b/app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt deleted file mode 100644 index 120cd91..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt +++ /dev/null @@ -1,22 +0,0 @@ -package ru.n00byara.notificationcode.permission - -import android.content.Intent -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity - -/* This class is bullshit because I don't find way of start activity from view model. */ - -class PermissionRequestActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - if (savedInstanceState == null) { - requestPermissions() - } - } - - private fun requestPermissions() { - val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS") - startActivityForResult(intent, 0) - finish() - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt b/app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt deleted file mode 100644 index 9e15906..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.n00byara.notificationcode.service - -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent - -class BootReceiver : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - if (Intent.ACTION_BOOT_COMPLETED.equals(intent.action)) { - context.startService(Intent(context, NotificationService::class.java)) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt b/app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt deleted file mode 100644 index 0a3b853..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt +++ /dev/null @@ -1,59 +0,0 @@ -package ru.n00byara.notificationcode.service - -import android.service.notification.NotificationListenerService -import android.service.notification.StatusBarNotification -import com.highcapable.yukihookapi.hook.factory.prefs -import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication -import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.application.ApplicationsList -import ru.n00byara.notificationcode.clip.Clip - -class NotificationService : NotificationListenerService() { - val prefs = ModuleApplication.appContext.prefs(Constants.SETTINGS_NAME) - override fun onNotificationPosted(sbn: StatusBarNotification) { - val applicationsList = ApplicationsList(this.baseContext).getAllApplications() - val appInfo = applicationsList.find { it.packageName == sbn.packageName } - - if (this.prefs.getInt(Constants.USE_CASE) == 1) { - appInfo?.let { appInfo -> - val notification = sbn.notification - - if (appInfo.isSystem) { - notification.extras?.let { extras -> - extras.getCharSequence(Constants.EXTRA_TEXT)?.let { contentText -> - Clip( - context = this.baseContext, - contentText = contentText, - prefs = this.prefs - ) - } - } - } else { - if (appInfo.isActive) { - notification.extras?.let { extras -> - extras.getCharSequence(Constants.EXTRA_TEXT)?.let { contentText -> - if (appInfo.name == Constants.SHAZAM_APP_NAME && notification.channelId == Constants.SHAZAM_CHANNEL_ID) { - val contentTitle = extras.getCharSequence(Constants.EXTRA_TITLE) - - Clip( - context = this.baseContext, - contentText = contentText, - contentTitle = contentTitle, - prefs = this.prefs - ) - } else { - Clip(context = this.baseContext, - contentText = contentText, - prefs = this.prefs - ) - } - } - } - } else { - // Do nothing - } - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt deleted file mode 100644 index 8692426..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt +++ /dev/null @@ -1,48 +0,0 @@ -package ru.n00byara.notificationcode.ui.activities - -import android.os.Bundle -import androidx.activity.ComponentActivity -import androidx.activity.compose.setContent -import androidx.activity.viewModels -import androidx.compose.material3.Scaffold -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.lifecycle.Observer -import ru.n00byara.notificationcode.ui.components.TopBar -import ru.n00byara.notificationcode.ui.theme.NotificationCodeTheme -import ru.n00byara.notificationcode.ui.screens.GlobalSettingsScreen -import ru.n00byara.notificationcode.ui.viewmodels.GlobalSettingsActivityViewModel -import ru.n00byara.notificationcode.ui.viewmodels.GlobalSettingsScreenViewModel - -class GlobalSettingsActivity : ComponentActivity() { - val globalSettingsScreenViewModel by viewModels() - val globalSettingsActivityViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - lifecycle.addObserver(globalSettingsScreenViewModel) - - globalSettingsActivityViewModel.shouldFinishLiveData.observe( - this, - Observer { finish() } - ) - - setContent { - NotificationCodeTheme { - val topBarModel by globalSettingsActivityViewModel.topBarUiState.collectAsState() - - Scaffold( - topBar = { - TopBar(topBarModel) - } - ) { paddingValues -> - GlobalSettingsScreen( - globalSettingsScreenViewModel = globalSettingsScreenViewModel, - setTopBarTitle = globalSettingsActivityViewModel::setTopBarTitle, - paddingValues = paddingValues) - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/activities/SettingsActivity.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/activities/SettingsActivity.kt index 51f4ad4..d826f69 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/activities/SettingsActivity.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/activities/SettingsActivity.kt @@ -1,6 +1,5 @@ package ru.n00byara.notificationcode.ui.activities -import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -10,7 +9,6 @@ import androidx.compose.material3.Scaffold import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import androidx.lifecycle.Observer import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController @@ -38,17 +36,6 @@ class SettingsActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - lifecycle.addObserver(settingsScreenViewModel) - - settingsActivityViewModel.shouldFinishLiveData.observe( - this, - Observer { - val intent = Intent(this, GlobalSettingsActivity::class.java) - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - this.startActivity(intent) - } - ) - setContent { NotificationCodeTheme { val topBarModel by settingsActivityViewModel.topBarUiState.collectAsState() diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt deleted file mode 100644 index 440fabd..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt +++ /dev/null @@ -1,93 +0,0 @@ -package ru.n00byara.notificationcode.ui.components - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import ru.n00byara.notificationcode.R - -data class PermissionAlertDialogModel( - val openDialogState: MutableState, - val openSettings: () -> Unit -) - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun PermissionAlertDialog(permissionAlertDialogModel: PermissionAlertDialogModel) { - AlertDialog( - onDismissRequest = { - permissionAlertDialogModel.openDialogState.value = false - }, - ) { - Row( - modifier = Modifier - .wrapContentHeight() - .clip(RoundedCornerShape(19.dp)) - ) { - Column( - modifier = Modifier - .padding(10.dp) - ) { - Row( - modifier = Modifier.padding(start = 7.dp, end = 7.dp, top = 7.dp, bottom = 15.dp) - ) { - Text( - text = stringResource(R.string.alert_dialog_permisson_firs_launch_text), - fontSize = 20.sp - ) - } - - Row( - modifier = Modifier - .padding(start = 20.dp, end = 20.dp) - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween - ) { - Button( - colors = ButtonDefaults.buttonColors( - containerColor = Color.Transparent, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer - ), - onClick = { - permissionAlertDialogModel.openSettings() - permissionAlertDialogModel.openDialogState.value = false - } - ) { - Text( - text = stringResource(R.string.alert_dealog_permission_first_launch_ok) - ) - } - - Button( - colors = ButtonDefaults.buttonColors( - containerColor = Color.Transparent, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer - ), - onClick = { permissionAlertDialogModel.openDialogState.value = false } - ) { - Text( - text = stringResource(R.string.alert_dealog_permission_first_launch_cancel) - ) - } - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt deleted file mode 100644 index 7dd61d1..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt +++ /dev/null @@ -1,45 +0,0 @@ -package ru.n00byara.notificationcode.ui.components - -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.height -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import ru.n00byara.notificationcode.R - -data class PermissionCardModel( - val openSettings: () -> Unit -) - -@Composable -fun PermissionCard(permissionCardModel: PermissionCardModel) { - Row( - modifier = Modifier - .fillMaxWidth() - .clickable { - permissionCardModel.openSettings() - } - .padding(start = 10.dp) - ) { - Row( - modifier = Modifier - .padding(10.dp), -// .height(50.dp), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(R.string.access_notification_listener), - fontSize = 19.sp - ) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt index 46afd00..db2d6da 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt @@ -9,13 +9,13 @@ import androidx.compose.foundation.selection.toggleable import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -25,21 +25,14 @@ data class SwitcherModel( val prefName: String, val state: Boolean, val setState: (String, Boolean) -> Unit, - val useCase: MutableState, - val moduleActive: MutableState, - val premissionAccess: MutableState + val moduleActive: Boolean ) @Composable fun Switcher(switcherModel: SwitcherModel) { var chechedState by remember { mutableStateOf(switcherModel.state) } - if ( - (!switcherModel.moduleActive.value && switcherModel.useCase.value == 0) || - (!switcherModel.premissionAccess.value && switcherModel.useCase.value == 1) - ) { - chechedState = false - } + if (!switcherModel.moduleActive) chechedState = false Row( modifier = Modifier @@ -47,16 +40,13 @@ fun Switcher(switcherModel: SwitcherModel) { .toggleable( value = chechedState, onValueChange = { - if ( - (switcherModel.moduleActive.value && switcherModel.useCase.value == 0) || - (switcherModel.premissionAccess.value && switcherModel.useCase.value == 1) - ) { + if (switcherModel.moduleActive) { chechedState = it switcherModel.setState(switcherModel.prefName, it) } } ) - .padding(start = 10.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) + .padding(start = 10.dp, end = 10.dp, top = 7.dp, bottom = 7.dp) ) { Row( modifier = Modifier @@ -67,7 +57,8 @@ fun Switcher(switcherModel: SwitcherModel) { ) { Text( text = stringResource(switcherModel.title), - fontSize = 19.sp + fontSize = 19.sp, + color = Color.Unspecified ) Switch( checked = chechedState, diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt deleted file mode 100644 index af8bc24..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt +++ /dev/null @@ -1,111 +0,0 @@ -package ru.n00byara.notificationcode.ui.components - -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.RadioButton -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import ru.n00byara.notificationcode.R - -data class UseCaseAlertDialogModel( - val openDialogState: MutableState, - val setSelectItem: ((Int) -> Unit)?, - val selectedCaseIndex: Int = 0 -) - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun UseCaseAlertDialog(useCaseAlertDialogModel: UseCaseAlertDialogModel) { - AlertDialog( - onDismissRequest = { - useCaseAlertDialogModel.openDialogState.value = false - }, - ) { - 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) - ) - - Row( - modifier = Modifier - .wrapContentHeight() - .clip(RoundedCornerShape(19.dp)) - .background(MaterialTheme.colorScheme.primaryContainer) - ) { - Column { - Row( - modifier = Modifier - .padding(start = 15.dp, end = 15.dp, top = 15.dp, bottom = 7.dp) - .fillMaxWidth() - ) { - Text( - text = stringResource(R.string.alert_dialog_use_case), - fontSize = 15.sp, - fontWeight = FontWeight.Bold - ) - } - - val (selectedOption, onOptionSelected) = remember { mutableStateOf(cases[useCaseAlertDialogModel.selectedCaseIndex]) } - - cases.forEachIndexed { index, case -> - UseCaseCheckBox( - case = case, - selectedOption = selectedOption, - onOptionSelected = onOptionSelected, - setSelectItem = useCaseAlertDialogModel.setSelectItem, - index = index - ) - } - } - } - } -} - -@Composable -fun UseCaseCheckBox( - case: String, - selectedOption: String, - onOptionSelected: (String) -> Unit, - setSelectItem: ((Int) -> Unit)?, - index: Int -) { - Row( - modifier = Modifier - .fillMaxWidth() - .height(50.dp) - .clickable { - onOptionSelected(case) - setSelectItem?.invoke(index) - } - .padding(start = 20.dp, end = 20.dp, top = 10.dp, bottom = 10.dp), - verticalAlignment = Alignment.CenterVertically - ) { - RadioButton ( - selected = (case == selectedOption), - onClick = null - ) - Text( - text = case - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/ApplicationsScreen.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/ApplicationsScreen.kt index bf428a1..d0f24da 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/ApplicationsScreen.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/ApplicationsScreen.kt @@ -9,7 +9,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.lifecycle.viewmodel.compose.viewModel import ru.n00byara.notificationcode.Constants import ru.n00byara.notificationcode.R import ru.n00byara.notificationcode.ui.components.ApplicationInfoCheckBox diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt deleted file mode 100644 index d4300a1..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt +++ /dev/null @@ -1,112 +0,0 @@ -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 -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import ru.n00byara.notificationcode.R -import ru.n00byara.notificationcode.ui.components.PermissionCard -import ru.n00byara.notificationcode.ui.components.UseCaseAlertDialog -import ru.n00byara.notificationcode.ui.components.UseCaseAlertDialogModel -import ru.n00byara.notificationcode.ui.viewmodels.GlobalSettingsScreenViewModel - -@Composable -fun GlobalSettingsScreen( - globalSettingsScreenViewModel: GlobalSettingsScreenViewModel, - setTopBarTitle: (String) -> Unit, - paddingValues: PaddingValues -) { - setTopBarTitle(stringResource(R.string.screen_global_settings_title)) - - LazyColumn( - modifier = Modifier.padding(paddingValues) - ) { - item { - val useCaseDialogModel by globalSettingsScreenViewModel.useCaseDialogState.collectAsState() - UseCaseDialog(useCaseDialogModel = useCaseDialogModel) - } - - val permissionCardVisibilityUiState = globalSettingsScreenViewModel.permissionCardVisibilityUiState - - item { - AnimatedVisibility( - visible = permissionCardVisibilityUiState.value - ) { - val permissionCardModel by globalSettingsScreenViewModel.permissionCardModelUiStateFlow.collectAsState() - PermissionCard(permissionCardModel = permissionCardModel) - } - } - } -} - -data class UseCaseDialogModel( - val openDialogState: MutableState, - var useCaseTitle: Int = 0, - var setSelectItem: ((Int) -> Unit)? = null, - var selectedCaseIndex: Int = 0 -) - -@Composable -fun UseCaseDialog( - useCaseDialogModel: UseCaseDialogModel, -) { - useCaseDialogModel.openDialogState.value - - - val useCaseAlertDialogModel = UseCaseAlertDialogModel( - openDialogState = useCaseDialogModel.openDialogState, - setSelectItem = useCaseDialogModel.setSelectItem, - selectedCaseIndex = useCaseDialogModel.selectedCaseIndex - ) - - if (useCaseAlertDialogModel.openDialogState.value) { - UseCaseAlertDialog(useCaseAlertDialogModel = useCaseAlertDialogModel) - } - - Row( - modifier = Modifier - .wrapContentHeight() - .clickable { - useCaseAlertDialogModel.openDialogState.value = - !useCaseAlertDialogModel.openDialogState.value - } - .padding(10.dp) - - ) { - Column( - modifier = Modifier - .padding(10.dp) - .fillMaxWidth() - - ) { - Row { - Text( - text = stringResource(R.string.alert_dialog_use_case), - fontSize = 15.sp, - fontWeight = FontWeight.Bold - ) - } - Row { - Text( - text = stringResource(useCaseDialogModel.useCaseTitle), - fontSize = 15.sp - ) - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/SettingsScreen.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/SettingsScreen.kt index 75e797c..5cdefbe 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/SettingsScreen.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/SettingsScreen.kt @@ -1,6 +1,5 @@ package ru.n00byara.notificationcode.ui.screens -import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -17,22 +16,16 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import androidx.lifecycle.viewmodel.compose.viewModel import ru.n00byara.notificationcode.Constants import ru.n00byara.notificationcode.R -import ru.n00byara.notificationcode.ui.components.PermissionAlertDialog -import ru.n00byara.notificationcode.ui.components.PermissionCard import ru.n00byara.notificationcode.ui.components.Switcher import ru.n00byara.notificationcode.ui.components.SwitcherModel -import ru.n00byara.notificationcode.ui.components.UseCaseAlertDialog import ru.n00byara.notificationcode.ui.viewmodels.SettingsScreenViewModel import kotlin.reflect.KFunction1 @@ -43,27 +36,10 @@ fun SettingsScreen( ) { setTopBarTitle(stringResource(R.string.screen_settings_title)) - val openRootDialogState = settingsScreenViewModel.openRootDialogState - if (openRootDialogState.value) { - val useCaseAlertDialogModel by settingsScreenViewModel.useCaseAlertDialogUiState.collectAsState() - UseCaseAlertDialog(useCaseAlertDialogModel = useCaseAlertDialogModel) - } - - val openNonRootDialogState = settingsScreenViewModel.openNonRootDialogState - if (openNonRootDialogState.value) { - val permissionAlertDialogModel by settingsScreenViewModel.permissionAlertDialogState.collectAsState() - PermissionAlertDialog(permissionAlertDialogModel = permissionAlertDialogModel) - } - LazyColumn { item { - AnimatedVisibility( - visible = settingsScreenViewModel.visibilityLsposedCardState.value, - ) { - LsposedInfoCard(isActive = settingsScreenViewModel.moduleActive.value) - } + LsposedInfoCard(isActive = settingsScreenViewModel.moduleActive) } - itemsIndexed( listOf( SwitcherModel( @@ -71,52 +47,33 @@ fun SettingsScreen( prefName = Constants.SWITCH_CODE, state = settingsScreenViewModel.getBoolean(Constants.SWITCH_CODE), setState = settingsScreenViewModel::setBoolean, - useCase = settingsScreenViewModel.useCase, - moduleActive = settingsScreenViewModel.moduleActive, - premissionAccess = settingsScreenViewModel.permissionAccess + moduleActive = settingsScreenViewModel.moduleActive ), SwitcherModel( title = R.string.switcher_phone, prefName = Constants.SWITCH_PHONE, state = settingsScreenViewModel.getBoolean(Constants.SWITCH_PHONE), setState = settingsScreenViewModel::setBoolean, - useCase = settingsScreenViewModel.useCase, moduleActive = settingsScreenViewModel.moduleActive, - premissionAccess = settingsScreenViewModel.permissionAccess ), SwitcherModel( title = R.string.switcher_shazam, prefName = Constants.APPLICATION_PREF + Constants.SHAZAM_PACKAGE, state = settingsScreenViewModel.getBoolean(Constants.APPLICATION_PREF + Constants.SHAZAM_PACKAGE), setState = settingsScreenViewModel::setBoolean, - useCase = settingsScreenViewModel.useCase, moduleActive = settingsScreenViewModel.moduleActive, - premissionAccess = settingsScreenViewModel.permissionAccess ), SwitcherModel( title = R.string.switcher_track_numbers, prefName = Constants.SWITHC_TRACK_NUMBER, state = settingsScreenViewModel.getBoolean(Constants.SWITHC_TRACK_NUMBER), setState = settingsScreenViewModel::setBoolean, - useCase = settingsScreenViewModel.useCase, moduleActive = settingsScreenViewModel.moduleActive, - premissionAccess = settingsScreenViewModel.permissionAccess ) ) ) { _, item -> Switcher(switcherModel = item) } - - val permissionCardVisibilityUiState = settingsScreenViewModel.permissionCardVisibilityUiState - - item { - AnimatedVisibility( - visible = permissionCardVisibilityUiState.value - ) { - val permissionCardModel by settingsScreenViewModel.permissionCardModelUiStateFlow.collectAsState() - PermissionCard(permissionCardModel = permissionCardModel) - } - } } } @@ -125,7 +82,7 @@ fun LsposedInfoCard(isActive: Boolean) { Row( modifier = Modifier .fillMaxWidth() - .padding(15.dp) + .padding(20.dp) .height(125.dp) .clip(RoundedCornerShape(19.dp)) .background( diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt deleted file mode 100644 index 9c8881c..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt +++ /dev/null @@ -1,46 +0,0 @@ -package ru.n00byara.notificationcode.ui.viewmodels - -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.icons.filled.Refresh -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import ru.n00byara.notificationcode.terminal.Terminal -import ru.n00byara.notificationcode.ui.components.TopBarModel - -class GlobalSettingsActivityViewModel : ViewModel() { - private val _topBarUiState = MutableStateFlow(TopBarModel()) - val topBarUiState: StateFlow = this._topBarUiState.asStateFlow() - - private val _shouldFinishLiveData = MutableLiveData() - val shouldFinishLiveData: LiveData = this._shouldFinishLiveData - - fun setTopBarTitle(title: String) { - this._topBarUiState.value = TopBarModel( - title, - actions = { - IconButton(onClick = { - Terminal.restartSystemui() - }) { - Icon( - imageVector = Icons.Filled.Refresh, - contentDescription = "restart" - ) - } - }, - navigationIcon = { - IconButton(onClick = { - this._shouldFinishLiveData.postValue(true) - }) { - Icon(Icons.Filled.ArrowBack, "Back") - } - } - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt deleted file mode 100644 index 37aabac..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt +++ /dev/null @@ -1,73 +0,0 @@ -package ru.n00byara.notificationcode.ui.viewmodels - -import android.app.Application -import androidx.compose.runtime.mutableStateOf -import androidx.lifecycle.AndroidViewModel -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.R -import ru.n00byara.notificationcode.permission.Permission -import ru.n00byara.notificationcode.settings.Settings -import ru.n00byara.notificationcode.ui.components.PermissionCardModel -import ru.n00byara.notificationcode.ui.screens.UseCaseDialogModel - -class GlobalSettingsScreenViewModel(application: Application) : - AndroidViewModel(application), - LifecycleObserver -{ - private val permission = Permission(application.applicationContext) - private val settings = Settings() - private val openDialogState = mutableStateOf(false) - private val _useCaseDialogState = MutableStateFlow( - UseCaseDialogModel(this.openDialogState) - ) - val useCaseDialogState: StateFlow = this._useCaseDialogState.asStateFlow() - val permissionCardVisibilityUiState = mutableStateOf( - this.settings.getInt(Constants.USE_CASE) == 1 && !permission.checkPermission() - ) - private val _permissionCardModelUiState = MutableStateFlow( - PermissionCardModel(openSettings = this::openSettings) - ) - val permissionCardModelUiStateFlow: StateFlow = this._permissionCardModelUiState.asStateFlow() - - init { - setVariantDialogDescription() - this._useCaseDialogState.value.selectedCaseIndex = this.settings.getInt(Constants.USE_CASE) - this._useCaseDialogState.value.setSelectItem = this::setUseCase - } - - private fun setUseCase(case: Int) { - this.settings.setInt(Constants.USE_CASE, case) - this._useCaseDialogState.value.selectedCaseIndex = this.settings.getInt(Constants.USE_CASE) - this.openDialogState.value = false - setVariantDialogDescription() - when (case) { - 0 -> this.permissionCardVisibilityUiState.value = false - 1 -> this.permissionCardVisibilityUiState.value = !this.permission.checkPermission() - } - } - - // 0 == Root 1 == Non Root - private fun setVariantDialogDescription() { - if (this.settings.getInt(Constants.USE_CASE) == 0) { - this._useCaseDialogState.value.useCaseTitle = R.string.alert_dialog_use_case_root - } else { - this._useCaseDialogState.value.useCaseTitle = R.string.alert_dialog_use_case_non_root - } - } - - private fun openSettings() { - this.permission.requestPermissions() - } - - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - private fun onResume() { - this.permissionCardVisibilityUiState.value = - this.settings.getInt(Constants.USE_CASE) == 1 && !permission.checkPermission() - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsActivityViewModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsActivityViewModel.kt index 58ea6d4..ae6978a 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsActivityViewModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsActivityViewModel.kt @@ -1,47 +1,31 @@ package ru.n00byara.notificationcode.ui.viewmodels -import android.app.Application import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Settings +import androidx.compose.material.icons.filled.Refresh import androidx.compose.material3.Icon import androidx.compose.material3.IconButton -import androidx.lifecycle.AndroidViewModel -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import com.scottyab.rootbeer.RootBeer +import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import ru.n00byara.notificationcode.settings.Settings +import ru.n00byara.notificationcode.terminal.Terminal import ru.n00byara.notificationcode.ui.components.TopBarModel -class SettingsActivityViewModel(application: Application) : AndroidViewModel(application) { - private val context = application.applicationContext +class SettingsActivityViewModel : ViewModel(), LifecycleObserver { private val settings = Settings() - private val isRooted = RootBeer(this.context).isRooted private val _topBarUiState = MutableStateFlow(TopBarModel()) val topBarUiState: StateFlow = _topBarUiState.asStateFlow() - private val _shouldStartActivityLiveData = MutableLiveData() - val shouldFinishLiveData: LiveData = this._shouldStartActivityLiveData - fun updateTopBarTitle(title: String) { this._topBarUiState.value = TopBarModel( title = title, - actions = if (this.isRooted) { - { - IconButton(onClick = { - this@SettingsActivityViewModel._shouldStartActivityLiveData.postValue(true) - }) { - Icon( - imageVector = Icons.Default.Settings, - contentDescription = "Settings" - ) - } + actions = { + IconButton(onClick = { Terminal.restartSystemui() }) { + Icon(imageVector = Icons.Filled.Refresh, contentDescription = "Restart") } - } else { - null } ) } diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsScreenViewModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsScreenViewModel.kt index adb5588..ba3aa29 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsScreenViewModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/SettingsScreenViewModel.kt @@ -1,116 +1,14 @@ package ru.n00byara.notificationcode.ui.viewmodels -import android.app.Application -import androidx.compose.runtime.mutableStateOf -import androidx.lifecycle.AndroidViewModel -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.OnLifecycleEvent -import com.scottyab.rootbeer.RootBeer -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.permission.Permission +import androidx.lifecycle.ViewModel import ru.n00byara.notificationcode.settings.Settings -import ru.n00byara.notificationcode.ui.components.PermissionAlertDialogModel -import ru.n00byara.notificationcode.ui.components.PermissionCardModel -import ru.n00byara.notificationcode.ui.components.UseCaseAlertDialogModel -class SettingsScreenViewModel(private val application: Application) : - AndroidViewModel(application), - LifecycleObserver -{ - companion object { - private const val IS_FIRST_LAUNCH = "is_first_launch" - } - - private val context = this.application.applicationContext - private val settingsModel = Settings() - private var permission = Permission(this.context) +class SettingsScreenViewModel : ViewModel() { private val settings = Settings() - private val isFirstLaunch = this.settings.getBoolean(IS_FIRST_LAUNCH, true) - - val isRootedDevice = RootBeer(this.context).isRooted - val openRootDialogState = mutableStateOf(false) - val openNonRootDialogState = mutableStateOf(false) - val useCase = mutableStateOf(this.settings.getInt(Constants.USE_CASE, 1)) - val moduleActive = mutableStateOf(this.settingsModel.isActive) - val permissionAccess = mutableStateOf(this.permission.checkPermission()) - val permissionCardVisibilityUiState = mutableStateOf( - this.settings.getInt(Constants.USE_CASE) == 1 && !permission.checkPermission() - ) - - private val _useCaseAlertDialogUiState = MutableStateFlow( - UseCaseAlertDialogModel( - openDialogState = this.openRootDialogState, - setSelectItem = this::setSelectedCase, - selectedCaseIndex = 0 - ) - ) - val useCaseAlertDialogUiState: StateFlow = this._useCaseAlertDialogUiState - - private val _permissionAlertDialogState = MutableStateFlow( - PermissionAlertDialogModel( - openDialogState = this.openNonRootDialogState, - openSettings = this::openSettings - ) - ) - val permissionAlertDialogState: StateFlow = this._permissionAlertDialogState - - val visibilityLsposedCardState = mutableStateOf( - this.settings.getInt(Constants.USE_CASE, 0) == 0 && this.isRootedDevice - ) - - private val _permissionCardModelUiState = MutableStateFlow( - PermissionCardModel(openSettings = this::openSettings) - ) - val permissionCardModelUiStateFlow: StateFlow = this._permissionCardModelUiState.asStateFlow() - - init { - this.openAlertDialog() - } - - private fun openAlertDialog() { - if (!this.isFirstLaunch) return - - if (this.isRootedDevice) { - this.visibilityLsposedCardState.value = true - this.openRootDialogState.value = true - return - } - - this.settings.setInt(Constants.USE_CASE, 1) - this.openNonRootDialogState.value = true - this.useCase.value = this.settings.getInt(Constants.USE_CASE) - } - - private fun openSettings() { - this.settings.setBoolean(IS_FIRST_LAUNCH, false) - this.permission.requestPermissions() - } - - private fun setSelectedCase(case: Int) { - this.settings.setInt(Constants.USE_CASE, case) - this.settings.setBoolean(IS_FIRST_LAUNCH, false) - this.openRootDialogState.value = false - this.useCase.value = case - - if (case != 1) return - this.openNonRootDialogState.value = true - this.visibilityLsposedCardState.value = false - } - fun getBoolean(prefName: String): Boolean = this.settingsModel.getBoolean(prefName) + val moduleActive = this.settings.isActive - fun setBoolean(prefName: String, value: Boolean) = this.settingsModel.setBoolean(prefName, value) + fun getBoolean(prefName: String): Boolean = this.settings.getBoolean(prefName) - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - private fun onResume() { - this.visibilityLsposedCardState.value = - this.settings.getInt(Constants.USE_CASE) == 0 && this.isRootedDevice - this.permissionCardVisibilityUiState.value = - this.settings.getInt(Constants.USE_CASE) == 1 && !permission.checkPermission() - this.permissionAccess.value = this.permission.checkPermission() - } + fun setBoolean(prefName: String, value: Boolean) = this.settings.setBoolean(prefName, value) } \ No newline at end of file