mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 10:41:48 +01:00
Library presenter now fixes category order when 2 categories have the same order
It's unlikely the case and nothing awful happens with it, but it fixes the jump to category sheet
This commit is contained in:
parent
d1c709ce2c
commit
dbf96f68ff
@ -102,6 +102,10 @@ class LibraryPresenter(
|
||||
/** Get favorited manga for library and sort and filter it */
|
||||
fun getLibrary() {
|
||||
if (categories.isEmpty()) {
|
||||
val dbCategories = db.getCategories().executeAsBlocking()
|
||||
if ((dbCategories + Category.createDefault(context)).distinctBy { it.order }.size != dbCategories.size + 1) {
|
||||
reorderCategories(dbCategories)
|
||||
}
|
||||
categories = lastCategories ?: db.getCategories().executeAsBlocking().toMutableList()
|
||||
}
|
||||
presenterScope.launch {
|
||||
@ -119,6 +123,12 @@ class LibraryPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun reorderCategories(categories: List<Category>) {
|
||||
val sortedCategories = categories.sortedBy { it.order }
|
||||
sortedCategories.forEachIndexed { i, category -> category.order = i }
|
||||
db.insertCategories(sortedCategories).executeAsBlocking()
|
||||
}
|
||||
|
||||
fun getCurrentCategory() = categories.find { it.id == currentCategory }
|
||||
|
||||
fun switchSection(order: Int) {
|
||||
|
Loading…
Reference in New Issue
Block a user