[ZH-Manhuagui] Add preference to use official mirror URL. (#6111)

This commit is contained in:
Oldwangtouchtouchdoge 2021-03-10 06:01:38 +08:00 committed by GitHub
parent ef82e290fe
commit dbb2fe726d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 4 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'ManHuaGui'
pkgNameSuffix = 'zh.manhuagui'
extClass = '.Manhuagui'
extVersionCode = 7
extVersionCode = 8
libVersion = '1.2'
}

View File

@ -50,16 +50,23 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() {
}
override val name = "漫画柜"
private val baseHost = if (preferences.getBoolean(USE_MIRROR_URL_PREF, false)) {
"mhgui.com"
} else {
"manhuagui.com"
}
override val baseUrl =
if (preferences.getBoolean(SHOW_ZH_HANT_WEBSITE_PREF, false))
"https://tw.manhuagui.com"
"https://tw.$baseHost"
else
"https://www.manhuagui.com"
"https://www.$baseHost"
override val lang = "zh"
override val supportsLatest = true
private val imageServer = arrayOf("https://i.hamreus.com", "https://cf.hamreus.com")
private val mobileWebsiteUrl = "https://m.manhuagui.com"
private val mobileWebsiteUrl = "https://m.$baseHost"
private val gson = Gson()
private val baseHttpUrl: HttpUrl = HttpUrl.parse(baseUrl)!!
@ -466,10 +473,28 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() {
}
}
val mirrorURLPreference = androidx.preference.CheckBoxPreference(screen.context).apply {
key = USE_MIRROR_URL_PREF
title = USE_MIRROR_URL_PREF_TITLE
summary = USE_MIRROR_URL_PREF_SUMMARY
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
try {
val newSetting = preferences.edit().putBoolean(USE_MIRROR_URL_PREF, newValue as Boolean).commit()
newSetting
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
screen.addPreference(mainSiteRateLimitPreference)
screen.addPreference(imgCDNRateLimitPreference)
screen.addPreference(zhHantPreference)
screen.addPreference(r18Preference)
screen.addPreference(mirrorURLPreference)
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
@ -543,10 +568,28 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() {
}
}
val mirrorURLPreference = CheckBoxPreference(screen.context).apply {
key = USE_MIRROR_URL_PREF
title = USE_MIRROR_URL_PREF_TITLE
summary = USE_MIRROR_URL_PREF_SUMMARY
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
try {
val newSetting = preferences.edit().putBoolean(USE_MIRROR_URL_PREF, newValue as Boolean).commit()
newSetting
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
screen.addPreference(mainSiteRateLimitPreference)
screen.addPreference(imgCDNRateLimitPreference)
screen.addPreference(zhHantPreference)
screen.addPreference(r18Preference)
screen.addPreference(mirrorURLPreference)
}
private fun getShowR18(): Boolean = preferences.getBoolean(SHOW_R18_PREF, false)
@ -723,6 +766,10 @@ class Manhuagui : ConfigurableSource, ParsedHttpSource() {
private const val SHOW_ZH_HANT_WEBSITE_PREF_TITLE = "使用繁体版网站" // "Use traditional chinese version website"
private const val SHOW_ZH_HANT_WEBSITE_PREF_SUMMARY = "需要重启软件以生效。" // "You need to restart Tachiyomi"
private const val USE_MIRROR_URL_PREF = "useMirrorWebsitePreference"
private const val USE_MIRROR_URL_PREF_TITLE = "使用镜像网址"
private const val USE_MIRROR_URL_PREF_SUMMARY = "使用镜像网址: mhgui.com部分漫画可能无法观看。" // "Use mirror url. Some manga may be hidden."
private const val MAINSITE_RATELIMIT_PREF = "mainSiteRatelimitPreference"
private const val MAINSITE_RATELIMIT_PREF_TITLE = "主站每秒连接数限制" // "Ratelimit permits per second for main website"
private const val MAINSITE_RATELIMIT_PREF_SUMMARY = "此值影响更新书架时发起连接请求的数量。调低此值可能减小IP被屏蔽的几率但加载速度也会变慢。需要重启软件以生效。\n当前值:%s" // "This value affects network request amount for updating library. Lower this value may reduce the chance to get IP Ban, but loading speed will be slower too. Tachiyomi restart required."