From 280b0f42db2cc8c21ac046b11717cac6975746ca Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 4 Nov 2022 09:39:23 -0400 Subject: [PATCH] Toggle enabled source in bulk Maybe fixes #8439 --- .../eu/kanade/domain/source/interactor/ToggleSource.kt | 7 +++++++ .../browse/extension/details/ExtensionDetailsPresenter.kt | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt index bb602da5c4..e69e76dab4 100644 --- a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleSource.kt @@ -18,6 +18,13 @@ class ToggleSource( } } + fun await(sourceIds: List, enable: Boolean) { + val transformedSourceIds = sourceIds.map { it.toString() } + preferences.disabledSources().getAndSet { disabled -> + if (enable) disabled.minus(transformedSourceIds) else disabled.plus(transformedSourceIds) + } + } + private fun isEnabled(sourceId: Long): Boolean { return sourceId.toString() in preferences.disabledSources().get() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt index 3e972394e0..1ddc124c58 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsPresenter.kt @@ -118,7 +118,9 @@ class ExtensionDetailsPresenter( } fun toggleSources(enable: Boolean) { - extension?.sources?.forEach { toggleSource.await(it.id, enable) } + extension?.sources + ?.map { it.id } + ?.let { toggleSource.await(it, enable) } } private fun createUrl(url: String, pkgName: String, pkgFactory: String?, path: String = ""): String {