From 90b312a56e38adb7e161178e00ab1934398f18e0 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 30 Oct 2021 23:34:26 +0700 Subject: [PATCH] Extension "Update all" button (#6171) Disabled for legacy installer --- .../browse/extension/ExtensionGroupHolder.kt | 6 +++++- .../ui/browse/extension/ExtensionGroupItem.kt | 9 ++++++++- .../ui/browse/extension/ExtensionPresenter.kt | 10 ++++++++++ .../main/res/layout/section_header_item.xml | 20 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupHolder.kt index bd56e82792..099ad8c88d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupHolder.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.annotation.SuppressLint import android.view.View +import androidx.core.view.isVisible import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.databinding.SectionHeaderItemBinding @@ -17,7 +18,10 @@ class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) : if (item.showSize) { text += " (${item.size})" } - binding.title.text = text + + binding.actionButton.isVisible = item.actionLabel != null && item.actionOnClick != null + binding.actionButton.text = item.actionLabel + binding.actionButton.setOnClickListener(if (item.actionLabel != null) item.actionOnClick else null) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupItem.kt index cb0bfa1c80..fcbea0a168 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionGroupItem.kt @@ -13,7 +13,14 @@ import eu.kanade.tachiyomi.R * @param name The header name. * @param size The number of items in the group. */ -data class ExtensionGroupItem(val name: String, val size: Int, val showSize: Boolean = false) : AbstractHeaderItem() { +data class ExtensionGroupItem( + val name: String, + val size: Int, + val showSize: Boolean = false +) : AbstractHeaderItem() { + + var actionLabel: String? = null + var actionOnClick: (View.OnClickListener)? = null /** * Returns the layout resource of this item. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt index 4c174ea6b6..2980d6f6f9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionPresenter.kt @@ -2,7 +2,9 @@ package eu.kanade.tachiyomi.ui.browse.extension import android.app.Application import android.os.Bundle +import android.view.View import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.Extension @@ -76,6 +78,14 @@ open class ExtensionPresenter( if (updatesSorted.isNotEmpty()) { val header = ExtensionGroupItem(context.getString(R.string.ext_updates_pending), updatesSorted.size, true) + if (preferences.extensionInstaller().get() != PreferenceValues.ExtensionInstaller.LEGACY) { + header.actionLabel = context.getString(R.string.ext_update_all) + header.actionOnClick = View.OnClickListener { _ -> + extensions + .filter { it.extension is Extension.Installed && it.extension.hasUpdate } + .forEach { updateExtension(it.extension as Extension.Installed) } + } + } items += updatesSorted.map { extension -> ExtensionItem(extension, header, currentDownloads[extension.pkgName] ?: InstallStep.Idle) } diff --git a/app/src/main/res/layout/section_header_item.xml b/app/src/main/res/layout/section_header_item.xml index 36d2a71ddf..5b46ea81b5 100644 --- a/app/src/main/res/layout/section_header_item.xml +++ b/app/src/main/res/layout/section_header_item.xml @@ -1,16 +1,28 @@ - + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:orientation="horizontal"> - +