fix: Don't overwrite allCategories inside combine {}

This commit is contained in:
Ahmad Ansori Palembani 2024-12-21 19:27:59 +07:00
parent 547028776e
commit 1298ef7d40
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -801,16 +801,17 @@ class LibraryPresenter(
* If category id '-1' is not empty, it means the library not grouped by categories * If category id '-1' is not empty, it means the library not grouped by categories
*/ */
private fun getLibraryFlow(): Flow<LibraryData> { private fun getLibraryFlow(): Flow<LibraryData> {
val libraryItemFlow = combine( val libraryFlow = combine(
getCategories.subscribe(), getCategories.subscribe(),
// FIXME: Remove retry once a real solution is found // FIXME: Remove retry once a real solution is found
getLibraryManga.subscribe().retry(1) { e -> e is NullPointerException }, getLibraryManga.subscribe().retry(1) { e -> e is NullPointerException },
getPreferencesFlow(), getPreferencesFlow(),
forceUpdateEvent.receiveAsFlow(), forceUpdateEvent.receiveAsFlow(),
) { allCategories, libraryMangaList, prefs, _ -> ) { dbCategories, libraryMangaList, prefs, _ ->
groupType = prefs.groupType groupType = prefs.groupType
val defaultCategory = createDefaultCategory() val defaultCategory = createDefaultCategory()
allCategories = listOf(defaultCategory) + dbCategories val allCategories = listOf(defaultCategory) + dbCategories
// FIXME: Should return Map<Int, LibraryItem> where Int is category id // FIXME: Should return Map<Int, LibraryItem> where Int is category id
if (groupType <= BY_DEFAULT || !libraryIsGrouped) { if (groupType <= BY_DEFAULT || !libraryIsGrouped) {
@ -831,13 +832,14 @@ class LibraryPresenter(
groupType, groupType,
prefs.collapsedDynamicCategories, prefs.collapsedDynamicCategories,
) )
} } to allCategories
} }
return combine( return combine(
libraryItemFlow, libraryFlow,
preferences.removeArticles().changes(), preferences.removeArticles().changes(),
) { libraryItems, removeArticles -> ) { library, removeArticles ->
val (libraryItems, allCategories) = library
val (items, categories, hiddenItems) = libraryItems val (items, categories, hiddenItems) = libraryItems
LibraryData( LibraryData(