From 448645d83ad261933dee7a32edf5fe7208d06cf1 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 24 Dec 2021 10:20:08 -0500 Subject: [PATCH] Don't recompute constant device info --- .../tachiyomi/data/preference/PreferencesHelper.kt | 2 +- .../network/interceptor/CloudflareInterceptor.kt | 2 +- .../tachiyomi/ui/setting/SettingsAdvancedController.kt | 2 +- .../tachiyomi/ui/setting/SettingsBackupController.kt | 4 ++-- .../java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt | 9 ++++++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 207e0af9a8..e8774b8baa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -326,7 +326,7 @@ class PreferencesHelper(val context: Context) { fun extensionInstaller() = flowPrefs.getEnum( Keys.extensionInstaller, - if (DeviceUtil.isMiui()) Values.ExtensionInstaller.LEGACY else Values.ExtensionInstaller.PACKAGEINSTALLER + if (DeviceUtil.isMiui) Values.ExtensionInstaller.LEGACY else Values.ExtensionInstaller.PACKAGEINSTALLER ) fun verboseLogging() = prefs.getBoolean(Keys.verboseLogging, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 58fbe042ab..a612db5939 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -41,7 +41,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { private val initWebView by lazy { // Avoid crashes on Samsung devices on Android 12 // See https://bugs.chromium.org/p/chromium/issues/detail?id=1279562 - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S && DeviceUtil.isSamsung()) { + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S && DeviceUtil.isSamsung) { return@lazy } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 23aae9207f..acc675e1d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -215,7 +215,7 @@ class SettingsAdvancedController : SettingsController() { R.string.ext_installer_shizuku, ) entryValues = PreferenceValues.ExtensionInstaller.values().map { it.name }.toTypedArray() - defaultValue = if (DeviceUtil.isMiui()) { + defaultValue = if (DeviceUtil.isMiui) { PreferenceValues.ExtensionInstaller.LEGACY } else { PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 2889580bf3..2c8ab6a7a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -62,7 +62,7 @@ class SettingsBackupController : SettingsController() { summaryRes = R.string.pref_create_backup_summ onClick { - if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { + if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) { context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) } @@ -81,7 +81,7 @@ class SettingsBackupController : SettingsController() { summaryRes = R.string.pref_restore_backup_summ onClick { - if (DeviceUtil.isMiui() && DeviceUtil.isMiuiOptimizationDisabled()) { + if (DeviceUtil.isMiui && DeviceUtil.isMiuiOptimizationDisabled()) { context.toast(R.string.restore_miui_warning, Toast.LENGTH_LONG) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 7cb7f8869b..33a132408a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -3,11 +3,12 @@ package eu.kanade.tachiyomi.util.system import android.annotation.SuppressLint import android.os.Build import logcat.LogPriority -import java.util.Locale object DeviceUtil { - fun isMiui() = getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false + val isMiui by lazy { + getSystemProperty("ro.miui.ui.version.name")?.isNotEmpty() ?: false + } @SuppressLint("PrivateApi") fun isMiuiOptimizationDisabled(): Boolean { @@ -25,7 +26,9 @@ object DeviceUtil { } } - fun isSamsung() = Build.MANUFACTURER.lowercase(Locale.ENGLISH) == "samsung" + val isSamsung by lazy { + Build.MANUFACTURER.equals("samsung", ignoreCase = true) + } @SuppressLint("PrivateApi") private fun getSystemProperty(key: String?): String? {