From 8583095a597a335f88709df7505d56e67efa8a87 Mon Sep 17 00:00:00 2001 From: anenasa <84259093+anenasa@users.noreply.github.com> Date: Sun, 29 Sep 2024 19:57:08 +0800 Subject: [PATCH] Manwa: Add preference for mirror selection (#5286) --- src/zh/manwa/build.gradle | 2 +- .../eu/kanade/tachiyomi/extension/zh/manwa/Manwa.kt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/zh/manwa/build.gradle b/src/zh/manwa/build.gradle index cdfc677c3..b7931e782 100644 --- a/src/zh/manwa/build.gradle +++ b/src/zh/manwa/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Manwa' extClass = '.Manwa' - extVersionCode = 6 + extVersionCode = 7 isNsfw = true } diff --git a/src/zh/manwa/src/eu/kanade/tachiyomi/extension/zh/manwa/Manwa.kt b/src/zh/manwa/src/eu/kanade/tachiyomi/extension/zh/manwa/Manwa.kt index 606b33a35..54b6177cb 100644 --- a/src/zh/manwa/src/eu/kanade/tachiyomi/extension/zh/manwa/Manwa.kt +++ b/src/zh/manwa/src/eu/kanade/tachiyomi/extension/zh/manwa/Manwa.kt @@ -43,10 +43,10 @@ class Manwa : ParsedHttpSource(), ConfigurableSource { override val name: String = "漫蛙" override val lang: String = "zh" override val supportsLatest: Boolean = true - override val baseUrl = "https://manwa.fun" private val json: Json by injectLazy() private val preferences: SharedPreferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) + override val baseUrl = "https://" + MIRROR_ENTRIES.run { this[preferences.getString(MIRROR_KEY, "0")!!.toInt().coerceAtMost(size)] } private val rewriteOctetStream: Interceptor = Interceptor { chain -> val originalResponse: Response = chain.proceed(chain.request()) @@ -179,6 +179,14 @@ class Manwa : ParsedHttpSource(), ConfigurableSource { override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException() override fun setupPreferenceScreen(screen: PreferenceScreen) { + ListPreference(screen.context).apply { + key = MIRROR_KEY + title = "使用镜像网址" + entries = MIRROR_ENTRIES + entryValues = Array(entries.size, Int::toString) + setDefaultValue("0") + }.let { screen.addPreference(it) } + ListPreference(screen.context).apply { key = IMAGE_HOST_KEY title = "图源" @@ -208,6 +216,8 @@ class Manwa : ParsedHttpSource(), ConfigurableSource { } companion object { + private const val MIRROR_KEY = "MIRROR" + private val MIRROR_ENTRIES get() = arrayOf("manwa.fun", "manwa.me", "manwav3.xyz", "manwasa.cc", "manwadf.cc") private const val IMAGE_HOST_KEY = "IMG_HOST" private val IMAGE_HOST_ENTRIES = arrayOf("图源1", "图源2", "图源3") private val IMAGE_HOST_ENTRY_VALUES = arrayOf("1", "2", "3")