diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..6a4cdc7 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9c775f6..4b0caa1 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.4" + versionName = "3.0.5" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 89f0994..f26e0e2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,7 @@ tools:targetApi="31" > @@ -28,7 +28,7 @@ @@ -37,7 +37,7 @@ diff --git a/app/src/main/assets/xposed_init b/app/src/main/assets/xposed_init index 9819d79..f2b6885 100644 --- a/app/src/main/assets/xposed_init +++ b/app/src/main/assets/xposed_init @@ -1 +1 @@ -ru.n00byara.notificationcode.components.hook.Hook_YukiHookXposedInit \ No newline at end of file +ru.n00byara.notificationcode.hook.Hook_YukiHookXposedInit \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/application/ApplicationsList.kt b/app/src/main/java/ru/n00byara/notificationcode/application/ApplicationsList.kt similarity index 59% rename from app/src/main/java/ru/n00byara/notificationcode/components/application/ApplicationsList.kt rename to app/src/main/java/ru/n00byara/notificationcode/application/ApplicationsList.kt index fb2a266..4891fe9 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/application/ApplicationsList.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/application/ApplicationsList.kt @@ -1,16 +1,16 @@ -package ru.n00byara.notificationcode.components.application +package ru.n00byara.notificationcode.application import android.content.Context import android.content.pm.PackageManager class ApplicationsList(private val context: Context) { - private val pm = context.packageManager - private val allInstalledApplications = pm.getInstalledApplications(PackageManager.GET_META_DATA) + private val pm = this.context.packageManager + private val allInstalledApplications = this.pm.getInstalledApplications(PackageManager.GET_META_DATA) fun getApplications(): List { - var result = mutableListOf() + val result = mutableListOf() - allInstalledApplications.forEach { applicationInfo -> + this.allInstalledApplications.forEach { applicationInfo -> val appInfo = InstalledAppInfo(this.pm, applicationInfo) if (!appInfo.isSystem && appInfo.name != "Shazam") { @@ -22,9 +22,9 @@ class ApplicationsList(private val context: Context) { } fun getAllApplications(): List { - var result = mutableListOf() + val result = mutableListOf() - allInstalledApplications.forEach { applicationInfo -> + this.allInstalledApplications.forEach { applicationInfo -> val appInfo = InstalledAppInfo(this.pm, applicationInfo) if (!appInfo.isSystem) { diff --git a/app/src/main/java/ru/n00byara/notificationcode/application/HookedAppInfo.kt b/app/src/main/java/ru/n00byara/notificationcode/application/HookedAppInfo.kt new file mode 100644 index 0000000..dcd5086 --- /dev/null +++ b/app/src/main/java/ru/n00byara/notificationcode/application/HookedAppInfo.kt @@ -0,0 +1,25 @@ +package ru.n00byara.notificationcode.application + +import android.content.Context +import android.content.pm.ApplicationInfo +import com.highcapable.yukihookapi.hook.factory.prefs +import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication +import ru.n00byara.notificationcode.Constants + +class HookedAppInfo(private val hookedContext: Context) { + val prefs = ModuleApplication().prefs(Constants.SETTINGS_NAME) + val isActive: Boolean + val isSystem: Boolean + val name: String + val packageName: String + + init { + val pm = this.hookedContext.packageManager + val applicationInfo = this.hookedContext.applicationInfo + + this.name = applicationInfo.loadLabel(pm).toString() + this.packageName = applicationInfo.packageName + this.isSystem = !((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0) + this.isActive = this.prefs.getBoolean(Constants.APPLICATION_PREF + packageName) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/application/InstalledAppInfo.kt b/app/src/main/java/ru/n00byara/notificationcode/application/InstalledAppInfo.kt new file mode 100644 index 0000000..6a9a9a3 --- /dev/null +++ b/app/src/main/java/ru/n00byara/notificationcode/application/InstalledAppInfo.kt @@ -0,0 +1,24 @@ +package ru.n00byara.notificationcode.application + +import android.content.pm.ApplicationInfo +import android.content.pm.PackageManager +import android.graphics.drawable.Drawable +import ru.n00byara.notificationcode.Constants +import ru.n00byara.notificationcode.settings.Settings + +class InstalledAppInfo(private val pm: PackageManager, private val applicationInfo: ApplicationInfo) { + val settings = Settings() + val name: String + val icon: Drawable + val isSystem: Boolean + val packageName: String + val isActive: Boolean + + init { + this.name = this.applicationInfo.loadLabel(this.pm).toString() + this.packageName = this.applicationInfo.packageName + this.isSystem = !((this.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0) + this.isActive = this.settings.getBoolean(Constants.APPLICATION_PREF + packageName) + this.icon = this.applicationInfo.loadIcon(this.pm) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/clip/Clip.kt b/app/src/main/java/ru/n00byara/notificationcode/clip/Clip.kt similarity index 89% rename from app/src/main/java/ru/n00byara/notificationcode/components/clip/Clip.kt rename to app/src/main/java/ru/n00byara/notificationcode/clip/Clip.kt index c5fb558..7779301 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/clip/Clip.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/clip/Clip.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.clip +package ru.n00byara.notificationcode.clip import android.content.ClipData import android.content.ClipboardManager @@ -25,14 +25,13 @@ class Clip( private var found = false init { - - if (contentTitle != null) { - addToClipBoard("${contentTitle} ${contentText}") + if (this.contentTitle != null) { + this.addToClipBoard("${this.contentTitle} ${this.contentText}") } else { val text = getText() text?.let { contentText -> - addToClipBoard(contentText) + this.addToClipBoard(contentText) } } } @@ -79,7 +78,7 @@ class Clip( this.matcher = pattern.matcher(this.contentText) this.found = matcher.matches() - if (this.found) return matcher.group(2) + matcher.group(3) + if (this.found) return this.matcher.group(2) + this.matcher.group(3) return null } diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/clip/RegExps.kt b/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt similarity index 91% rename from app/src/main/java/ru/n00byara/notificationcode/components/clip/RegExps.kt rename to app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt index 95a2e01..2418961 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/clip/RegExps.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/clip/RegExps.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.clip +package ru.n00byara.notificationcode.clip object RegExps { val regExps = listOf( diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/application/HookedAppInfo.kt b/app/src/main/java/ru/n00byara/notificationcode/components/application/HookedAppInfo.kt deleted file mode 100644 index 6939d2f..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/components/application/HookedAppInfo.kt +++ /dev/null @@ -1,25 +0,0 @@ -package ru.n00byara.notificationcode.components.application - -import android.content.Context -import android.content.pm.ApplicationInfo -import com.highcapable.yukihookapi.hook.factory.prefs -import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication -import ru.n00byara.notificationcode.Constants - -class HookedAppInfo(hookedContext: Context) { - val prefs = ModuleApplication().prefs(Constants.SETTINGS_NAME) - val isActive: Boolean - val isSystem: Boolean - val name: String - val packageName: String - - init { - val pm = hookedContext.packageManager - val applicationInfo = hookedContext.applicationInfo - - name = applicationInfo.loadLabel(pm).toString() - packageName = applicationInfo.packageName - isSystem = !((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0) - isActive = prefs.getBoolean(Constants.APPLICATION_PREF + packageName) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/application/InstalledAppInfo.kt b/app/src/main/java/ru/n00byara/notificationcode/components/application/InstalledAppInfo.kt deleted file mode 100644 index ac9d838..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/components/application/InstalledAppInfo.kt +++ /dev/null @@ -1,24 +0,0 @@ -package ru.n00byara.notificationcode.components.application - -import android.content.pm.ApplicationInfo -import android.content.pm.PackageManager -import android.graphics.drawable.Drawable -import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.models.SettingsModel - -class InstalledAppInfo(private val pm: PackageManager, private val applicationInfo: ApplicationInfo) { - val settingsModel = SettingsModel() - val name: String - val icon: Drawable - val isSystem: Boolean - val packageName: String - val isActive: Boolean - - init { - name = applicationInfo.loadLabel(pm).toString() - packageName = applicationInfo.packageName - isSystem = !((applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0) - isActive = settingsModel.getBoolean(Constants.APPLICATION_PREF + packageName) - icon = applicationInfo.loadIcon(pm) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/hook/Hook.kt b/app/src/main/java/ru/n00byara/notificationcode/hook/Hook.kt similarity index 78% rename from app/src/main/java/ru/n00byara/notificationcode/components/hook/Hook.kt rename to app/src/main/java/ru/n00byara/notificationcode/hook/Hook.kt index a33fdc8..d54b7d8 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/hook/Hook.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/hook/Hook.kt @@ -1,11 +1,11 @@ -package ru.n00byara.notificationcode.components.hook +package ru.n00byara.notificationcode.hook import com.highcapable.yukihookapi.YukiHookAPI.encase import com.highcapable.yukihookapi.annotation.xposed.InjectYukiHookWithXposed import com.highcapable.yukihookapi.hook.xposed.proxy.IYukiHookXposedInit import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.components.hook.entity.SystemUIHooker +import ru.n00byara.notificationcode.hook.entity.SystemUIHooker @InjectYukiHookWithXposed object Hook : IYukiHookXposedInit { diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/hook/entity/SystemUIHooker.kt b/app/src/main/java/ru/n00byara/notificationcode/hook/entity/SystemUIHooker.kt similarity index 68% rename from app/src/main/java/ru/n00byara/notificationcode/components/hook/entity/SystemUIHooker.kt rename to app/src/main/java/ru/n00byara/notificationcode/hook/entity/SystemUIHooker.kt index 37640db..0bee911 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/hook/entity/SystemUIHooker.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/hook/entity/SystemUIHooker.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.hook.entity +package ru.n00byara.notificationcode.hook.entity import android.app.Notification import android.content.Context @@ -11,8 +11,8 @@ import com.highcapable.yukihookapi.hook.type.android.Notification_BuilderClass import com.highcapable.yukihookapi.hook.type.android.ParcelClass import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.components.application.HookedAppInfo -import ru.n00byara.notificationcode.components.clip.Clip +import ru.n00byara.notificationcode.application.HookedAppInfo +import ru.n00byara.notificationcode.clip.Clip object SystemUIHooker : YukiBaseHooker() { override fun onHook() { @@ -40,7 +40,11 @@ object SystemUIHooker : YukiBaseHooker() { if (appInfo.isSystem) { notification.extras?.let { extras -> extras.getCharSequence(Constants.EXTRA_TEXT)?.let { contentText -> - Clip(appContext!!, contentText, prefs = prefs) + Clip( + context = appContext!!, + contentText = contentText, + prefs = prefs + ) } } } else { @@ -50,14 +54,23 @@ object SystemUIHooker : YukiBaseHooker() { if (appInfo.name == Constants.SHAZAM_APP_NAME && notification.getChannelId() == Constants.SHAZAM_CHANNEL_ID) { val contentTitle = extras.getCharSequence(Constants.EXTRA_TITLE) - Clip(appContext!!, contentText, contentTitle, prefs = prefs) + Clip( + context = appContext!!, + contentText = contentText, + contentTitle = contentTitle, + prefs = prefs + ) } else { - Clip(appContext!!, contentText, prefs = prefs) + Clip( + context = appContext!!, + contentText = contentText, + prefs = prefs + ) } } } } else { - // .. ?? + // Do nothing } } } diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/permission/Permission.kt b/app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt similarity index 68% rename from app/src/main/java/ru/n00byara/notificationcode/components/permission/Permission.kt rename to app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt index 1fc8000..f1cfd4e 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/permission/Permission.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/permission/Permission.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.permission +package ru.n00byara.notificationcode.permission import android.content.Context import android.content.Intent @@ -8,12 +8,12 @@ class Permission(private val context: Context) { fun requestPermissions() { val intent = Intent(this.context, PermissionRequestActivity::class.java) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(intent) + this.context.startActivity(intent) } fun checkPermission(): Boolean { val notificationListener = - arrayOf(Settings.Secure.getString(context.contentResolver, "enabled_notification_listeners")).joinToString() + arrayOf(Settings.Secure.getString(this.context.contentResolver, "enabled_notification_listeners")).joinToString() return notificationListener.contains(this.context.packageName) } diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/permission/PermissionRequestActivity.kt b/app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt similarity index 91% rename from app/src/main/java/ru/n00byara/notificationcode/components/permission/PermissionRequestActivity.kt rename to app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt index 8394ff0..120cd91 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/permission/PermissionRequestActivity.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/permission/PermissionRequestActivity.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.permission +package ru.n00byara.notificationcode.permission import android.content.Intent import android.os.Bundle diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/service/BootReceiver.kt b/app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt similarity index 87% rename from app/src/main/java/ru/n00byara/notificationcode/components/service/BootReceiver.kt rename to app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt index 79d14ce..9e15906 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/service/BootReceiver.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/service/BootReceiver.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.components.service +package ru.n00byara.notificationcode.service import android.content.BroadcastReceiver import android.content.Context diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/service/NotificationService.kt b/app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt similarity index 61% rename from app/src/main/java/ru/n00byara/notificationcode/components/service/NotificationService.kt rename to app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt index afc788f..0a3b853 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/service/NotificationService.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/service/NotificationService.kt @@ -1,12 +1,12 @@ -package ru.n00byara.notificationcode.components.service +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.components.application.ApplicationsList -import ru.n00byara.notificationcode.components.clip.Clip +import ru.n00byara.notificationcode.application.ApplicationsList +import ru.n00byara.notificationcode.clip.Clip class NotificationService : NotificationListenerService() { val prefs = ModuleApplication.appContext.prefs(Constants.SETTINGS_NAME) @@ -14,14 +14,18 @@ class NotificationService : NotificationListenerService() { val applicationsList = ApplicationsList(this.baseContext).getAllApplications() val appInfo = applicationsList.find { it.packageName == sbn.packageName } - if (prefs.getInt(Constants.USE_CASE) == 1) { + 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(this.baseContext, contentText, prefs = prefs) + Clip( + context = this.baseContext, + contentText = contentText, + prefs = this.prefs + ) } } } else { @@ -31,14 +35,22 @@ class NotificationService : NotificationListenerService() { if (appInfo.name == Constants.SHAZAM_APP_NAME && notification.channelId == Constants.SHAZAM_CHANNEL_ID) { val contentTitle = extras.getCharSequence(Constants.EXTRA_TITLE) - Clip(this.baseContext, contentText, contentTitle, prefs = prefs) + Clip( + context = this.baseContext, + contentText = contentText, + contentTitle = contentTitle, + prefs = this.prefs + ) } else { - Clip(this.baseContext, contentText, prefs = prefs) + Clip(context = this.baseContext, + contentText = contentText, + prefs = this.prefs + ) } } } } else { - // .. ?? + // Do nothing } } } diff --git a/app/src/main/java/ru/n00byara/notificationcode/models/SettingsModel.kt b/app/src/main/java/ru/n00byara/notificationcode/settings/Settings.kt similarity index 94% rename from app/src/main/java/ru/n00byara/notificationcode/models/SettingsModel.kt rename to app/src/main/java/ru/n00byara/notificationcode/settings/Settings.kt index bdcb177..c3d7787 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/models/SettingsModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/settings/Settings.kt @@ -1,11 +1,11 @@ -package ru.n00byara.notificationcode.models +package ru.n00byara.notificationcode.settings import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.hook.factory.prefs import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication import ru.n00byara.notificationcode.Constants -class SettingsModel { +class Settings { private val prefs = ModuleApplication.appContext.prefs(Constants.SETTINGS_NAME) val isActive = YukiHookAPI.Status.isXposedModuleActive diff --git a/app/src/main/java/ru/n00byara/notificationcode/components/terminal/Terminal.kt b/app/src/main/java/ru/n00byara/notificationcode/terminal/Terminal.kt similarity index 85% rename from app/src/main/java/ru/n00byara/notificationcode/components/terminal/Terminal.kt rename to app/src/main/java/ru/n00byara/notificationcode/terminal/Terminal.kt index 367b0d7..a8930b7 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/components/terminal/Terminal.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/terminal/Terminal.kt @@ -1,11 +1,11 @@ -package ru.n00byara.notificationcode.components.terminal +package ru.n00byara.notificationcode.terminal import java.io.BufferedReader import java.io.InputStreamReader object Terminal { fun restartSystemui() { - this.runCommand("killall com.android.systemui") + runCommand("killall com.android.systemui") } private fun runCommand(cmd: String): String { 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 index e1bd9ff..8692426 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/activities/GlobalSettingsActivity.kt @@ -3,26 +3,31 @@ 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.ViewModelProvider -import ru.n00byara.notificationcode.ui.components.topbar.TopBar +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.GlobalSettingsActivityViewModelFactory 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) - val globalSettingsScreenViewModel = ViewModelProvider(this).get(GlobalSettingsScreenViewModel::class.java) - val globalSettingsActivityViewModel = ViewModelProvider(this, GlobalSettingsActivityViewModelFactory(this::finish)).get(GlobalSettingsActivityViewModel::class.java) - lifecycle.addObserver(globalSettingsScreenViewModel) + globalSettingsActivityViewModel.shouldFinishLiveData.observe( + this, + Observer { finish() } + ) + setContent { NotificationCodeTheme { val topBarModel by globalSettingsActivityViewModel.topBarUiState.collectAsState() @@ -32,7 +37,10 @@ class GlobalSettingsActivity : ComponentActivity() { TopBar(topBarModel) } ) { paddingValues -> - GlobalSettingsScreen(globalSettingsScreenViewModel, globalSettingsActivityViewModel::setTopBarTitle, paddingValues) + GlobalSettingsScreen( + globalSettingsScreenViewModel = globalSettingsScreenViewModel, + setTopBarTitle = globalSettingsActivityViewModel::setTopBarTitle, + paddingValues = paddingValues) } } } 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 44bc880..51f4ad4 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,21 +1,23 @@ package ru.n00byara.notificationcode.ui.activities +import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.viewModels import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.Observer import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable 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.topbar.TopBar +import ru.n00byara.notificationcode.ui.components.BottomNavBar +import ru.n00byara.notificationcode.ui.components.BottomNavBarModel +import ru.n00byara.notificationcode.ui.components.Screen +import ru.n00byara.notificationcode.ui.components.TopBar import ru.n00byara.notificationcode.ui.screens.ApplicationsScreen import ru.n00byara.notificationcode.ui.screens.SettingsScreen import ru.n00byara.notificationcode.ui.theme.NotificationCodeTheme @@ -29,15 +31,24 @@ class SettingsActivity : ComponentActivity() { const val PREF_SCREEN_SELECTED = "selected_screen_index" } + val settingsActivityViewModel by viewModels() + val settingsScreenViewModel by viewModels() + val applicationsScreenViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val settingsActivityViewModel = ViewModelProvider(this).get(SettingsActivityViewModel::class.java) - val settingsScreenViewModel = ViewModelProvider(this).get(SettingsScreenViewModel::class.java) - val applicationsScreenViewModel = ViewModelProvider(this).get(ApplicationsScreenViewModel::class.java) - 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() @@ -60,23 +71,23 @@ class SettingsActivity : ComponentActivity() { } ) { innerPadding -> NavHost( - navController, - settingsActivityViewModel.getScreenRoute(PREF_SCREEN_ROUTE, Screen.Settings.route), - Modifier.padding(innerPadding) + navController = navController, + startDestination = settingsActivityViewModel.getScreenRoute(PREF_SCREEN_ROUTE, Screen.Settings.route), + modifier = Modifier.padding(innerPadding) ) { composable(Screen.Settings.route) { settingsActivityViewModel.setScreenRoute(PREF_SCREEN_ROUTE, Screen.Settings.route) SettingsScreen( - settingsScreenViewModel, - settingsActivityViewModel::updateTopBarTitle + settingsScreenViewModel = settingsScreenViewModel, + setTopBarTitle = settingsActivityViewModel::updateTopBarTitle ) } composable(Screen.ApplicationsList.route) { settingsActivityViewModel.setScreenRoute(PREF_SCREEN_ROUTE, Screen.ApplicationsList.route) ApplicationsScreen( - applicationsScreenViewModel, - settingsActivityViewModel::updateTopBarTitle + applicationsScreenViewModel = applicationsScreenViewModel, + setTopBarTitle = settingsActivityViewModel::updateTopBarTitle ) } } diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/ApplicationInfoSwitch.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/ApplicationInfoSwitch.kt new file mode 100644 index 0000000..a70b677 --- /dev/null +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/ApplicationInfoSwitch.kt @@ -0,0 +1,88 @@ +package ru.n00byara.notificationcode.ui.components + +import androidx.compose.foundation.Image +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.layout.size +import androidx.compose.foundation.selection.toggleable +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Switch +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +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.draw.clip +import androidx.compose.ui.unit.dp +import com.google.accompanist.drawablepainter.rememberDrawablePainter +import ru.n00byara.notificationcode.Constants +import ru.n00byara.notificationcode.application.InstalledAppInfo + +data class ApplicationInfoSwitchModel( + val appInfo: InstalledAppInfo, + val checked: Boolean, + val setState: (String, Boolean) -> Unit +) + +@Composable +fun ApplicationInfoCheckBox( + applicationInfoSwitchModel: ApplicationInfoSwitchModel +) { + var checkedState by remember { mutableStateOf(applicationInfoSwitchModel.checked) } + + Row( + modifier = Modifier + .fillMaxWidth() + .toggleable( + value = checkedState, + onValueChange = { + checkedState = it + applicationInfoSwitchModel.setState( + Constants.APPLICATION_PREF + applicationInfoSwitchModel.appInfo.packageName, + checkedState + ) + } + ) + .padding(start = 10.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) + ) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Row( + modifier = Modifier + .padding(10.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Image( + painter = rememberDrawablePainter(applicationInfoSwitchModel.appInfo.icon), + contentDescription = applicationInfoSwitchModel.appInfo.name, + modifier = Modifier + .size(40.dp) + .clip(CircleShape) + ) + Text( + text = applicationInfoSwitchModel.appInfo.name, + modifier = Modifier.padding(start = 10.dp) + ) + } + + Row( + modifier = Modifier + .padding(7.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.End + ) { + Switch( + checked = checkedState, + onCheckedChange = null + ) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBar.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/BottomNavBar.kt similarity index 85% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBar.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/BottomNavBar.kt index 75c3246..310baf5 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBar.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/BottomNavBar.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.ui.components.bottomnavigationbar +package ru.n00byara.notificationcode.ui.components import androidx.compose.material3.Icon import androidx.compose.material3.NavigationBar @@ -10,16 +10,22 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource +import androidx.navigation.NavController import androidx.navigation.NavDestination.Companion.hierarchy import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.compose.currentBackStackEntryAsState +data class BottomNavBarModel( + val navController: NavController, + val prefName: String, + val selected: Int, + val setSelected: (String, Int) -> Unit +) + @Composable fun BottomNavBar(bottomNavBarModel: BottomNavBarModel) { val items = listOf(Screen.Settings, Screen.ApplicationsList) - val selectedState by remember { - mutableStateOf(bottomNavBarModel.selected) - } + val selectedState by remember { mutableStateOf(bottomNavBarModel.selected) } NavigationBar( containerColor = Color.Transparent, diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialog.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt similarity index 93% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialog.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt index 2c8ed72..440fabd 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialog.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionAlertDialog.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.ui.components.permissionalertdialog +package ru.n00byara.notificationcode.ui.components import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -10,11 +10,11 @@ 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.Card 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 @@ -23,6 +23,11 @@ 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) { @@ -31,7 +36,7 @@ fun PermissionAlertDialog(permissionAlertDialogModel: PermissionAlertDialogModel permissionAlertDialogModel.openDialogState.value = false }, ) { - Card( + Row( modifier = Modifier .wrapContentHeight() .clip(RoundedCornerShape(19.dp)) diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCard.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt similarity index 64% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCard.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt index c9b4abb..7dd61d1 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCard.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/PermissionCard.kt @@ -1,39 +1,44 @@ -package ru.n00byara.notificationcode.ui.components.permissioncard +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.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Card import androidx.compose.material3.Text import androidx.compose.runtime.Composable +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.unit.dp import androidx.compose.ui.unit.sp import ru.n00byara.notificationcode.R +data class PermissionCardModel( + val openSettings: () -> Unit +) + @Composable fun PermissionCard(permissionCardModel: PermissionCardModel) { - Card( + Row( modifier = Modifier .fillMaxWidth() - .padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) - .clip(RoundedCornerShape(19.dp)) .clickable { permissionCardModel.openSettings() } + .padding(start = 10.dp) ) { Row( - modifier = Modifier.padding(10.dp), - horizontalArrangement = Arrangement.Center + modifier = Modifier + .padding(10.dp), +// .height(50.dp), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically ) { Text( text = stringResource(R.string.access_notification_listener), - fontSize = 15.sp + fontSize = 19.sp ) } } diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/Screen.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Screen.kt similarity index 91% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/Screen.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/Screen.kt index 751ffa7..231a507 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/Screen.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Screen.kt @@ -1,4 +1,4 @@ -package ru.n00byara.notificationcode.ui.components.bottomnavigationbar +package ru.n00byara.notificationcode.ui.components import androidx.annotation.StringRes import androidx.compose.material.icons.Icons diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/Switcher.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt similarity index 56% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/Switcher.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt index 854de2e..46afd00 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/Switcher.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/Switcher.kt @@ -1,67 +1,77 @@ -package ru.n00byara.notificationcode.ui.components.switcher +package ru.n00byara.notificationcode.ui.components import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Card +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.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +data class SwitcherModel( + val title: Int, + val prefName: String, + val state: Boolean, + val setState: (String, Boolean) -> Unit, + val useCase: MutableState, + val moduleActive: MutableState, + val premissionAccess: MutableState +) + @Composable fun Switcher(switcherModel: SwitcherModel) { - var chechedState = remember { - mutableStateOf(switcherModel.state) - } + var chechedState by remember { mutableStateOf(switcherModel.state) } if ( (!switcherModel.moduleActive.value && switcherModel.useCase.value == 0) || (!switcherModel.premissionAccess.value && switcherModel.useCase.value == 1) ) { - chechedState.value = false + chechedState = false } - Card( - Modifier + Row( + modifier = Modifier .fillMaxWidth() - .padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) - .height(50.dp) - .clip(RoundedCornerShape(19.dp)) + .toggleable( + value = chechedState, + onValueChange = { + if ( + (switcherModel.moduleActive.value && switcherModel.useCase.value == 0) || + (switcherModel.premissionAccess.value && switcherModel.useCase.value == 1) + ) { + chechedState = it + switcherModel.setState(switcherModel.prefName, it) + } + } + ) + .padding(start = 10.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) ) { Row( - Modifier + modifier = Modifier .fillMaxSize() .padding(10.dp), - Arrangement.SpaceBetween, - Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, ) { Text( - stringResource(switcherModel.title), + text = stringResource(switcherModel.title), fontSize = 19.sp ) Switch( - chechedState.value, - { - if ( - (switcherModel.moduleActive.value && switcherModel.useCase.value == 0) || - (switcherModel.premissionAccess.value && switcherModel.useCase.value == 1) - ) { - chechedState.value = it - switcherModel.setState(switcherModel.prefName, it) - } - } + checked = chechedState, + onCheckedChange = null ) } } diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBar.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/TopBar.kt similarity index 75% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBar.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/TopBar.kt index 5363c3c..5b53834 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBar.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/TopBar.kt @@ -1,15 +1,24 @@ -package ru.n00byara.notificationcode.ui.components.topbar +package ru.n00byara.notificationcode.ui.components import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.RowScope import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import com.google.accompanist.systemuicontroller.rememberSystemUiController +data class TopBarModel @OptIn(ExperimentalMaterial3Api::class) constructor( + var title: String = "", + val scrollBehavior: TopAppBarScrollBehavior? = null, + val actions: (@Composable RowScope.() -> Unit)? = null, + val navigationIcon: (@Composable ()-> Unit)? = null +) + @OptIn(ExperimentalMaterial3Api::class) @Composable fun TopBar(topBarModel: TopBarModel) { diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialog.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt similarity index 66% rename from app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialog.kt rename to app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt index 48f5e68..af8bc24 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialog.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/components/UseCaseAlertDialog.kt @@ -1,18 +1,21 @@ -package ru.n00byara.notificationcode.ui.components.usecasealertdialog +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.selection.selectableGroup import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Card 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 @@ -24,6 +27,12 @@ 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) { @@ -37,17 +46,16 @@ fun UseCaseAlertDialog(useCaseAlertDialogModel: UseCaseAlertDialogModel) { stringResource(R.string.alert_dialog_use_case_non_root) ) - Card( + Row( modifier = Modifier .wrapContentHeight() .clip(RoundedCornerShape(19.dp)) + .background(MaterialTheme.colorScheme.primaryContainer) ) { - Column( - modifier = Modifier.padding(10.dp) - ) { + Column { Row( modifier = Modifier - .padding(7.dp) + .padding(start = 15.dp, end = 15.dp, top = 15.dp, bottom = 7.dp) .fillMaxWidth() ) { Text( @@ -59,12 +67,14 @@ fun UseCaseAlertDialog(useCaseAlertDialogModel: UseCaseAlertDialogModel) { val (selectedOption, onOptionSelected) = remember { mutableStateOf(cases[useCaseAlertDialogModel.selectedCaseIndex]) } - Column( - modifier = Modifier.selectableGroup() - ) { - cases.forEachIndexed { index, case -> - UseCaseCheckBox(case, selectedOption, onOptionSelected, useCaseAlertDialogModel.setSelectItem, index) - } + cases.forEachIndexed { index, case -> + UseCaseCheckBox( + case = case, + selectedOption = selectedOption, + onOptionSelected = onOptionSelected, + setSelectItem = useCaseAlertDialogModel.setSelectItem, + index = index + ) } } } @@ -80,15 +90,19 @@ fun UseCaseCheckBox( index: Int ) { Row( - modifier = Modifier.padding(7.dp), - verticalAlignment = Alignment.CenterVertically - ) { - RadioButton ( - (case == selectedOption), - { + 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 diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBox.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBox.kt deleted file mode 100644 index 87ea4e8..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBox.kt +++ /dev/null @@ -1,85 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.applicationinfocheckbox - -import androidx.compose.foundation.Image -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.layout.size -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.CheckCircle -import androidx.compose.material.icons.outlined.CheckCircle -import androidx.compose.material3.Card -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -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.unit.dp -import com.google.accompanist.drawablepainter.rememberDrawablePainter -import ru.n00byara.notificationcode.Constants - -@Composable -fun ApplicationInfoCheckBox( - applicationInfoCheckBoxModel: ApplicationInfoCheckBoxModel -) { - val checkedState = remember { - mutableStateOf(applicationInfoCheckBoxModel.checked) - } - - Card( - modifier = Modifier - .fillMaxWidth() - .padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) - .clip(RoundedCornerShape(19.dp)) - .clickable { - checkedState.value = !checkedState.value - applicationInfoCheckBoxModel.setState( - Constants.APPLICATION_PREF + applicationInfoCheckBoxModel.appInfo.packageName, - checkedState.value - ) - } - ) { - Row( - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Row( - Modifier - .padding(10.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Image( - rememberDrawablePainter(applicationInfoCheckBoxModel.appInfo.icon), - null, - Modifier - .size(40.dp) - .clip(CircleShape) - ) - Text( - applicationInfoCheckBoxModel.appInfo.name, - Modifier.padding(start = 5.dp) - ) - } - Row( - Modifier - .padding(7.dp) - .fillMaxWidth(), - horizontalArrangement = Arrangement.End - ) { - Icon( - if (checkedState.value) Icons.Default.CheckCircle else Icons.Outlined.CheckCircle, - applicationInfoCheckBoxModel.appInfo.name, - Modifier - .size(30.dp) - ) - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBoxModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBoxModel.kt deleted file mode 100644 index 5c1b436..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/applicationinfocheckbox/ApplicationInfoCheckBoxModel.kt +++ /dev/null @@ -1,9 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.applicationinfocheckbox - -import ru.n00byara.notificationcode.components.application.InstalledAppInfo - -data class ApplicationInfoCheckBoxModel( - val appInfo: InstalledAppInfo, - val checked: Boolean, - val setState: (String, Boolean) -> Unit -) \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBarModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBarModel.kt deleted file mode 100644 index 9cd7942..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/bottomnavigationbar/BottomNavBarModel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.bottomnavigationbar - -import androidx.navigation.NavController - -data class BottomNavBarModel( - val navController: NavController, - val prefName: String, - val selected: Int, - val setSelected: (String, Int) -> Unit -) \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialogModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialogModel.kt deleted file mode 100644 index 3c726d0..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissionalertdialog/PermissionAlertDialogModel.kt +++ /dev/null @@ -1,8 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.permissionalertdialog - -import androidx.compose.runtime.MutableState - -data class PermissionAlertDialogModel( - val openDialogState: MutableState, - val openSettings: () -> Unit -) \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCardModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCardModel.kt deleted file mode 100644 index 16287ca..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/permissioncard/PermissionCardModel.kt +++ /dev/null @@ -1,5 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.permissioncard - -data class PermissionCardModel( - val openSettings: () -> Unit -) \ No newline at end of file diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/SwitcherModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/SwitcherModel.kt deleted file mode 100644 index ce30f23..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/switcher/SwitcherModel.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 useCase: MutableState, - val moduleActive: MutableState, - val premissionAccess: MutableState -) diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBarModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBarModel.kt deleted file mode 100644 index 3fa4321..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/topbar/TopBarModel.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.topbar - -import androidx.compose.foundation.layout.RowScope -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.TopAppBarScrollBehavior -import androidx.compose.runtime.Composable - -data class TopBarModel @OptIn(ExperimentalMaterial3Api::class) constructor( - var title: String = "", - val scrollBehavior: TopAppBarScrollBehavior? = null, - val actions: (@Composable RowScope.() -> Unit)? = null, - val navigationIcon: (@Composable ()-> Unit)? = null -) diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialogModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialogModel.kt deleted file mode 100644 index 255f3d9..0000000 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/components/usecasealertdialog/UseCaseAlertDialogModel.kt +++ /dev/null @@ -1,9 +0,0 @@ -package ru.n00byara.notificationcode.ui.components.usecasealertdialog - -import androidx.compose.runtime.MutableState - -data class UseCaseAlertDialogModel( - val openDialogState: MutableState, - val setSelectItem: ((Int) -> Unit)?, - val selectedCaseIndex: Int = 0 -) \ 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 58492bf..bf428a1 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 @@ -1,20 +1,25 @@ package ru.n00byara.notificationcode.ui.screens +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.material3.Divider import androidx.compose.runtime.Composable +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.ApplicationInfoCheckBox -import ru.n00byara.notificationcode.ui.components.applicationinfocheckbox.ApplicationInfoCheckBoxModel +import ru.n00byara.notificationcode.ui.components.ApplicationInfoCheckBox +import ru.n00byara.notificationcode.ui.components.ApplicationInfoSwitchModel import ru.n00byara.notificationcode.ui.viewmodels.ApplicationsScreenViewModel import kotlin.reflect.KFunction1 @Composable fun ApplicationsScreen( - applicationsScreenViewModel: ApplicationsScreenViewModel = viewModel(), + applicationsScreenViewModel: ApplicationsScreenViewModel, setTopBarTitle: KFunction1, ) { setTopBarTitle(stringResource(R.string.screen_application_title)) @@ -22,14 +27,20 @@ fun ApplicationsScreen( LazyColumn { itemsIndexed( applicationsScreenViewModel.applications - ) { _, appInfo -> - val applicationInfoCheckBoxModel = ApplicationInfoCheckBoxModel( - appInfo, - applicationsScreenViewModel.getApplicationState(Constants.APPLICATION_PREF + appInfo.packageName), - applicationsScreenViewModel::setApplicationState + ) { index, appInfo -> + val applicationInfoSwitchModel = ApplicationInfoSwitchModel( + appInfo = appInfo, + checked = applicationsScreenViewModel.getApplicationState(Constants.APPLICATION_PREF + appInfo.packageName), + setState = applicationsScreenViewModel::setApplicationState ) - ApplicationInfoCheckBox(applicationInfoCheckBoxModel) + ApplicationInfoCheckBox(applicationInfoSwitchModel = applicationInfoSwitchModel) + if (index < applicationsScreenViewModel.applications.lastIndex) { + Divider( + modifier = Modifier.padding(start = 20.dp, end = 20.dp), + color = Color.Gray + ) + } } } } \ No newline at end of file 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 index a070c33..d4300a1 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/screens/GlobalSettingsScreen.kt @@ -9,40 +9,36 @@ 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.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Card 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.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.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.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 = viewModel(), + globalSettingsScreenViewModel: GlobalSettingsScreenViewModel, setTopBarTitle: (String) -> Unit, paddingValues: PaddingValues ) { setTopBarTitle(stringResource(R.string.screen_global_settings_title)) LazyColumn( - Modifier.padding(paddingValues) + modifier = Modifier.padding(paddingValues) ) { item { val useCaseDialogModel by globalSettingsScreenViewModel.useCaseDialogState.collectAsState() - UseCaseDialog(useCaseDialogModel) + UseCaseDialog(useCaseDialogModel = useCaseDialogModel) } val permissionCardVisibilityUiState = globalSettingsScreenViewModel.permissionCardVisibilityUiState @@ -52,7 +48,7 @@ fun GlobalSettingsScreen( visible = permissionCardVisibilityUiState.value ) { val permissionCardModel by globalSettingsScreenViewModel.permissionCardModelUiStateFlow.collectAsState() - PermissionCard(permissionCardModel) + PermissionCard(permissionCardModel = permissionCardModel) } } } @@ -73,42 +69,41 @@ fun UseCaseDialog( val useCaseAlertDialogModel = UseCaseAlertDialogModel( - useCaseDialogModel.openDialogState, - useCaseDialogModel.setSelectItem, - useCaseDialogModel.selectedCaseIndex + openDialogState = useCaseDialogModel.openDialogState, + setSelectItem = useCaseDialogModel.setSelectItem, + selectedCaseIndex = useCaseDialogModel.selectedCaseIndex ) if (useCaseAlertDialogModel.openDialogState.value) { - UseCaseAlertDialog(useCaseAlertDialogModel) + UseCaseAlertDialog(useCaseAlertDialogModel = useCaseAlertDialogModel) } - Card( - Modifier - .padding(start = 15.dp, end = 15.dp, top = 7.dp, bottom = 7.dp) + Row( + modifier = Modifier .wrapContentHeight() - .clip(RoundedCornerShape(19.dp)) .clickable { useCaseAlertDialogModel.openDialogState.value = !useCaseAlertDialogModel.openDialogState.value } + .padding(10.dp) ) { Column( - Modifier + modifier = Modifier .padding(10.dp) .fillMaxWidth() ) { Row { Text( - stringResource(R.string.alert_dialog_use_case), + text = stringResource(R.string.alert_dialog_use_case), fontSize = 15.sp, fontWeight = FontWeight.Bold ) } Row { Text( - stringResource(useCaseDialogModel.useCaseTitle), + text = stringResource(useCaseDialogModel.useCaseTitle), fontSize = 15.sp ) } 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 a06a920..75e797c 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,7 @@ 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 import androidx.compose.foundation.layout.fillMaxWidth @@ -12,8 +13,6 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Info -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -29,17 +28,17 @@ 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.PermissionAlertDialog -import ru.n00byara.notificationcode.ui.components.permissioncard.PermissionCard -import ru.n00byara.notificationcode.ui.components.switcher.Switcher -import ru.n00byara.notificationcode.ui.components.switcher.SwitcherModel -import ru.n00byara.notificationcode.ui.components.usecasealertdialog.UseCaseAlertDialog +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 @Composable fun SettingsScreen( - settingsScreenViewModel: SettingsScreenViewModel = viewModel(), + settingsScreenViewModel: SettingsScreenViewModel, setTopBarTitle: KFunction1, ) { setTopBarTitle(stringResource(R.string.screen_settings_title)) @@ -47,13 +46,13 @@ fun SettingsScreen( val openRootDialogState = settingsScreenViewModel.openRootDialogState if (openRootDialogState.value) { val useCaseAlertDialogModel by settingsScreenViewModel.useCaseAlertDialogUiState.collectAsState() - UseCaseAlertDialog(useCaseAlertDialogModel) + UseCaseAlertDialog(useCaseAlertDialogModel = useCaseAlertDialogModel) } val openNonRootDialogState = settingsScreenViewModel.openNonRootDialogState if (openNonRootDialogState.value) { val permissionAlertDialogModel by settingsScreenViewModel.permissionAlertDialogState.collectAsState() - PermissionAlertDialog(permissionAlertDialogModel) + PermissionAlertDialog(permissionAlertDialogModel = permissionAlertDialogModel) } LazyColumn { @@ -61,51 +60,51 @@ fun SettingsScreen( AnimatedVisibility( visible = settingsScreenViewModel.visibilityLsposedCardState.value, ) { - LsposedInfoCard(settingsScreenViewModel.moduleActive.value) + LsposedInfoCard(isActive = settingsScreenViewModel.moduleActive.value) } } itemsIndexed( listOf( SwitcherModel( - R.string.switcher_code, - Constants.SWITCH_CODE, - settingsScreenViewModel.getBoolean(Constants.SWITCH_CODE), - settingsScreenViewModel::setBoolean, - settingsScreenViewModel.useCase, - settingsScreenViewModel.moduleActive, - settingsScreenViewModel.permissionAccess + title = R.string.switcher_code, + prefName = Constants.SWITCH_CODE, + state = settingsScreenViewModel.getBoolean(Constants.SWITCH_CODE), + setState = settingsScreenViewModel::setBoolean, + useCase = settingsScreenViewModel.useCase, + moduleActive = settingsScreenViewModel.moduleActive, + premissionAccess = settingsScreenViewModel.permissionAccess ), SwitcherModel( - R.string.switcher_phone, - Constants.SWITCH_PHONE, - settingsScreenViewModel.getBoolean(Constants.SWITCH_PHONE), - settingsScreenViewModel::setBoolean, - settingsScreenViewModel.useCase, - settingsScreenViewModel.moduleActive, - settingsScreenViewModel.permissionAccess + 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( - R.string.switcher_shazam, - Constants.APPLICATION_PREF + Constants.SHAZAM_PACKAGE, - settingsScreenViewModel.getBoolean(Constants.APPLICATION_PREF + Constants.SHAZAM_PACKAGE), - settingsScreenViewModel::setBoolean, - settingsScreenViewModel.useCase, - settingsScreenViewModel.moduleActive, - settingsScreenViewModel.permissionAccess + 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( - R.string.switcher_track_numbers, - Constants.SWITHC_TRACK_NUMBER, - settingsScreenViewModel.getBoolean(Constants.SWITHC_TRACK_NUMBER), - settingsScreenViewModel::setBoolean, - settingsScreenViewModel.useCase, - settingsScreenViewModel.moduleActive, - settingsScreenViewModel.permissionAccess + 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(item) + Switcher(switcherModel = item) } val permissionCardVisibilityUiState = settingsScreenViewModel.permissionCardVisibilityUiState @@ -115,7 +114,7 @@ fun SettingsScreen( visible = permissionCardVisibilityUiState.value ) { val permissionCardModel by settingsScreenViewModel.permissionCardModelUiStateFlow.collectAsState() - PermissionCard(permissionCardModel) + PermissionCard(permissionCardModel = permissionCardModel) } } } @@ -123,31 +122,33 @@ fun SettingsScreen( @Composable fun LsposedInfoCard(isActive: Boolean) { - Card( - Modifier + Row( + modifier = Modifier .fillMaxWidth() .padding(15.dp) .height(125.dp) - .clip(RoundedCornerShape(19.dp)), - colors = CardDefaults.cardColors( - containerColor = if (isActive) MaterialTheme.colorScheme.inverseOnSurface else MaterialTheme.colorScheme.tertiaryContainer - ) + .clip(RoundedCornerShape(19.dp)) + .background( + if (isActive) MaterialTheme.colorScheme.inverseOnSurface + else MaterialTheme.colorScheme.tertiaryContainer + ), + ) { Row( - Modifier.padding(10.dp) + modifier = Modifier.padding(10.dp) ) { Column( - Modifier.padding(top = 29.dp, bottom = 29.dp, start = 10.dp, end = 10.dp) + modifier = Modifier.padding(top = 29.dp, bottom = 29.dp, start = 10.dp, end = 10.dp) ) { Icon( - Icons.Filled.Info, - null, - Modifier.size(47.dp) + imageVector = Icons.Filled.Info, + contentDescription = null, + modifier = Modifier.size(47.dp) ) } Column( - Modifier.padding(start = 5.dp) + modifier = Modifier.padding(start = 5.dp) ) { Text( stringResource(if (isActive) R.string.module_status_active else R.string.module_status_inactive), diff --git a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/ApplicationsScreenViewModel.kt b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/ApplicationsScreenViewModel.kt index ab2d94f..8fdb064 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/ApplicationsScreenViewModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/ApplicationsScreenViewModel.kt @@ -2,20 +2,16 @@ package ru.n00byara.notificationcode.ui.viewmodels import android.app.Application import androidx.lifecycle.AndroidViewModel -import ru.n00byara.notificationcode.components.application.ApplicationsList -import ru.n00byara.notificationcode.models.SettingsModel +import ru.n00byara.notificationcode.application.ApplicationsList +import ru.n00byara.notificationcode.settings.Settings class ApplicationsScreenViewModel(application: Application) : AndroidViewModel(application) { private val context = application.applicationContext private val applicationsList = ApplicationsList(this.context) - private val settings = SettingsModel() - val applications = applicationsList.getApplications() + private val settings = Settings() + val applications = this.applicationsList.getApplications() - fun getApplicationState(prefName: String): Boolean { - return this.settings.getBoolean(prefName) - } + fun getApplicationState(prefName: String) = this.settings.getBoolean(prefName) - fun setApplicationState(prefName: String, value: Boolean) { - this.settings.setBoolean(prefName, value) - } + fun setApplicationState(prefName: String, value: Boolean) = this.settings.setBoolean(prefName, value) } \ No newline at end of file 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 index 7dcf71d..9c8881c 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsActivityViewModel.kt @@ -5,19 +5,22 @@ 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 androidx.lifecycle.ViewModelProvider import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow -import ru.n00byara.notificationcode.components.terminal.Terminal -import ru.n00byara.notificationcode.ui.components.topbar.TopBarModel -import kotlin.reflect.KFunction0 +import ru.n00byara.notificationcode.terminal.Terminal +import ru.n00byara.notificationcode.ui.components.TopBarModel -class GlobalSettingsActivityViewModel(private val finishActivity: KFunction0) : ViewModel() { +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, @@ -33,22 +36,11 @@ class GlobalSettingsActivityViewModel(private val finishActivity: KFunction0 -) : ViewModelProvider.NewInstanceFactory() { - override fun create(modelClass: Class): T { - if (modelClass.isAssignableFrom(GlobalSettingsActivityViewModel::class.java)) { - return GlobalSettingsActivityViewModel(this.finishActivity) as T - } - throw IllegalArgumentException("Unknown class name") - } } \ 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 index bac8b02..37aabac 100644 --- a/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt +++ b/app/src/main/java/ru/n00byara/notificationcode/ui/viewmodels/GlobalSettingsScreenViewModel.kt @@ -11,9 +11,9 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import ru.n00byara.notificationcode.Constants import ru.n00byara.notificationcode.R -import ru.n00byara.notificationcode.components.permission.Permission -import ru.n00byara.notificationcode.models.SettingsModel -import ru.n00byara.notificationcode.ui.components.permissioncard.PermissionCardModel +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) : @@ -21,7 +21,7 @@ class GlobalSettingsScreenViewModel(application: Application) : LifecycleObserver { private val permission = Permission(application.applicationContext) - private val settings = SettingsModel() + private val settings = Settings() private val openDialogState = mutableStateOf(false) private val _useCaseDialogState = MutableStateFlow( UseCaseDialogModel(this.openDialogState) @@ -48,8 +48,7 @@ class GlobalSettingsScreenViewModel(application: Application) : setVariantDialogDescription() when (case) { 0 -> this.permissionCardVisibilityUiState.value = false - 1 -> this.permissionCardVisibilityUiState.value = - !this.permission.checkPermission() + 1 -> this.permissionCardVisibilityUiState.value = !this.permission.checkPermission() } } 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 cac7750..58ea6d4 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,36 +1,38 @@ package ru.n00byara.notificationcode.ui.viewmodels import android.app.Application -import android.content.Intent import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Settings 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 kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow -import ru.n00byara.notificationcode.models.SettingsModel -import ru.n00byara.notificationcode.ui.activities.GlobalSettingsActivity -import ru.n00byara.notificationcode.ui.components.topbar.TopBarModel +import ru.n00byara.notificationcode.settings.Settings +import ru.n00byara.notificationcode.ui.components.TopBarModel class SettingsActivityViewModel(application: Application) : AndroidViewModel(application) { private val context = application.applicationContext - private val settings = SettingsModel() + 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 = { - val intent = Intent(this@SettingsActivityViewModel.context, GlobalSettingsActivity::class.java) - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - this@SettingsActivityViewModel.context.startActivity(intent) + this@SettingsActivityViewModel._shouldStartActivityLiveData.postValue(true) }) { Icon( imageVector = Icons.Default.Settings, @@ -44,19 +46,11 @@ class SettingsActivityViewModel(application: Application) : AndroidViewModel(app ) } - fun getScreenRoute(prefName: String, value: String = ""): String { - return this.settings.getString(prefName, value) - } + fun getScreenRoute(prefName: String, value: String = "") = this.settings.getString(prefName, value) - fun setScreenRoute(prefName: String, value: String) { - this.settings.setString(prefName, value) - } + fun setScreenRoute(prefName: String, value: String) = this.settings.setString(prefName, value) - fun getScreenSelected(prefName: String, value: Int = 0): Int { - return this.settings.getInt(prefName, value) - } + fun getScreenSelected(prefName: String, value: Int = 0) = this.settings.getInt(prefName, value) - fun setScreenSelected(prefName: String, value: Int) { - this.settings.setInt(prefName, value) - } + fun setScreenSelected(prefName: String, value: Int) = this.settings.setInt(prefName, value) } \ No newline at end of file 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 b92d464..adb5588 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 @@ -11,11 +11,11 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import ru.n00byara.notificationcode.Constants -import ru.n00byara.notificationcode.components.permission.Permission -import ru.n00byara.notificationcode.models.SettingsModel -import ru.n00byara.notificationcode.ui.components.permissionalertdialog.PermissionAlertDialogModel -import ru.n00byara.notificationcode.ui.components.permissioncard.PermissionCardModel -import ru.n00byara.notificationcode.ui.components.usecasealertdialog.UseCaseAlertDialogModel +import ru.n00byara.notificationcode.permission.Permission +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), @@ -26,21 +26,30 @@ class SettingsScreenViewModel(private val application: Application) : } private val context = this.application.applicationContext - private val settingsModel = SettingsModel() + private val settingsModel = Settings() private var permission = Permission(this.context) - private val settings = SettingsModel() + private val settings = Settings() + private val isFirstLaunch = this.settings.getBoolean(IS_FIRST_LAUNCH, true) + val isRootedDevice = RootBeer(this.context).isRooted - val isFirstLaunch = this.settings.getBoolean(IS_FIRST_LAUNCH, true) 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( - this.openRootDialogState, - this::setSelectedCase, - 0 + openDialogState = this.openRootDialogState, + setSelectItem = this::setSelectedCase, + selectedCaseIndex = 0 ) ) val useCaseAlertDialogUiState: StateFlow = this._useCaseAlertDialogUiState + private val _permissionAlertDialogState = MutableStateFlow( PermissionAlertDialogModel( openDialogState = this.openNonRootDialogState, @@ -48,15 +57,11 @@ class SettingsScreenViewModel(private val application: Application) : ) ) val permissionAlertDialogState: StateFlow = this._permissionAlertDialogState + val visibilityLsposedCardState = mutableStateOf( this.settings.getInt(Constants.USE_CASE, 0) == 0 && this.isRootedDevice ) - 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 _permissionCardModelUiState = MutableStateFlow( PermissionCardModel(openSettings = this::openSettings) ) @@ -96,13 +101,9 @@ class SettingsScreenViewModel(private val application: Application) : this.visibilityLsposedCardState.value = false } - fun getBoolean(prefName: String): Boolean { - return this.settingsModel.getBoolean(prefName) - } + fun getBoolean(prefName: String): Boolean = this.settingsModel.getBoolean(prefName) - fun setBoolean(prefName: String, value: Boolean) { - this.settingsModel.setBoolean(prefName, value) - } + fun setBoolean(prefName: String, value: Boolean) = this.settingsModel.setBoolean(prefName, value) @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) private fun onResume() { diff --git a/app/src/main/resources/META-INF/yukihookapi_init b/app/src/main/resources/META-INF/yukihookapi_init index 67aa75f..f5c3013 100644 --- a/app/src/main/resources/META-INF/yukihookapi_init +++ b/app/src/main/resources/META-INF/yukihookapi_init @@ -1 +1 @@ -ru.n00byara.notificationcode.components.hook.Hook \ No newline at end of file +ru.n00byara.notificationcode.hook.Hook \ No newline at end of file