Happymh: check override user agent (#15880)

This commit is contained in:
stevenyomi 2023-04-01 23:57:13 +08:00 committed by GitHub
parent b3fce539b1
commit 6d6a51d2a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Happymh'
pkgNameSuffix = 'zh.happymh'
extClass = '.Happymh'
extVersionCode = 3
extVersionCode = 4
}
apply from: "$rootDir/common.gradle"

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.extension.zh.happymh
import android.app.Application
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.network.GET
@ -139,10 +140,22 @@ class Happymh : HttpSource(), ConfigurableSource {
override fun imageUrlParse(response: Response): String = throw Exception("Not Used")
override fun setupPreferenceScreen(screen: PreferenceScreen) {
EditTextPreference(screen.context).apply {
val context = screen.context
EditTextPreference(context).apply {
key = USER_AGENT_PREF
title = "User Agent"
summary = "留空则使用应用设置中的默认 User Agent"
summary = "留空则使用应用设置中的默认 User Agent重启生效"
setOnPreferenceChangeListener { _, newValue ->
try {
Headers.Builder().add("User-Agent", newValue as String)
true
} catch (e: Throwable) {
Toast.makeText(context, "User Agent 无效:${e.message}", Toast.LENGTH_LONG).show()
false
}
}
}.let(screen::addPreference)
}