From 217b03a292457b648ab8abd7c2d264382ddb3023 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 27 Nov 2022 09:37:22 +0700 Subject: [PATCH] Fix library not loading when not logged in to any tracker (#8629) --- .../ui/library/LibraryScreenModel.kt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt index aa09dfd2c..2b4d8cce6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt @@ -52,6 +52,7 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach @@ -417,13 +418,17 @@ class LibraryScreenModel( */ private fun getTrackingFilterFlow(): Flow> { val loggedServices = trackManager.services.filter { it.isLogged } - val a = loggedServices - .map { libraryPreferences.filterTracking(it.id.toInt()).changes() } - .toTypedArray() - return combine(*a) { - loggedServices - .mapIndexed { index, trackService -> trackService.id to it[index] } - .toMap() + return if (loggedServices.isNotEmpty()) { + val prefFlows = loggedServices + .map { libraryPreferences.filterTracking(it.id.toInt()).changes() } + .toTypedArray() + combine(*prefFlows) { + loggedServices + .mapIndexed { index, trackService -> trackService.id to it[index] } + .toMap() + } + } else { + flowOf(emptyMap()) } }