From 248d57600c01d4a3b56c535cf0b00452c1fa37d4 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 10 Jul 2021 14:30:55 -0400 Subject: [PATCH] Add warning for MIUI users when trying to install extensions with MIUI Optimization enabled miui sucks so much --- .../ui/extension/ExtensionBottomPresenter.kt | 19 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt index a52d4a9d47..5b98e737e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomPresenter.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.extension import android.content.pm.PackageInstaller +import android.widget.Toast import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga @@ -18,7 +19,9 @@ import eu.kanade.tachiyomi.ui.migration.MangaItem import eu.kanade.tachiyomi.ui.migration.SelectionHeader import eu.kanade.tachiyomi.ui.migration.SourceItem import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.system.MiuiUtil import eu.kanade.tachiyomi.util.system.executeOnIO +import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -241,11 +244,23 @@ class ExtensionBottomPresenter( } fun installExtension(extension: Extension.Available) { - extensionManager.installExtension(extension).subscribeToInstallUpdate(extension) + if (isNotMIUIOptimized()) { + extensionManager.installExtension(extension).subscribeToInstallUpdate(extension) + } } fun updateExtension(extension: Extension.Installed) { - extensionManager.updateExtension(extension).subscribeToInstallUpdate(extension) + if (isNotMIUIOptimized()) { + extensionManager.updateExtension(extension).subscribeToInstallUpdate(extension) + } + } + + fun isNotMIUIOptimized(): Boolean { + if (MiuiUtil.isMiui() && !MiuiUtil.isMiuiOptimizationDisabled()) { + preferences.context.toast(R.string.extensions_miui_warning, Toast.LENGTH_LONG) + return false + } + return true } private fun Observable.subscribeToInstallUpdate(extension: Extension) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dfe4071c8e..09bf41f636 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -303,6 +303,7 @@ Language: %1$s 18+ Unofficial + MIUI Optimization must be disabled to install extensions. May contain NSFW (18+) content App info %1$s must be enabled first