Fixed being able to collaspe catrgories if you only have one

This commit is contained in:
Jay 2020-05-11 13:01:54 -04:00
parent fdd4b08a49
commit 51c93bcd55

View File

@ -125,7 +125,8 @@ class LibraryPresenter(
fun restoreLibrary() { fun restoreLibrary() {
val items = libraryItems val items = libraryItems
val show = showAllCategories || preferences.hideCategories().getOrDefault() val show = showAllCategories || preferences.hideCategories().getOrDefault() ||
categories.size == 1
if (!show) { if (!show) {
sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap() sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap()
if (currentCategory == -1) currentCategory = categories.find { if (currentCategory == -1) currentCategory = categories.find {
@ -141,8 +142,9 @@ class LibraryPresenter(
private suspend fun sectionLibrary(items: List<LibraryItem>, freshStart: Boolean = false) { private suspend fun sectionLibrary(items: List<LibraryItem>, freshStart: Boolean = false) {
libraryItems = items libraryItems = items
val show = showAllCategories || preferences.hideCategories().getOrDefault() val showAll = showAllCategories || preferences.hideCategories().getOrDefault() ||
if (!show) { categories.size == 1
if (!showAll) {
sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap() sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap()
if (currentCategory == -1) currentCategory = categories.find { if (currentCategory == -1) currentCategory = categories.find {
it.order == preferences.lastUsedCategory().getOrDefault() it.order == preferences.lastUsedCategory().getOrDefault()
@ -150,7 +152,7 @@ class LibraryPresenter(
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
view.onNextLibraryUpdate( view.onNextLibraryUpdate(
if (!show) sectionedLibraryItems[currentCategory] if (!showAll) sectionedLibraryItems[currentCategory]
?: sectionedLibraryItems[categories.first().id] ?: blankItem() ?: sectionedLibraryItems[categories.first().id] ?: blankItem()
else libraryItems, freshStart else libraryItems, freshStart
) )
@ -530,7 +532,7 @@ class LibraryPresenter(
if (headerItem != null) items.add( if (headerItem != null) items.add(
LibraryItem(LibraryManga.createBlank(catId), headerItem) LibraryItem(LibraryManga.createBlank(catId), headerItem)
) )
} else if (catId in categoriesHidden && showAll) { } else if (catId in categoriesHidden && showAll && categories.size > 1) {
val mangaToRemove = items.filter { it.manga.category == catId } val mangaToRemove = items.filter { it.manga.category == catId }
val mergedTitle = mangaToRemove.joinToString("-") { val mergedTitle = mangaToRemove.joinToString("-") {
it.manga.title + "-" + it.manga.author it.manga.title + "-" + it.manga.author