Updates to category refresh ui

Pager: swipe refresh remains visible until updates are done
Single List: using a refresh icon instead of UPDATE text button
This commit is contained in:
Jay 2020-02-23 11:36:26 -08:00
parent 97e92d0a3d
commit 975de673f0
4 changed files with 23 additions and 32 deletions

View File

@ -125,7 +125,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
}, category.name)) }, category.name))
if (!inQueue) if (!inQueue)
LibraryUpdateService.start(context, category) LibraryUpdateService.start(context, category)
swipe_refresh.isRefreshing = false
} }
} }
@ -177,6 +176,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
} }
} }
} }
subscriptions += controller.stopRefreshRelay.subscribe {
swipe_refresh?.isRefreshing = false
}
} }
override fun canDrag(): Boolean { override fun canDrag(): Boolean {
@ -215,6 +218,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
adapter.setItems(mangaForCategory) adapter.setItems(mangaForCategory)
swipe_refresh.isEnabled = !preferences.hideCategories().getOrDefault() swipe_refresh.isEnabled = !preferences.hideCategories().getOrDefault()
swipe_refresh.isRefreshing = LibraryUpdateService.categoryInQueue(category.id)
if (adapter.mode == SelectableAdapter.Mode.MULTI) { if (adapter.mode == SelectableAdapter.Mode.MULTI) {
controller.selectedMangas.forEach { manga -> controller.selectedMangas.forEach { manga ->

View File

@ -122,6 +122,8 @@ open class LibraryController(
*/ */
val reorganizeRelay: PublishRelay<Pair<Int, Int>> = PublishRelay.create() val reorganizeRelay: PublishRelay<Pair<Int, Int>> = PublishRelay.create()
val stopRefreshRelay: PublishRelay<Boolean> = PublishRelay.create()
/** /**
* Number of manga per row in grid mode. * Number of manga per row in grid mode.
*/ */
@ -292,6 +294,7 @@ open class LibraryController(
override fun onUpdateManga(manga: LibraryManga) { override fun onUpdateManga(manga: LibraryManga) {
if (manga.id != null) presenter.updateManga(manga) if (manga.id != null) presenter.updateManga(manga)
else stopRefreshRelay.call(true)
} }
override fun onDetach(view: View) { override fun onDetach(view: View) {

View File

@ -4,14 +4,12 @@ import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.button.MaterialButton
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.SelectableAdapter import eu.davidea.flexibleadapter.SelectableAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem import eu.davidea.flexibleadapter.items.AbstractHeaderItem
@ -22,7 +20,6 @@ import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.library.LibraryUpdateService
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
@ -79,8 +76,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int
private val sectionText: TextView = view.findViewById(R.id.category_title) private val sectionText: TextView = view.findViewById(R.id.category_title)
private val sortText: TextView = view.findViewById(R.id.category_sort) private val sortText: TextView = view.findViewById(R.id.category_sort)
private val updateButton: MaterialButton = view.findViewById(R.id.update_button) private val updateButton: ImageView = view.findViewById(R.id.update_button)
private val catProgress: ProgressBar = view.findViewById(R.id.cat_progress)
private val checkboxImage: ImageView = view.findViewById(R.id.checkbox) private val checkboxImage: ImageView = view.findViewById(R.id.checkbox)
init { init {
@ -91,6 +87,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int
sortText.compoundDrawablesRelative[2]?.mutate()?.setTint( sortText.compoundDrawablesRelative[2]?.mutate()?.setTint(
ContextCompat.getColor(contentView.context, R.color.gray_button)) ContextCompat.getColor(contentView.context, R.color.gray_button))
} }
updateButton.drawable.mutate()
} }
fun bind(category: Category) { fun bind(category: Category) {
@ -115,23 +112,23 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int
when { when {
adapter.mode == SelectableAdapter.Mode.MULTI -> { adapter.mode == SelectableAdapter.Mode.MULTI -> {
checkboxImage.visible() checkboxImage.visible()
catProgress.gone()
updateButton.gone() updateButton.gone()
setSelection() setSelection()
} }
category.id == -1 -> { category.id == -1 -> {
checkboxImage.gone() checkboxImage.gone()
catProgress.gone()
updateButton.gone() updateButton.gone()
} }
LibraryUpdateService.categoryInQueue(category.id) -> { LibraryUpdateService.categoryInQueue(category.id) -> {
checkboxImage.gone() checkboxImage.gone()
catProgress.visible() updateButton.drawable.setTint(ContextCompat.getColor(itemView.context,
updateButton.gone() R.color.material_on_surface_disabled))
updateButton.visible()
} }
else -> { else -> {
checkboxImage.gone() checkboxImage.gone()
catProgress.gone() updateButton.drawable.setTint(itemView.context.getResourceColor(
R.attr.colorAccent))
updateButton.visible() updateButton.visible()
} }
} }
@ -139,10 +136,8 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int
private fun addCategoryToUpdate() { private fun addCategoryToUpdate() {
if (adapter.libraryListener.updateCategory(adapterPosition)) { if (adapter.libraryListener.updateCategory(adapterPosition)) {
updateButton.gone() updateButton.drawable.setTint(ContextCompat.getColor(itemView.context,
launchUI { R.color.material_on_surface_disabled))
adapter.notifyItemChanged(adapterPosition)
}
} }
} }
private fun showCatSortOptions() { private fun showCatSortOptions() {

View File

@ -56,33 +56,22 @@
app:layout_constraintStart_toEndOf="@id/update_button" app:layout_constraintStart_toEndOf="@id/update_button"
app:layout_constraintWidth_min="1dp" /> app:layout_constraintWidth_min="1dp" />
<com.google.android.material.button.MaterialButton <ImageView
android:id="@+id/update_button" android:id="@+id/update_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="35dp" android:layout_height="35dp"
android:padding="5dp"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:text="@string/ext_update" android:layout_marginBottom="6dp"
android:textColor="?android:attr/colorAccent" tools:tint="?attr/colorAccent"
app:layout_constraintBaseline_toBaselineOf="@id/category_title" android:src="@drawable/ic_refresh_white_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/space" app:layout_constraintEnd_toStartOf="@id/space"
app:layout_constraintStart_toEndOf="@+id/category_title" app:layout_constraintStart_toEndOf="@+id/category_title"
app:layout_constraintWidth_default="wrap" app:layout_constraintWidth_default="wrap"
app:rippleColor="@color/fullRippleColor" /> app:rippleColor="@color/fullRippleColor" />
<ProgressBar
android:id="@+id/cat_progress"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="@+id/category_title"
app:layout_constraintEnd_toStartOf="@+id/category_sort"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/category_title"
app:layout_constraintTop_toTopOf="@+id/category_title" />
<TextView <TextView
android:id="@+id/category_sort" android:id="@+id/category_sort"
android:layout_width="wrap_content" android:layout_width="wrap_content"