
This includes shadowed variables, unnecessary parameters, layouts with string literals, items that cause performance bottlenecks, and the merge of extension types into only the necessary separate classes.
72 lines
2.1 KiB
Kotlin
72 lines
2.1 KiB
Kotlin
package eu.kanade.domain.base
|
|
|
|
import android.content.Context
|
|
import eu.kanade.domain.base.BasePreferences.ExtensionInstaller
|
|
import eu.kanade.tachiyomi.util.system.hasMiuiPackageInstaller
|
|
import eu.kanade.tachiyomi.util.system.isShizukuInstalled
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import tachiyomi.core.preference.Preference
|
|
import tachiyomi.core.preference.PreferenceStore
|
|
import tachiyomi.core.preference.getEnum
|
|
|
|
class ExtensionInstallerPreference(
|
|
private val context: Context,
|
|
preferenceStore: PreferenceStore
|
|
) : Preference<ExtensionInstaller> {
|
|
|
|
private val basePref = preferenceStore.getEnum(key(), defaultValue())
|
|
|
|
override fun key() = "extension_installer"
|
|
|
|
|
|
val entries
|
|
get() = ExtensionInstaller.entries.toTypedArray().run {
|
|
if (context.hasMiuiPackageInstaller) {
|
|
filter { it != ExtensionInstaller.PACKAGEINSTALLER }
|
|
} else {
|
|
toList()
|
|
}
|
|
}
|
|
|
|
override fun defaultValue() = if (context.hasMiuiPackageInstaller) {
|
|
ExtensionInstaller.LEGACY
|
|
} else {
|
|
ExtensionInstaller.PACKAGEINSTALLER
|
|
}
|
|
|
|
private fun check(value: ExtensionInstaller): ExtensionInstaller {
|
|
when (value) {
|
|
ExtensionInstaller.PACKAGEINSTALLER -> {
|
|
if (context.hasMiuiPackageInstaller) return ExtensionInstaller.LEGACY
|
|
}
|
|
|
|
ExtensionInstaller.SHIZUKU -> {
|
|
if (!context.isShizukuInstalled) return defaultValue()
|
|
}
|
|
|
|
else -> {}
|
|
}
|
|
return value
|
|
}
|
|
|
|
override fun get(): ExtensionInstaller {
|
|
val value = basePref.get()
|
|
val checkedValue = check(value)
|
|
if (value != checkedValue) {
|
|
basePref.set(checkedValue)
|
|
}
|
|
return checkedValue
|
|
}
|
|
|
|
override fun set(value: ExtensionInstaller) {
|
|
basePref.set(check(value))
|
|
}
|
|
|
|
override fun isSet() = basePref.isSet()
|
|
|
|
override fun delete() = basePref.delete()
|
|
|
|
override fun changes() = basePref.changes()
|
|
|
|
override fun stateIn(scope: CoroutineScope) = basePref.stateIn(scope)
|
|
}
|