mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore: Simplify some code and add some comments/todo
This commit is contained in:
parent
ff08e19880
commit
e36379bd6c
1 changed files with 9 additions and 7 deletions
|
@ -729,6 +729,8 @@ class LibraryPresenter(
|
||||||
) { categories, libraryMangaList, groupType ->
|
) { categories, libraryMangaList, groupType ->
|
||||||
this.groupType = groupType
|
this.groupType = groupType
|
||||||
|
|
||||||
|
// TODO: Support custom groups
|
||||||
|
|
||||||
val categoryAll = Category.createAll(
|
val categoryAll = Category.createAll(
|
||||||
context,
|
context,
|
||||||
preferences.librarySortingMode().get(),
|
preferences.librarySortingMode().get(),
|
||||||
|
@ -739,12 +741,8 @@ class LibraryPresenter(
|
||||||
val headerItems = if (libraryIsGrouped)
|
val headerItems = if (libraryIsGrouped)
|
||||||
(
|
(
|
||||||
categories.mapNotNull { category ->
|
categories.mapNotNull { category ->
|
||||||
val id = category.id
|
val id = category.id ?: return@mapNotNull null
|
||||||
if (id == null) {
|
id to LibraryHeaderItem({ getCategory(id) }, id)
|
||||||
null
|
|
||||||
} else {
|
|
||||||
id to LibraryHeaderItem({ getCategory(id) }, id)
|
|
||||||
}
|
|
||||||
} + (-1 to catItemAll) + (0 to LibraryHeaderItem({ getCategory(0) }, 0))
|
} + (-1 to catItemAll) + (0 to LibraryHeaderItem({ getCategory(0) }, 0))
|
||||||
).toMap()
|
).toMap()
|
||||||
else null
|
else null
|
||||||
|
@ -758,7 +756,7 @@ class LibraryPresenter(
|
||||||
LibraryItem(it, headerItem, viewContext)
|
LibraryItem(it, headerItem, viewContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
categories.associateWith { libraryManga.filter { item -> item.header.category.id == it.id } }
|
libraryManga.groupBy { it.header.category.id!! }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,6 +766,7 @@ class LibraryPresenter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Simplify this code
|
||||||
/**
|
/**
|
||||||
* Get the categories and all its manga from the database.
|
* Get the categories and all its manga from the database.
|
||||||
*
|
*
|
||||||
|
@ -776,6 +775,9 @@ class LibraryPresenter(
|
||||||
private suspend fun getLibraryFromDB(): Pair<List<LibraryItem>, List<LibraryItem>> {
|
private suspend fun getLibraryFromDB(): Pair<List<LibraryItem>, List<LibraryItem>> {
|
||||||
removeArticles = preferences.removeArticles().get()
|
removeArticles = preferences.removeArticles().get()
|
||||||
val categories = getCategories.await().toMutableList()
|
val categories = getCategories.await().toMutableList()
|
||||||
|
|
||||||
|
// In default grouping, which uses category as group, a manga can be in multiple categories.
|
||||||
|
// So before we group it by different type, we should make the list unique.
|
||||||
val libraryManga = getLibraryManga.await().apply { if (groupType > BY_DEFAULT) { distinctBy { it.id } } }
|
val libraryManga = getLibraryManga.await().apply { if (groupType > BY_DEFAULT) { distinctBy { it.id } } }
|
||||||
val showAll = showAllCategories
|
val showAll = showAllCategories
|
||||||
val hiddenItems = mutableListOf<LibraryItem>()
|
val hiddenItems = mutableListOf<LibraryItem>()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue