From f3e228e8a4be324220124676d9ad122a1bdcd397 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 12 Jan 2020 18:27:04 -0500 Subject: [PATCH] Indicate obsolete extensions (#2494) * Indicate obsolete extensions * Make obsolete indicators red * Move obsolete extensions up the list * Add base button theme for holder * Use red button color state instead of explicit text color --- .../tachiyomi/extension/ExtensionManager.kt | 21 ++++++++++----- .../tachiyomi/extension/model/Extension.kt | 3 ++- .../extension/ExtensionDetailsController.kt | 4 +++ .../tachiyomi/ui/extension/ExtensionHolder.kt | 26 +++++++++++++++---- .../ui/extension/ExtensionPresenter.kt | 2 +- app/src/main/res/drawable/button_bg_error.xml | 26 +++++++++++++++++++ .../layout/extension_detail_controller.xml | 18 ++++++++++++- app/src/main/res/values/strings.xml | 2 ++ 8 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/drawable/button_bg_error.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 8dfcb27a40..bfb3381fa0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -71,7 +71,7 @@ class ExtensionManager( private set(value) { field = value availableExtensionsRelay.call(value) - setUpdateFieldOfInstalledExtensions(value) + updatedInstalledExtensionsStatuses(value) } /** @@ -158,18 +158,25 @@ class ExtensionManager( * * @param availableExtensions The list of extensions given by the [api]. */ - private fun setUpdateFieldOfInstalledExtensions(availableExtensions: List) { + private fun updatedInstalledExtensionsStatuses(availableExtensions: List) { val mutInstalledExtensions = installedExtensions.toMutableList() var changed = false for ((index, installedExt) in mutInstalledExtensions.withIndex()) { val pkgName = installedExt.pkgName - val availableExt = availableExtensions.find { it.pkgName == pkgName } ?: continue + val availableExt = availableExtensions.find { it.pkgName == pkgName } - val hasUpdate = availableExt.versionCode > installedExt.versionCode - if (installedExt.hasUpdate != hasUpdate) { - mutInstalledExtensions[index] = installedExt.copy(hasUpdate = hasUpdate) - changed = true + if (availableExt == null) { + if (!installedExt.isObsolete) { + mutInstalledExtensions[index] = installedExt.copy(isObsolete = true) + changed = true + } + } else { + val hasUpdate = availableExt.versionCode > installedExt.versionCode + if (installedExt.hasUpdate != hasUpdate) { + mutInstalledExtensions[index] = installedExt.copy(hasUpdate = hasUpdate) + changed = true + } } } if (changed) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt index ef4c245684..f0a53690f5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/model/Extension.kt @@ -16,7 +16,8 @@ sealed class Extension { override val versionCode: Int, val sources: List, override val lang: String, - val hasUpdate: Boolean = false) : Extension() + val hasUpdate: Boolean = false, + val isObsolete: Boolean = false) : Extension() data class Available(override val name: String, override val pkgName: String, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index 9d020e278a..73afc46810 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -69,6 +69,10 @@ class ExtensionDetailsController(bundle: Bundle? = null) : presenter.uninstallExtension() } + if (extension.isObsolete) { + extension_obsolete.visibility = View.VISIBLE + } + val themedContext by lazy { getPreferenceThemeContext() } val manager = PreferenceManager(themedContext) manager.preferenceDataStore = EmptyPreferenceDataStore() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt index bcf6b3a131..a1425da46b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionHolder.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.extension import android.view.View +import androidx.core.content.ContextCompat +import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.extension.model.Extension @@ -52,11 +54,15 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : bindButton(item) } + @Suppress("ResourceType") fun bindButton(item: ExtensionItem) = with(ext_button) { isEnabled = true isClickable = true isActivated = false + background = VectorDrawableCompat.create(resources!!, R.drawable.button_bg_transparent, null) + setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_bg_transparent)) + val extension = item.extension val installStep = item.installStep @@ -73,11 +79,21 @@ class ExtensionHolder(view: View, override val adapter: ExtensionAdapter) : isClickable = false } } else if (extension is Extension.Installed) { - if (extension.hasUpdate) { - isActivated = true - setText(R.string.ext_update) - } else { - setText(R.string.ext_details) + when { + extension.hasUpdate -> { + isActivated = true + setText(R.string.ext_update) + } + extension.isObsolete -> { + // Red outline + background = VectorDrawableCompat.create(resources, R.drawable.button_bg_error, null) + setTextColor(ContextCompat.getColorStateList(context, R.drawable.button_bg_error)) + + setText(R.string.ext_obsolete) + } + else -> { + setText(R.string.ext_details) + } } } else if (extension is Extension.Untrusted) { setText(R.string.ext_trust) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt index fda29d66e8..97997b55f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionPresenter.kt @@ -62,7 +62,7 @@ open class ExtensionPresenter( val items = mutableListOf() - val installedSorted = installed.sortedWith(compareBy({ !it.hasUpdate }, { it.pkgName })) + val installedSorted = installed.sortedWith(compareBy({ !it.hasUpdate }, { !it.isObsolete }, { it.pkgName })) val untrustedSorted = untrusted.sortedBy { it.pkgName } val availableSorted = available // Filter out already installed extensions and disabled languages diff --git a/app/src/main/res/drawable/button_bg_error.xml b/app/src/main/res/drawable/button_bg_error.xml new file mode 100644 index 0000000000..3edb3611bb --- /dev/null +++ b/app/src/main/res/drawable/button_bg_error.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/extension_detail_controller.xml b/app/src/main/res/layout/extension_detail_controller.xml index 137b81f853..d91b5a84eb 100644 --- a/app/src/main/res/layout/extension_detail_controller.xml +++ b/app/src/main/res/layout/extension_detail_controller.xml @@ -60,6 +60,22 @@ app:layout_constraintEnd_toEndOf="parent" tools:text="eu.kanade.tachiyomi.extension.en.myext"/> + +