mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-19 09:39:43 +02:00
Fix crash opening filter sheet with empty library and mark as read/unread for selected items (#2355)
This commit is contained in:
@@ -499,8 +499,9 @@ class LibraryScreenModel(
|
||||
* Marks mangas' chapters read status.
|
||||
*/
|
||||
fun markReadSelection(read: Boolean) {
|
||||
val selection = state.value.selectedManga
|
||||
screenModelScope.launchNonCancellable {
|
||||
state.value.selectedManga.forEach { manga ->
|
||||
selection.forEach { manga ->
|
||||
setReadStatus.await(
|
||||
manga = manga,
|
||||
read = read,
|
||||
@@ -573,7 +574,7 @@ class LibraryScreenModel(
|
||||
|
||||
fun getRandomLibraryItemForCurrentCategory(): LibraryItem? {
|
||||
val state = state.value
|
||||
return state.getItemsForCategoryId(state.activeCategory.id).randomOrNull()
|
||||
return state.getItemsForCategoryId(state.activeCategory?.id).randomOrNull()
|
||||
}
|
||||
|
||||
fun showSettingsDialog() {
|
||||
@@ -631,7 +632,7 @@ class LibraryScreenModel(
|
||||
lastSelectionCategory = null
|
||||
mutableState.update { state ->
|
||||
val newSelection = state.selection.mutate { list ->
|
||||
state.getItemsForCategoryId(state.activeCategory.id).map { it.id }.let(list::addAll)
|
||||
state.getItemsForCategoryId(state.activeCategory?.id).map { it.id }.let(list::addAll)
|
||||
}
|
||||
state.copy(selection = newSelection)
|
||||
}
|
||||
@@ -641,7 +642,7 @@ class LibraryScreenModel(
|
||||
lastSelectionCategory = null
|
||||
mutableState.update { state ->
|
||||
val newSelection = state.selection.mutate { list ->
|
||||
val itemIds = state.getItemsForCategoryId(state.activeCategory.id).fastMap { it.id }
|
||||
val itemIds = state.getItemsForCategoryId(state.activeCategory?.id).fastMap { it.id }
|
||||
val (toRemove, toAdd) = itemIds.partition { it in list }
|
||||
list.removeAll(toRemove)
|
||||
list.addAll(toAdd)
|
||||
@@ -756,7 +757,7 @@ class LibraryScreenModel(
|
||||
maximumValue = displayedCategories.lastIndex.coerceAtLeast(0),
|
||||
)
|
||||
|
||||
val activeCategory: Category by lazy { displayedCategories[coercedActiveCategoryIndex] }
|
||||
val activeCategory: Category? = displayedCategories.getOrNull(coercedActiveCategoryIndex)
|
||||
|
||||
val isLibraryEmpty = libraryData.favorites.isEmpty()
|
||||
|
||||
@@ -764,7 +765,8 @@ class LibraryScreenModel(
|
||||
|
||||
val selectedManga by lazy { selection.mapNotNull { libraryData.favoritesById[it]?.libraryManga?.manga } }
|
||||
|
||||
fun getItemsForCategoryId(categoryId: Long): List<LibraryItem> {
|
||||
fun getItemsForCategoryId(categoryId: Long?): List<LibraryItem> {
|
||||
if (categoryId == null) return emptyList()
|
||||
val category = displayedCategories.find { it.id == categoryId } ?: return emptyList()
|
||||
return getItemsForCategory(category)
|
||||
}
|
||||
|
Reference in New Issue
Block a user