mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Library refresh state didn't update right away
This commit is contained in:
parent
a5a5ce8797
commit
233758b219
2 changed files with 51 additions and 41 deletions
|
@ -128,7 +128,14 @@ import eu.kanade.tachiyomi.util.view.snack
|
|||
import eu.kanade.tachiyomi.util.view.text
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.widget.EmptyView
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextInt
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
@ -138,12 +145,6 @@ import uy.kohesive.injekt.api.get
|
|||
import yokai.domain.ui.UiPreferences
|
||||
import yokai.i18n.MR
|
||||
import yokai.util.lang.getString
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextInt
|
||||
import android.R as AR
|
||||
|
||||
open class LibraryController(
|
||||
|
@ -610,6 +611,13 @@ open class LibraryController(
|
|||
setUpHopper()
|
||||
setPreferenceFlows()
|
||||
LibraryUpdateJob.updateFlow.onEach(::onUpdateManga).launchIn(viewScope)
|
||||
viewScope.launchUI {
|
||||
LibraryUpdateJob.isRunningFlow(view.context).collectLatest {
|
||||
val holder = if (mAdapter != null) visibleHeaderHolder() else null
|
||||
val category = holder?.category ?: return@collectLatest
|
||||
holder.notifyStatus(LibraryUpdateJob.categoryInQueue(category.id), category)
|
||||
}
|
||||
}
|
||||
|
||||
elevateAppBar =
|
||||
scrollViewWith(
|
||||
|
|
|
@ -47,6 +47,8 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
|||
private val refreshDrawable = itemView.context.contextCompatDrawable(R.drawable.ic_refresh_24dp)
|
||||
var locked = false
|
||||
private val headerGestureDetector = LibraryHeaderGestureDetector(this, binding)
|
||||
val category: Category?
|
||||
get() = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||
|
||||
init {
|
||||
binding.categoryHeaderLayout.setOnClickListener {
|
||||
|
@ -56,8 +58,6 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
|||
binding.updateButton.setOnClickListener { addCategoryToUpdate() }
|
||||
binding.categoryTitle.setOnLongClickListener { manageCategory() }
|
||||
binding.categoryTitle.setOnClickListener {
|
||||
val category =
|
||||
(adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||
if (category?.isHidden == false && adapter.mode == SelectableAdapter.Mode.MULTI) {
|
||||
selectAll()
|
||||
} else {
|
||||
|
@ -209,32 +209,7 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
|||
R.drawable.ic_expand_less_24dp
|
||||
},
|
||||
)
|
||||
when {
|
||||
adapter.mode == SelectableAdapter.Mode.MULTI -> {
|
||||
binding.checkbox.isVisible = !category.isHidden
|
||||
binding.collapseArrow.isVisible = category.isHidden && !adapter.isSingleCategory
|
||||
binding.updateButton.isVisible = false
|
||||
setSelection()
|
||||
}
|
||||
(category.id ?: -1) < 0 || adapter.libraryListener is FilteredLibraryController -> {
|
||||
binding.collapseArrow.isVisible = false
|
||||
binding.checkbox.isVisible = false
|
||||
setRefreshing(false)
|
||||
binding.updateButton.isVisible = false
|
||||
}
|
||||
LibraryUpdateJob.categoryInQueue(category.id) -> {
|
||||
binding.collapseArrow.isVisible = !adapter.isSingleCategory
|
||||
binding.checkbox.isVisible = false
|
||||
binding.updateButton.isVisible = true
|
||||
setRefreshing(true)
|
||||
}
|
||||
else -> {
|
||||
binding.collapseArrow.isVisible = !adapter.isSingleCategory
|
||||
binding.checkbox.isVisible = false
|
||||
setRefreshing(false)
|
||||
binding.updateButton.isVisible = !adapter.isSingleCategory
|
||||
}
|
||||
}
|
||||
notifyStatus(LibraryUpdateJob.categoryInQueue(category.id), category)
|
||||
}
|
||||
|
||||
@SuppressLint("DiscouragedApi")
|
||||
|
@ -280,31 +255,29 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
|||
}
|
||||
|
||||
fun manageCategory(): Boolean {
|
||||
val category = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||
adapter.libraryListener?.manageCategory(flexibleAdapterPosition)
|
||||
return category?.isDynamic == false
|
||||
}
|
||||
|
||||
private fun showCatSortOptions() {
|
||||
val category =
|
||||
(adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category ?: return
|
||||
if (category == null) return
|
||||
adapter.controller?.activity?.let { activity ->
|
||||
val items = LibrarySort.entries.map { it.menuSheetItem(category.isDynamic) }
|
||||
val sortingMode = category.sortingMode(true)
|
||||
val items = LibrarySort.entries.map { it.menuSheetItem(category!!.isDynamic) }
|
||||
val sortingMode = category!!.sortingMode(true)
|
||||
val sheet = MaterialMenuSheet(
|
||||
activity,
|
||||
items,
|
||||
activity.getString(MR.strings.sort_by),
|
||||
sortingMode?.mainValue,
|
||||
) { sheet, item ->
|
||||
onCatSortClicked(category, item)
|
||||
onCatSortClicked(category!!, item)
|
||||
val nCategory = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||
val isAscending = nCategory?.isAscending() ?: false
|
||||
val drawableRes = getSortRes(item, isAscending)
|
||||
sheet.setDrawable(item, drawableRes)
|
||||
false
|
||||
}
|
||||
val isAscending = category.isAscending()
|
||||
val isAscending = category!!.isAscending()
|
||||
val drawableRes = getSortRes(sortingMode, isAscending)
|
||||
sheet.setDrawable(sortingMode?.mainValue ?: -1, drawableRes)
|
||||
sheet.show()
|
||||
|
@ -391,4 +364,33 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
|||
super.onLongClick(view)
|
||||
return false
|
||||
}
|
||||
|
||||
fun notifyStatus(isReloading: Boolean, category: Category) {
|
||||
when {
|
||||
adapter.mode == SelectableAdapter.Mode.MULTI -> {
|
||||
binding.checkbox.isVisible = !category.isHidden
|
||||
binding.collapseArrow.isVisible = category.isHidden && !adapter.isSingleCategory
|
||||
binding.updateButton.isVisible = false
|
||||
setSelection()
|
||||
}
|
||||
(category.id ?: -1) < 0 || adapter.libraryListener is FilteredLibraryController -> {
|
||||
binding.collapseArrow.isVisible = false
|
||||
binding.checkbox.isVisible = false
|
||||
setRefreshing(false)
|
||||
binding.updateButton.isVisible = false
|
||||
}
|
||||
isReloading -> {
|
||||
binding.collapseArrow.isVisible = !adapter.isSingleCategory
|
||||
binding.checkbox.isVisible = false
|
||||
binding.updateButton.isVisible = true
|
||||
setRefreshing(true)
|
||||
}
|
||||
else -> {
|
||||
binding.collapseArrow.isVisible = !adapter.isSingleCategory
|
||||
binding.checkbox.isVisible = false
|
||||
setRefreshing(false)
|
||||
binding.updateButton.isVisible = !adapter.isSingleCategory
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue