address change requests

address change requests
This commit is contained in:
sdaqo 2024-11-01 23:52:50 +01:00
parent b47b3bfdd5
commit 3107b1dd12
No known key found for this signature in database
8 changed files with 50 additions and 19 deletions

View file

@ -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()) }

View file

@ -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
}
}

View file

@ -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<Long>, enable: Boolean) {
val transformedSourceIds = sourceIds.map { it.toString() }
preferences.incognitoSources().getAndSet { incognitoed ->
if (enable) incognitoed.plus(transformedSourceIds) else incognitoed.minus(transformedSourceIds)
}
}
}

View file

@ -25,13 +25,6 @@ class ToggleSource(
}
}
fun awaitIncognito(sourceIds: List<Long>, 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()
}

View file

@ -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

View file

@ -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<ExtensionDetailsScreenModel.State>(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 {

View file

@ -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,6 +71,7 @@ class BrowseSourceScreenModel(
private val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
private val updateManga: UpdateManga = Injekt.get(),
private val addTracks: AddTracks = Injekt.get(),
private val getIncognitoState: GetIncognitoState = Injekt.get(),
) : StateScreenModel<BrowseSourceScreenModel.State>(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)
}
}

View file

@ -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()