From 3107b1dd12acbbb189de183d127a2e0f5f9970a7 Mon Sep 17 00:00:00 2001 From: sdaqo Date: Fri, 1 Nov 2024 23:52:50 +0100 Subject: [PATCH] address change requests address change requests --- .../main/java/eu/kanade/domain/DomainModule.kt | 4 ++++ .../domain/source/interactor/GetIncognitoState.kt | 15 +++++++++++++++ .../source/interactor/ToggleIncognitoSource.kt | 15 +++++++++++++++ .../domain/source/interactor/ToggleSource.kt | 7 ------- .../tachiyomi/extension/ExtensionManager.kt | 10 +++++----- .../details/ExtensionDetailsScreenModel.kt | 6 ++++-- .../source/browse/BrowseSourceScreenModel.kt | 8 ++++---- .../kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 4 +++- 8 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/eu/kanade/domain/source/interactor/GetIncognitoState.kt create mode 100644 app/src/main/java/eu/kanade/domain/source/interactor/ToggleIncognitoSource.kt diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 08787e1f8..38469bb8e 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -13,9 +13,11 @@ import eu.kanade.domain.manga.interactor.SetExcludedScanlators import eu.kanade.domain.manga.interactor.SetMangaViewerFlags import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.source.interactor.GetEnabledSources +import eu.kanade.domain.source.interactor.GetIncognitoState import eu.kanade.domain.source.interactor.GetLanguagesWithSources import eu.kanade.domain.source.interactor.GetSourcesWithFavoriteCount import eu.kanade.domain.source.interactor.SetMigrateSorting +import eu.kanade.domain.source.interactor.ToggleIncognitoSource import eu.kanade.domain.source.interactor.ToggleLanguage import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.interactor.ToggleSourcePin @@ -177,9 +179,11 @@ class DomainModule : InjektModule { addFactory { GetRemoteManga(get()) } addFactory { GetSourcesWithFavoriteCount(get(), get()) } addFactory { GetSourcesWithNonLibraryManga(get()) } + addFactory { GetIncognitoState(get(), get()) } addFactory { SetMigrateSorting(get()) } addFactory { ToggleLanguage(get()) } addFactory { ToggleSource(get()) } + addFactory { ToggleIncognitoSource(get()) } addFactory { ToggleSourcePin(get()) } addFactory { TrustExtension(get(), get()) } diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/GetIncognitoState.kt b/app/src/main/java/eu/kanade/domain/source/interactor/GetIncognitoState.kt new file mode 100644 index 000000000..d0cf9050d --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/source/interactor/GetIncognitoState.kt @@ -0,0 +1,15 @@ +package eu.kanade.domain.source.interactor + +import eu.kanade.domain.base.BasePreferences +import eu.kanade.domain.source.service.SourcePreferences + +class GetIncognitoState( + private val basePreferences: BasePreferences, + private val sourcePreferences: SourcePreferences, +) { + fun isEnabled(sourceId: Long): Boolean { + val globalIncognito = basePreferences.incognitoMode().get() + val sourceIncognito = sourceId.toString() in sourcePreferences.incognitoSources().get() + return globalIncognito || sourceIncognito + } +} diff --git a/app/src/main/java/eu/kanade/domain/source/interactor/ToggleIncognitoSource.kt b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleIncognitoSource.kt new file mode 100644 index 000000000..f531d8246 --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/source/interactor/ToggleIncognitoSource.kt @@ -0,0 +1,15 @@ +package eu.kanade.domain.source.interactor + +import eu.kanade.domain.source.service.SourcePreferences +import tachiyomi.core.common.preference.getAndSet + +class ToggleIncognitoSource( + private val preferences: SourcePreferences, +) { + fun await(sourceIds: List, enable: Boolean) { + val transformedSourceIds = sourceIds.map { it.toString() } + preferences.incognitoSources().getAndSet { incognitoed -> + if (enable) incognitoed.plus(transformedSourceIds) else incognitoed.minus(transformedSourceIds) + } + } +} 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 fa5102b83..852f267c5 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 @@ -25,13 +25,6 @@ class ToggleSource( } } - fun awaitIncognito(sourceIds: List, enableIncognito: Boolean) { - val transformedSourceIds = sourceIds.map { it.toString() } - preferences.incognitoSources().getAndSet { incognitoed -> - if (enableIncognito) incognitoed.plus(transformedSourceIds) else incognitoed.minus(transformedSourceIds) - } - } - private fun isEnabled(sourceId: Long): Boolean { return sourceId.toString() in preferences.disabledSources().get() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 1968c6133..8d3a2d010 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.extension import android.content.Context import android.graphics.drawable.Drawable import eu.kanade.domain.extension.interactor.TrustExtension -import eu.kanade.domain.source.interactor.ToggleSource +import eu.kanade.domain.source.interactor.ToggleIncognitoSource import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.api.ExtensionApi import eu.kanade.tachiyomi.extension.api.ExtensionUpdateNotifier @@ -44,7 +44,7 @@ class ExtensionManager( private val context: Context, private val preferences: SourcePreferences = Injekt.get(), private val sourcePreferences: SourcePreferences = Injekt.get(), - private val toggleSource: ToggleSource = Injekt.get(), + private val toggleIncognitoSource: ToggleIncognitoSource = Injekt.get(), private val trustExtension: TrustExtension = Injekt.get(), ) { @@ -301,11 +301,11 @@ class ExtensionManager( if (oldExtension.sources.first().id.toString() in sourcePreferences.incognitoSources().get()) { oldExtension.sources .map { it.id } - .let { toggleSource.awaitIncognito(it, false) } + .let { toggleIncognitoSource.await(it, false) } extension.sources .map { it.id } - .let { toggleSource.awaitIncognito(it, true) } + .let { toggleIncognitoSource.await(it, true) } } } installedExtensionMapFlow.value += extension @@ -320,7 +320,7 @@ class ExtensionManager( private fun unregisterExtension(pkgName: String) { val installedExtension = installedExtensionMapFlow.value[pkgName] installedExtension?.sources?.map { it.id }?.let { - toggleSource.awaitIncognito(it, false) + toggleIncognitoSource.await(it, false) } installedExtensionMapFlow.value -= pkgName diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreenModel.kt index 6cddf6fdf..554443787 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsScreenModel.kt @@ -6,6 +6,7 @@ import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.screenModelScope import eu.kanade.domain.extension.interactor.ExtensionSourceItem import eu.kanade.domain.extension.interactor.GetExtensionSources +import eu.kanade.domain.source.interactor.ToggleIncognitoSource import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.extension.ExtensionManager @@ -37,6 +38,7 @@ class ExtensionDetailsScreenModel( private val extensionManager: ExtensionManager = Injekt.get(), private val getExtensionSources: GetExtensionSources = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(), + private val toggleIncognitoSource: ToggleIncognitoSource = Injekt.get(), private val preferences: SourcePreferences = Injekt.get(), ) : StateScreenModel(State()) { @@ -120,10 +122,10 @@ class ExtensionDetailsScreenModel( ?.let { toggleSource.awaitDisable(it, enable) } } - fun toggleIncognito(enableIncognito: Boolean) { + fun toggleIncognito(enable: Boolean) { state.value.extension?.sources ?.map { it.id } - ?.let { toggleSource.awaitIncognito(it, enableIncognito) } + ?.let { toggleIncognitoSource.await(it, enable) } } fun isIncognito(): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt index 7ffba57ff..bece97fc7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceScreenModel.kt @@ -14,9 +14,9 @@ import androidx.paging.map import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.screenModelScope import eu.kanade.core.preference.asState -import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.toDomainManga +import eu.kanade.domain.source.interactor.GetIncognitoState import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.track.interactor.AddTracks import eu.kanade.presentation.util.ioCoroutineScope @@ -60,7 +60,6 @@ class BrowseSourceScreenModel( listingQuery: String?, sourceManager: SourceManager = Injekt.get(), sourcePreferences: SourcePreferences = Injekt.get(), - basePreferences: BasePreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), private val getRemoteManga: GetRemoteManga = Injekt.get(), @@ -72,7 +71,8 @@ class BrowseSourceScreenModel( private val networkToLocalManga: NetworkToLocalManga = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), private val addTracks: AddTracks = Injekt.get(), -) : StateScreenModel(State(Listing.valueOf(listingQuery))) { + private val getIncognitoState: GetIncognitoState = Injekt.get(), + ) : StateScreenModel(State(Listing.valueOf(listingQuery))) { var displayMode by sourcePreferences.sourceDisplayMode().asState(screenModelScope) @@ -97,7 +97,7 @@ class BrowseSourceScreenModel( } } - if (!(basePreferences.incognitoMode().get() || source.id.toString() in sourcePreferences.incognitoSources().get())) { + if (!getIncognitoState.isEnabled(source.id)) { sourcePreferences.lastUsedSource().set(source.id) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 526ec856d..62e9fda11 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -12,6 +12,7 @@ import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.SetMangaViewerFlags import eu.kanade.domain.manga.model.readerOrientation import eu.kanade.domain.manga.model.readingMode +import eu.kanade.domain.source.interactor.GetIncognitoState import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.track.interactor.TrackChapter import eu.kanade.domain.track.service.TrackPreferences @@ -101,6 +102,7 @@ class ReaderViewModel @JvmOverloads constructor( private val upsertHistory: UpsertHistory = Injekt.get(), private val updateChapter: UpdateChapter = Injekt.get(), private val setMangaViewerFlags: SetMangaViewerFlags = Injekt.get(), + private val getIncognitoState: GetIncognitoState = Injekt.get() ) : ViewModel() { private val mutableState = MutableStateFlow(State()) @@ -220,7 +222,7 @@ class ReaderViewModel @JvmOverloads constructor( // Use lazy here as manga can be null private val incognitoMode: Boolean by lazy { - preferences.incognitoMode().get() || manga?.source.toString() in sourcePreferences.incognitoSources().get() + getIncognitoState.isEnabled(manga!!.source) } private val downloadAheadAmount = downloadPreferences.autoDownloadWhileReading().get()