Skip to content

Commit

Permalink
Rename ShizukuUtils to ShizukuCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Nov 24, 2023
1 parent 6800b23 commit 71f6e4c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.sanmer.pi.app.utils
package dev.sanmer.pi.compat

import android.content.pm.PackageManager
import androidx.compose.runtime.getValue
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions app/src/main/kotlin/dev/sanmer/pi/viewmodel/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() }

Expand Down

0 comments on commit 71f6e4c

Please sign in to comment.