mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 14:51:50 +01:00
Add "Update all" button for extension updates
This commit is contained in:
parent
d527547f6a
commit
5026c48864
@ -24,5 +24,6 @@ class ExtensionAdapter(val listener: OnButtonClickListener) :
|
||||
interface OnButtonClickListener {
|
||||
fun onButtonClick(position: Int)
|
||||
fun onCancelClick(position: Int)
|
||||
fun onUpdateAllClicked(position: Int)
|
||||
}
|
||||
}
|
||||
|
@ -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])
|
||||
|
@ -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) {
|
||||
|
@ -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<IFlexible<Recycl
|
||||
|
||||
private val binding = ExtensionCardHeaderBinding.bind(view)
|
||||
|
||||
init {
|
||||
binding.extButton.setOnClickListener {
|
||||
(adapter as? ExtensionAdapter)?.listener?.onUpdateAllClicked(bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
fun bind(item: ExtensionGroupItem) {
|
||||
binding.title.text = item.name
|
||||
binding.extButton.isVisible = item.canUpdate != null
|
||||
binding.extButton.isEnabled = item.canUpdate == true
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ 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) : AbstractHeaderItem<ExtensionGroupHolder>() {
|
||||
data class ExtensionGroupItem(val name: String, val size: Int, var canUpdate: Boolean? = null) : AbstractHeaderItem<ExtensionGroupHolder>() {
|
||||
|
||||
/**
|
||||
* Returns the layout resource of this item.
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:alpha="1.00" android:color="?colorAccent" android:state_checkable="true" android:state_checked="true" android:state_enabled="true"/>
|
||||
<item android:alpha="0.60" android:color="?colorOnSurface" android:state_checkable="true" android:state_checked="false" android:state_enabled="true"/>
|
||||
<item android:alpha="1.00" android:color="?colorAccent" android:state_enabled="true"/>
|
||||
<item android:alpha="0.38" android:color="?colorOnSurface"/>
|
||||
</selector>
|
@ -24,6 +24,25 @@
|
||||
android:layout_marginTop="20dp"
|
||||
tools:text="Title"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/ext_button"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/accent_text_btn_color_selector"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:layout_constraintBaseline_toBaselineOf="@id/title"
|
||||
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toEndOf="@id/title"
|
||||
app:layout_constraintTop_toTopOf="@id/title"
|
||||
app:rippleColor="@color/fullRippleColor"
|
||||
android:text="@string/update_all" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
@ -312,6 +312,7 @@
|
||||
<string name="app_info">App info</string>
|
||||
<string name="_must_be_enabled_first">%1$s must be enabled first</string>
|
||||
<string name="could_not_install_extension">Could not install extension</string>
|
||||
<string name="update_all">Update all</string>
|
||||
<plurals name="_updates_pending">
|
||||
<item quantity="one">%d update pending</item>
|
||||
<item quantity="other">%d updates pending</item>
|
||||
|
Loading…
Reference in New Issue
Block a user