diff --git a/app/src/main/java/com/zacharee1/systemuituner/activities/ReadSettingFailActivity.kt b/app/src/main/java/com/zacharee1/systemuituner/activities/ReadSettingFailActivity.kt index fa57f9668..9d449a301 100644 --- a/app/src/main/java/com/zacharee1/systemuituner/activities/ReadSettingFailActivity.kt +++ b/app/src/main/java/com/zacharee1/systemuituner/activities/ReadSettingFailActivity.kt @@ -23,6 +23,8 @@ import androidx.core.view.WindowCompat import com.zacharee1.systemuituner.R import com.zacharee1.systemuituner.data.SettingsType import com.zacharee1.systemuituner.util.launchUrl +import com.zacharee1.systemuituner.util.openShizuku +import com.zacharee1.systemuituner.util.openShizukuWebsite import com.zacharee1.systemuituner.util.shizukuServiceManager import dev.zwander.composeintroslider.IntroSlider import dev.zwander.composeintroslider.SimpleIntroPage @@ -77,16 +79,13 @@ class ReadSettingFailActivity : ComponentActivity() { if (shizukuServiceManager.isShizukuInstalled) { OutlinedButton(onClick = { - startActivity(Intent(Intent.ACTION_MAIN).apply { - addCategory(Intent.CATEGORY_LAUNCHER) - `package` = "moe.shizuku.privileged.api" - }) + openShizuku() }) { Text(text = stringResource(id = R.string.open_shizuku)) } } else { OutlinedButton(onClick = { - launchUrl("https://shizuku.rikka.app") + openShizukuWebsite() }) { Text(text = stringResource(id = R.string.download_shizuku)) } diff --git a/app/src/main/java/com/zacharee1/systemuituner/activities/WriteSettingFailActivity.kt b/app/src/main/java/com/zacharee1/systemuituner/activities/WriteSettingFailActivity.kt index 49b71792b..393b4adbd 100644 --- a/app/src/main/java/com/zacharee1/systemuituner/activities/WriteSettingFailActivity.kt +++ b/app/src/main/java/com/zacharee1/systemuituner/activities/WriteSettingFailActivity.kt @@ -23,6 +23,8 @@ import androidx.core.view.WindowCompat import com.zacharee1.systemuituner.R import com.zacharee1.systemuituner.data.SettingsType import com.zacharee1.systemuituner.util.launchUrl +import com.zacharee1.systemuituner.util.openShizuku +import com.zacharee1.systemuituner.util.openShizukuWebsite import com.zacharee1.systemuituner.util.shizukuServiceManager import dev.zwander.composeintroslider.IntroSlider import dev.zwander.composeintroslider.SimpleIntroPage @@ -80,16 +82,13 @@ class WriteSettingFailActivity : ComponentActivity() { if (shizukuServiceManager.isShizukuInstalled) { OutlinedButton(onClick = { - startActivity(Intent(Intent.ACTION_MAIN).apply { - addCategory(Intent.CATEGORY_LAUNCHER) - `package` = "moe.shizuku.privileged.api" - }) + openShizuku() }) { Text(text = stringResource(id = R.string.open_shizuku)) } } else { OutlinedButton(onClick = { - launchUrl("https://shizuku.rikka.app") + openShizukuWebsite() }) { Text(text = stringResource(id = R.string.download_shizuku)) } diff --git a/app/src/main/java/com/zacharee1/systemuituner/util/ShizukuUtils.kt b/app/src/main/java/com/zacharee1/systemuituner/util/ShizukuUtils.kt new file mode 100644 index 000000000..fdbc6a144 --- /dev/null +++ b/app/src/main/java/com/zacharee1/systemuituner/util/ShizukuUtils.kt @@ -0,0 +1,20 @@ +package com.zacharee1.systemuituner.util + +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent + +fun Context.openShizuku() { + try { + startActivity(Intent(Intent.ACTION_MAIN).apply { + addCategory(Intent.CATEGORY_LAUNCHER) + `package` = "moe.shizuku.privileged.api" + }) + } catch (e: ActivityNotFoundException) { + openShizukuWebsite() + } +} + +fun Context.openShizukuWebsite() { + launchUrl("https://shizuku.rikka.app") +}