Manage Exhentai better, if login is disabled the source will disappear

This commit is contained in:
Jobobby04 2020-09-29 12:15:41 -04:00
parent 3c8fe2ed0e
commit 4805d3c0c0

View File

@ -4,7 +4,6 @@ import android.content.Context
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -35,7 +34,9 @@ import exh.source.EnhancedHttpSource
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import rx.Observable import rx.Observable
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -56,9 +57,18 @@ open class SourceManager(private val context: Context) {
createInternalSources().forEach { registerSource(it) } createInternalSources().forEach { registerSource(it) }
// SY --> // SY -->
// Recreate sources when they change // Create internal sources
prefs.enableExhentai().asImmediateFlow {
createEHSources().forEach { registerSource(it) } createEHSources().forEach { registerSource(it) }
// Watch the preference and manage Exhentai
prefs.enableExhentai().asFlow()
.drop(1)
.onEach {
if (it) {
registerSource(EHentai(EXH_SOURCE_ID, true, context))
} else {
sourcesMap.remove(EXH_SOURCE_ID)
}
}.launchIn(scope) }.launchIn(scope)
registerSource(MergedSource()) registerSource(MergedSource())