From 71f6e4c41c89c9ccc62a0690e99baf0c11345e9d Mon Sep 17 00:00:00 2001 From: SanmerDev Date: Fri, 24 Nov 2023 19:40:54 +0800 Subject: [PATCH] Rename ShizukuUtils to ShizukuCompat --- .../ShizukuCompat.kt} | 4 ++-- .../sanmer/pi/ui/activity/InstallActivity.kt | 4 ++-- .../sanmer/pi/ui/screens/home/HomeScreen.kt | 4 ++-- .../screens/home/items/AuthorizedAppItem.kt | 4 ++-- .../pi/ui/screens/home/items/ExecutorItem.kt | 10 ++-------- .../pi/ui/screens/home/items/RequesterItem.kt | 19 ++----------------- .../pi/ui/screens/home/items/ShizukuItem.kt | 16 ++++++++-------- .../dev/sanmer/pi/viewmodel/HomeViewModel.kt | 4 ++-- 8 files changed, 22 insertions(+), 43 deletions(-) rename app/src/main/kotlin/dev/sanmer/pi/{app/utils/ShizukuUtils.kt => compat/ShizukuCompat.kt} (92%) diff --git a/app/src/main/kotlin/dev/sanmer/pi/app/utils/ShizukuUtils.kt b/app/src/main/kotlin/dev/sanmer/pi/compat/ShizukuCompat.kt similarity index 92% rename from app/src/main/kotlin/dev/sanmer/pi/app/utils/ShizukuUtils.kt rename to app/src/main/kotlin/dev/sanmer/pi/compat/ShizukuCompat.kt index d4769929..22dec674 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/app/utils/ShizukuUtils.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/compat/ShizukuCompat.kt @@ -1,4 +1,4 @@ -package dev.sanmer.pi.app.utils +package dev.sanmer.pi.compat import android.content.pm.PackageManager import androidx.compose.runtime.getValue @@ -6,7 +6,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import rikka.shizuku.Shizuku -object ShizukuUtils: Shizuku.OnRequestPermissionResultListener { +object ShizukuCompat: Shizuku.OnRequestPermissionResultListener { var isGranted by mutableStateOf(false) private set diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt index 95670a5d..a1754b9c 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/activity/InstallActivity.kt @@ -13,7 +13,7 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import dev.sanmer.pi.app.Const -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.compat.ActivityCompat import dev.sanmer.pi.compat.PackageManagerCompat import dev.sanmer.pi.model.IPackageInfo @@ -95,7 +95,7 @@ class InstallActivity : ComponentActivity() { } private fun initPackage(intent: Intent?) = lifecycleScope.launch { - if (!ShizukuUtils.isEnable) { + if (!ShizukuCompat.isEnable) { Timber.w("Shizuku not running") finish() return@launch diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/HomeScreen.kt index 104d709d..36141974 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/HomeScreen.kt @@ -24,7 +24,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavController import dev.sanmer.pi.R -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.ui.navigation.navigateToApps import dev.sanmer.pi.ui.screens.home.items.AuthorizedAppItem import dev.sanmer.pi.ui.screens.home.items.ExecutorItem @@ -41,7 +41,7 @@ fun HomeScreen( val authorized by viewModel.authorized.collectAsStateWithLifecycle(0) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - LaunchedEffect(key1 = ShizukuUtils.isEnable) { + LaunchedEffect(key1 = ShizukuCompat.isEnable) { viewModel.loadData() } diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/AuthorizedAppItem.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/AuthorizedAppItem.kt index 9e918002..05574507 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/AuthorizedAppItem.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/AuthorizedAppItem.kt @@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import dev.sanmer.pi.R -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.ui.component.OverviewCard @Composable @@ -16,5 +16,5 @@ fun AuthorizedAppItem( title = pluralStringResource(id = R.plurals.home_authorized_apps_count, count = count, count), desc = stringResource(id = R.string.home_view_authorized_apps), onClick = onClick, - enable = ShizukuUtils.isEnable + enable = ShizukuCompat.isEnable ) \ No newline at end of file diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ExecutorItem.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ExecutorItem.kt index e71a0ace..77d9010d 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ExecutorItem.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ExecutorItem.kt @@ -1,20 +1,14 @@ package dev.sanmer.pi.ui.screens.home.items import android.content.pm.PackageInfo -import androidx.compose.animation.Crossfade import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.unit.dp import dev.sanmer.pi.R -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.ui.component.OverviewCard import dev.sanmer.pi.ui.utils.stringResource @@ -30,7 +24,7 @@ fun ExecutorItem( ) { Surface( onClick = onClick, - enabled = ShizukuUtils.isEnable, + enabled = ShizukuCompat.isEnable, shape = RoundedCornerShape(15.dp), border = BorderStroke(1.dp, MaterialTheme.colorScheme.outline), color = MaterialTheme.colorScheme.secondaryContainer diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/RequesterItem.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/RequesterItem.kt index fce0dc08..e8f950e7 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/RequesterItem.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/RequesterItem.kt @@ -2,28 +2,13 @@ package dev.sanmer.pi.ui.screens.home.items import android.content.pm.PackageInfo import androidx.compose.foundation.BorderStroke -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.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp -import coil.compose.AsyncImage -import coil.request.ImageRequest import dev.sanmer.pi.R -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.ui.component.OverviewCard import dev.sanmer.pi.ui.utils.stringResource @@ -39,7 +24,7 @@ fun RequesterItem( ) { Surface( onClick = onClick, - enabled = ShizukuUtils.isEnable, + enabled = ShizukuCompat.isEnable, shape = RoundedCornerShape(15.dp), border = BorderStroke(1.dp, MaterialTheme.colorScheme.outline), color = MaterialTheme.colorScheme.secondaryContainer diff --git a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ShizukuItem.kt b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ShizukuItem.kt index 871c1708..28fe35b0 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ShizukuItem.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/ui/screens/home/items/ShizukuItem.kt @@ -2,26 +2,26 @@ package dev.sanmer.pi.ui.screens.home.items import androidx.compose.runtime.Composable import dev.sanmer.pi.R -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.ui.component.OverviewCard import dev.sanmer.pi.ui.utils.stringResource @Composable fun ShizukuItem() = OverviewCard( icon = when { - ShizukuUtils.isGranted -> R.drawable.circle_check + ShizukuCompat.isGranted -> R.drawable.circle_check else -> R.drawable.alert_circle }, title = when { - !ShizukuUtils.isAlive -> stringResource(id = R.string.home_shizuku_not_running) - !ShizukuUtils.atLeast12 -> stringResource(id = R.string.home_shizuku_low_version) - ShizukuUtils.isGranted -> stringResource(id = R.string.home_shizuku_access, R.string.home_shizuku_granted) + !ShizukuCompat.isAlive -> stringResource(id = R.string.home_shizuku_not_running) + !ShizukuCompat.atLeast12 -> stringResource(id = R.string.home_shizuku_low_version) + ShizukuCompat.isGranted -> stringResource(id = R.string.home_shizuku_access, R.string.home_shizuku_granted) else -> stringResource(id = R.string.home_shizuku_access, R.string.home_shizuku_not_authorized) }, desc = when { - ShizukuUtils.isGranted -> ShizukuUtils.version + ShizukuCompat.isGranted -> ShizukuCompat.version else -> null }, - onClick = { ShizukuUtils.requestPermission() }, - enable = !ShizukuUtils.isEnable + onClick = { ShizukuCompat.requestPermission() }, + enable = !ShizukuCompat.isEnable ) \ No newline at end of file diff --git a/app/src/main/kotlin/dev/sanmer/pi/viewmodel/HomeViewModel.kt b/app/src/main/kotlin/dev/sanmer/pi/viewmodel/HomeViewModel.kt index ae3433ec..1571944f 100644 --- a/app/src/main/kotlin/dev/sanmer/pi/viewmodel/HomeViewModel.kt +++ b/app/src/main/kotlin/dev/sanmer/pi/viewmodel/HomeViewModel.kt @@ -9,7 +9,7 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import dev.sanmer.pi.app.utils.ShizukuUtils +import dev.sanmer.pi.compat.ShizukuCompat import dev.sanmer.pi.compat.PackageInfoCompat.isOverlayPackage import dev.sanmer.pi.compat.PackageInfoCompat.isPreinstalled import dev.sanmer.pi.compat.PackageManagerCompat @@ -46,7 +46,7 @@ class HomeViewModel @Inject constructor( suspend fun loadData() { viewModelScope.launch { - if (!ShizukuUtils.isEnable) return@launch + if (!ShizukuCompat.isEnable) return@launch val packagesDeferred = async { getPackages() }