From 975de673f0c9214597234f4838c8146e724536b8 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 23 Feb 2020 11:36:26 -0800 Subject: [PATCH] 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 --- .../ui/library/LibraryCategoryView.kt | 6 ++++- .../tachiyomi/ui/library/LibraryController.kt | 3 +++ .../tachiyomi/ui/library/LibraryHeaderItem.kt | 23 ++++++++----------- .../layout/library_category_header_item.xml | 23 +++++-------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index 34f6ddaa82..9d46d40c78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -125,7 +125,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att }, category.name)) if (!inQueue) 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 { @@ -215,6 +218,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att adapter.setItems(mangaForCategory) swipe_refresh.isEnabled = !preferences.hideCategories().getOrDefault() + swipe_refresh.isRefreshing = LibraryUpdateService.categoryInQueue(category.id) if (adapter.mode == SelectableAdapter.Mode.MULTI) { controller.selectedMangas.forEach { manga -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 31a29295cb..7082a05160 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -122,6 +122,8 @@ open class LibraryController( */ val reorganizeRelay: PublishRelay> = PublishRelay.create() + val stopRefreshRelay: PublishRelay = PublishRelay.create() + /** * Number of manga per row in grid mode. */ @@ -292,6 +294,7 @@ open class LibraryController( override fun onUpdateManga(manga: LibraryManga) { if (manga.id != null) presenter.updateManga(manga) + else stopRefreshRelay.call(true) } override fun onDetach(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt index 72498c78eb..90195692df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderItem.kt @@ -4,14 +4,12 @@ import android.graphics.drawable.Drawable import android.os.Build import android.view.View import android.widget.ImageView -import android.widget.ProgressBar import android.widget.TextView import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.button.MaterialButton import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter 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.util.system.dpToPx 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.updateLayoutParams 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 sortText: TextView = view.findViewById(R.id.category_sort) - private val updateButton: MaterialButton = view.findViewById(R.id.update_button) - private val catProgress: ProgressBar = view.findViewById(R.id.cat_progress) + private val updateButton: ImageView = view.findViewById(R.id.update_button) private val checkboxImage: ImageView = view.findViewById(R.id.checkbox) init { @@ -91,6 +87,7 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int sortText.compoundDrawablesRelative[2]?.mutate()?.setTint( ContextCompat.getColor(contentView.context, R.color.gray_button)) } + updateButton.drawable.mutate() } fun bind(category: Category) { @@ -115,23 +112,23 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int when { adapter.mode == SelectableAdapter.Mode.MULTI -> { checkboxImage.visible() - catProgress.gone() updateButton.gone() setSelection() } category.id == -1 -> { checkboxImage.gone() - catProgress.gone() updateButton.gone() } LibraryUpdateService.categoryInQueue(category.id) -> { checkboxImage.gone() - catProgress.visible() - updateButton.gone() + updateButton.drawable.setTint(ContextCompat.getColor(itemView.context, + R.color.material_on_surface_disabled)) + updateButton.visible() } else -> { checkboxImage.gone() - catProgress.gone() + updateButton.drawable.setTint(itemView.context.getResourceColor( + R.attr.colorAccent)) updateButton.visible() } } @@ -139,10 +136,8 @@ class LibraryHeaderItem(private val categoryF: (Int) -> Category, val catId: Int private fun addCategoryToUpdate() { if (adapter.libraryListener.updateCategory(adapterPosition)) { - updateButton.gone() - launchUI { - adapter.notifyItemChanged(adapterPosition) - } + updateButton.drawable.setTint(ContextCompat.getColor(itemView.context, + R.color.material_on_surface_disabled)) } } private fun showCatSortOptions() { diff --git a/app/src/main/res/layout/library_category_header_item.xml b/app/src/main/res/layout/library_category_header_item.xml index d95c463666..93fee1204e 100644 --- a/app/src/main/res/layout/library_category_header_item.xml +++ b/app/src/main/res/layout/library_category_header_item.xml @@ -56,33 +56,22 @@ app:layout_constraintStart_toEndOf="@id/update_button" app:layout_constraintWidth_min="1dp" /> - - -