Fix NPE in ListConfigViewModel

pull/571/head v6.4
Koitharu 2 years ago
parent cb0f0c70d0
commit 012eefe4fe
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -10,6 +10,7 @@ import org.koitharu.kotatsu.core.util.ext.require
import org.koitharu.kotatsu.core.util.ext.sortedByOrdinal
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
import org.koitharu.kotatsu.list.domain.ListSortOrder
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
import javax.inject.Inject
@HiltViewModel
@ -54,7 +55,7 @@ class ListConfigViewModel @Inject constructor(
}?.sortedByOrdinal()
fun getSelectedSortOrder(): ListSortOrder? = when (section) {
is ListConfigSection.Favorites -> runBlocking { favouritesRepository.getCategory(section.categoryId).order }
is ListConfigSection.Favorites -> getCategorySortOrder(section.categoryId)
ListConfigSection.General -> null
ListConfigSection.History -> settings.historySortOrder
ListConfigSection.Suggestions -> ListSortOrder.RELEVANCE // TODO
@ -73,4 +74,10 @@ class ListConfigViewModel @Inject constructor(
ListConfigSection.Suggestions -> Unit
}
}
private fun getCategorySortOrder(id: Long): ListSortOrder = runBlocking {
runCatchingCancellable {
favouritesRepository.getCategory(id).order
}.getOrDefault(ListSortOrder.NEWEST)
}
}

Loading…
Cancel
Save