From dbf96f68ff4b394e95d2d0762cd6a515a1ef85c9 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Tue, 27 Apr 2021 02:28:59 -0400 Subject: [PATCH] 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 --- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 1459ff5acc..2618c94b77 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -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) { + 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) {