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.text
|
||||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.widget.EmptyView
|
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.delay
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.drop
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
@ -138,12 +145,6 @@ import uy.kohesive.injekt.api.get
|
||||||
import yokai.domain.ui.UiPreferences
|
import yokai.domain.ui.UiPreferences
|
||||||
import yokai.i18n.MR
|
import yokai.i18n.MR
|
||||||
import yokai.util.lang.getString
|
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
|
import android.R as AR
|
||||||
|
|
||||||
open class LibraryController(
|
open class LibraryController(
|
||||||
|
@ -610,6 +611,13 @@ open class LibraryController(
|
||||||
setUpHopper()
|
setUpHopper()
|
||||||
setPreferenceFlows()
|
setPreferenceFlows()
|
||||||
LibraryUpdateJob.updateFlow.onEach(::onUpdateManga).launchIn(viewScope)
|
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 =
|
elevateAppBar =
|
||||||
scrollViewWith(
|
scrollViewWith(
|
||||||
|
|
|
@ -47,6 +47,8 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
private val refreshDrawable = itemView.context.contextCompatDrawable(R.drawable.ic_refresh_24dp)
|
private val refreshDrawable = itemView.context.contextCompatDrawable(R.drawable.ic_refresh_24dp)
|
||||||
var locked = false
|
var locked = false
|
||||||
private val headerGestureDetector = LibraryHeaderGestureDetector(this, binding)
|
private val headerGestureDetector = LibraryHeaderGestureDetector(this, binding)
|
||||||
|
val category: Category?
|
||||||
|
get() = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||||
|
|
||||||
init {
|
init {
|
||||||
binding.categoryHeaderLayout.setOnClickListener {
|
binding.categoryHeaderLayout.setOnClickListener {
|
||||||
|
@ -56,8 +58,6 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
binding.updateButton.setOnClickListener { addCategoryToUpdate() }
|
binding.updateButton.setOnClickListener { addCategoryToUpdate() }
|
||||||
binding.categoryTitle.setOnLongClickListener { manageCategory() }
|
binding.categoryTitle.setOnLongClickListener { manageCategory() }
|
||||||
binding.categoryTitle.setOnClickListener {
|
binding.categoryTitle.setOnClickListener {
|
||||||
val category =
|
|
||||||
(adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
|
||||||
if (category?.isHidden == false && adapter.mode == SelectableAdapter.Mode.MULTI) {
|
if (category?.isHidden == false && adapter.mode == SelectableAdapter.Mode.MULTI) {
|
||||||
selectAll()
|
selectAll()
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,32 +209,7 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
R.drawable.ic_expand_less_24dp
|
R.drawable.ic_expand_less_24dp
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
when {
|
notifyStatus(LibraryUpdateJob.categoryInQueue(category.id), category)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DiscouragedApi")
|
@SuppressLint("DiscouragedApi")
|
||||||
|
@ -280,31 +255,29 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
}
|
}
|
||||||
|
|
||||||
fun manageCategory(): Boolean {
|
fun manageCategory(): Boolean {
|
||||||
val category = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
|
||||||
adapter.libraryListener?.manageCategory(flexibleAdapterPosition)
|
adapter.libraryListener?.manageCategory(flexibleAdapterPosition)
|
||||||
return category?.isDynamic == false
|
return category?.isDynamic == false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showCatSortOptions() {
|
private fun showCatSortOptions() {
|
||||||
val category =
|
if (category == null) return
|
||||||
(adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category ?: return
|
|
||||||
adapter.controller?.activity?.let { activity ->
|
adapter.controller?.activity?.let { activity ->
|
||||||
val items = LibrarySort.entries.map { it.menuSheetItem(category.isDynamic) }
|
val items = LibrarySort.entries.map { it.menuSheetItem(category!!.isDynamic) }
|
||||||
val sortingMode = category.sortingMode(true)
|
val sortingMode = category!!.sortingMode(true)
|
||||||
val sheet = MaterialMenuSheet(
|
val sheet = MaterialMenuSheet(
|
||||||
activity,
|
activity,
|
||||||
items,
|
items,
|
||||||
activity.getString(MR.strings.sort_by),
|
activity.getString(MR.strings.sort_by),
|
||||||
sortingMode?.mainValue,
|
sortingMode?.mainValue,
|
||||||
) { sheet, item ->
|
) { sheet, item ->
|
||||||
onCatSortClicked(category, item)
|
onCatSortClicked(category!!, item)
|
||||||
val nCategory = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
val nCategory = (adapter.getItem(flexibleAdapterPosition) as? LibraryHeaderItem)?.category
|
||||||
val isAscending = nCategory?.isAscending() ?: false
|
val isAscending = nCategory?.isAscending() ?: false
|
||||||
val drawableRes = getSortRes(item, isAscending)
|
val drawableRes = getSortRes(item, isAscending)
|
||||||
sheet.setDrawable(item, drawableRes)
|
sheet.setDrawable(item, drawableRes)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
val isAscending = category.isAscending()
|
val isAscending = category!!.isAscending()
|
||||||
val drawableRes = getSortRes(sortingMode, isAscending)
|
val drawableRes = getSortRes(sortingMode, isAscending)
|
||||||
sheet.setDrawable(sortingMode?.mainValue ?: -1, drawableRes)
|
sheet.setDrawable(sortingMode?.mainValue ?: -1, drawableRes)
|
||||||
sheet.show()
|
sheet.show()
|
||||||
|
@ -391,4 +364,33 @@ class LibraryHeaderHolder(val view: View, val adapter: LibraryCategoryAdapter) :
|
||||||
super.onLongClick(view)
|
super.onLongClick(view)
|
||||||
return false
|
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