Extension "Update all" button (#6171)

Disabled for legacy installer
This commit is contained in:
Ivan Iskandar 2021-10-30 23:34:26 +07:00 committed by GitHub
parent 459759bfe5
commit 90b312a56e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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<ExtensionGroupHolder>() {
data class ExtensionGroupItem(
val name: String,
val size: Int,
val showSize: Boolean = false
) : AbstractHeaderItem<ExtensionGroupHolder>() {
var actionLabel: String? = null
var actionOnClick: (View.OnClickListener)? = null
/**
* Returns the layout resource of this item.

View File

@ -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)
}

View File

@ -1,16 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:textAppearance="@style/TextAppearance.Tachiyomi.SectionHeader"
tools:text="Title" />
</FrameLayout>
<Button
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:visibility="gone"
tools:text="Button"
tools:visibility="visible" />
</LinearLayout>

View File

@ -246,6 +246,7 @@
<string name="all_lang">All</string>
<string name="ext_updates_pending">Updates pending</string>
<string name="ext_update">Update</string>
<string name="ext_update_all">Update all</string>
<string name="ext_obsolete">Obsolete</string>
<string name="ext_install">Install</string>
<string name="ext_pending">Pending</string>