From 5026c48864e68bacdec3db087f391eaa35b3fec6 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 5 Jul 2021 14:57:41 -0400 Subject: [PATCH] Add "Update all" button for extension updates --- .../ui/extension/ExtensionAdapter.kt | 1 + .../ui/extension/ExtensionBottomPresenter.kt | 3 +- .../ui/extension/ExtensionBottomSheet.kt | 29 +++++++++++++++++++ .../ui/extension/ExtensionGroupHolder.kt | 9 ++++++ .../ui/extension/ExtensionGroupItem.kt | 2 +- .../color/accent_text_btn_color_selector.xml | 7 +++++ .../main/res/layout/extension_card_header.xml | 19 ++++++++++++ app/src/main/res/values/strings.xml | 1 + 8 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/color/accent_text_btn_color_selector.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt index a0d4dc24b8..2f2c77108e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionAdapter.kt @@ -24,5 +24,6 @@ class ExtensionAdapter(val listener: OnButtonClickListener) : interface OnButtonClickListener { fun onButtonClick(position: Int) fun onCancelClick(position: Int) + fun onUpdateAllClicked(position: Int) } } 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 59ff68e33d..1e69843c7e 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 @@ -176,7 +176,8 @@ class ExtensionBottomPresenter( updatesSorted.size, updatesSorted.size ), - updatesSorted.size + updatesSorted.size, + items.count { it.extension.pkgName in currentDownloads.keys } != updatesSorted.size ) items += updatesSorted.map { extension -> ExtensionItem(extension, header, currentDownloads[extension.pkgName]) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt index efd1312963..9964cac171 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt @@ -201,6 +201,20 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At presenter.cancelExtensionInstall(extension) } + override fun onUpdateAllClicked(position: Int) { + val header = (extAdapter?.getSectionHeader(position)) as? ExtensionGroupItem ?: return + val items = extAdapter?.getSectionItemPositions(header) + items?.forEach { + val extItem = (extAdapter?.getItem(it) as? ExtensionItem) ?: return + val extension = (extAdapter?.getItem(it) as? ExtensionItem)?.extension ?: return + if (extItem.installStep == null && + extension is Extension.Installed && extension.hasUpdate + ) { + presenter.updateExtension(extension) + } + } + } + override fun onItemClick(view: View?, position: Int): Boolean { when (binding.tabs.selectedTabPosition) { 0 -> { @@ -298,6 +312,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At extAdapter?.updateDataSet(extensions) } updateExtTitle() + updateExtUpdateAllButton() } fun canGoBack(): Boolean { @@ -310,6 +325,20 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At fun downloadUpdate(item: ExtensionItem) { extAdapter?.updateItem(item, item.installStep) + updateExtUpdateAllButton() + } + + fun updateExtUpdateAllButton() { + val updateHeader = + extAdapter?.headerItems?.find { it is ExtensionGroupItem && it.canUpdate != null } as? ExtensionGroupItem + ?: return + val items = extAdapter?.getSectionItemPositions(updateHeader) ?: return + updateHeader.canUpdate = items.any { + val extItem = (extAdapter?.getItem(it) as? ExtensionItem) ?: return + val extension = (extAdapter?.getItem(it) as? ExtensionItem)?.extension ?: return + extItem.installStep == null + } + extAdapter?.updateItem(updateHeader) } override fun trustSignature(signatureHash: String) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt index f6f00096f9..5da62cc8d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionGroupHolder.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.extension import android.annotation.SuppressLint import android.view.View +import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible @@ -13,8 +14,16 @@ class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter() { +data class ExtensionGroupItem(val name: String, val size: Int, var canUpdate: Boolean? = null) : AbstractHeaderItem() { /** * Returns the layout resource of this item. diff --git a/app/src/main/res/color/accent_text_btn_color_selector.xml b/app/src/main/res/color/accent_text_btn_color_selector.xml new file mode 100644 index 0000000000..3c44c75b60 --- /dev/null +++ b/app/src/main/res/color/accent_text_btn_color_selector.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/extension_card_header.xml b/app/src/main/res/layout/extension_card_header.xml index 3b5d2c1763..416b0be1ac 100644 --- a/app/src/main/res/layout/extension_card_header.xml +++ b/app/src/main/res/layout/extension_card_header.xml @@ -24,6 +24,25 @@ android:layout_marginTop="20dp" tools:text="Title"/> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a446809e68..28396c1835 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -312,6 +312,7 @@ App info %1$s must be enabled first Could not install extension + Update all %d update pending %d updates pending