diff --git a/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt b/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt index 84dfd214d..f2167cbc6 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt +++ b/app/src/main/java/org/koitharu/kotatsu/library/domain/LibraryRepository.kt @@ -1,13 +1,11 @@ package org.koitharu.kotatsu.library.domain -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.* import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.db.entity.toManga import org.koitharu.kotatsu.core.db.entity.toMangaTags import org.koitharu.kotatsu.core.model.FavouriteCategory +import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity import org.koitharu.kotatsu.favourites.data.toFavouriteCategory import org.koitharu.kotatsu.parsers.model.Manga @@ -18,13 +16,22 @@ class LibraryRepository( fun observeFavourites(): Flow>> { return db.favouriteCategoriesDao.observeAll() .flatMapLatest { categories -> - combine( - categories.map { cat -> - val category = cat.toFavouriteCategory() - db.favouritesDao.observeAll(category.id, category.order) - .map { category to it.map { x -> x.manga.toManga(x.tags.toMangaTags()) } } - }, - ) { array -> array.toMap() } + val cats = categories.filter { it.isVisibleInLibrary } + if (cats.isEmpty()) { + flowOf(emptyMap()) + } else { + observeCategoriesContent(cats) + } } } + + private fun observeCategoriesContent( + categories: List, + ) = combine>, Map>>( + categories.map { cat -> + val category = cat.toFavouriteCategory() + db.favouritesDao.observeAll(category.id, category.order) + .map { category to it.map { x -> x.manga.toManga(x.tags.toMangaTags()) } } + }, + ) { array -> array.toMap() } } diff --git a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt b/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt index 3d08a43b7..846eb21c5 100644 --- a/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt +++ b/app/src/main/java/org/koitharu/kotatsu/library/ui/adapter/LibraryGroupAD.kt @@ -27,9 +27,8 @@ fun libraryGroupAD( selectionController: SectionedSelectionController, listener: LibraryListEventListener, ) = adapterDelegateViewBinding( - { layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) } + { layoutInflater, parent -> ItemListGroupBinding.inflate(layoutInflater, parent, false) }, ) { - val listenerAdapter = object : OnListItemClickListener, View.OnClickListener { override fun onItemClick(item: Manga, view: View) { listener.onItemClick(item, this@adapterDelegateViewBinding.item, view) @@ -46,7 +45,7 @@ fun libraryGroupAD( val adapter = AsyncListDifferDelegationAdapter( MangaItemDiffCallback(), - mangaGridItemAD(coil, lifecycleOwner, listenerAdapter, sizeResolver) + mangaGridItemAD(coil, lifecycleOwner, listenerAdapter, sizeResolver), ) binding.recyclerView.setRecycledViewPool(sharedPool) binding.recyclerView.adapter = adapter @@ -64,4 +63,8 @@ fun libraryGroupAD( binding.buttonMore.setTextAndVisible(item.showAllButtonText) adapter.items = item.items } -} \ No newline at end of file + + onViewRecycled { + adapter.items = emptyList() + } +}