Hanime1:Add subtitle preference setting.

This commit is contained in:
ZhendongWu 2025-03-22 12:42:53 +08:00
parent 430ec3f5ad
commit 952e90f592

View file

@ -24,6 +24,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Cookie
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.Request
@ -287,25 +288,50 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
}
override fun setupPreferenceScreen(screen: PreferenceScreen) {
screen.addPreference(
ListPreference(screen.context).apply {
key = PREF_KEY_VIDEO_QUALITY
title = "設置首選畫質"
entries = arrayOf("1080P", "720P", "480P")
entryValues = entries
setDefaultValue(DEFAULT_QUALITY)
summary =
"當前選擇:${preferences.getString(PREF_KEY_VIDEO_QUALITY, DEFAULT_QUALITY)}"
setOnPreferenceChangeListener { _, newValue ->
summary = "當前選擇:${newValue as String}"
true
}
},
)
screen.apply {
addPreference(
ListPreference(context).apply {
key = PREF_KEY_VIDEO_QUALITY
title = "設置首選畫質"
entries = arrayOf("1080P", "720P", "480P")
entryValues = entries
setDefaultValue(DEFAULT_QUALITY)
summary =
"當前選擇:${preferences.getString(PREF_KEY_VIDEO_QUALITY, DEFAULT_QUALITY)}"
setOnPreferenceChangeListener { _, newValue ->
summary = "當前選擇:${newValue as String}"
true
}
},
)
addPreference(
ListPreference(context).apply {
key = PREF_KEY_LANG
title = "設置首選語言"
summary = "該設置僅影響影片字幕"
entries = arrayOf("繁體中文", "簡體中文")
entryValues = arrayOf("zh-CHT", "zh-CHS")
setOnPreferenceChangeListener { _, newValue ->
val baseHttpUrl = baseUrl.toHttpUrl()
client.cookieJar.saveFromResponse(
baseHttpUrl,
listOf(
Cookie.parse(
baseHttpUrl,
"user_lang=${newValue as String}",
)!!,
),
)
true
}
},
)
}
}
companion object {
const val PREF_KEY_VIDEO_QUALITY = "PREF_KEY_VIDEO_QUALITY"
const val PREF_KEY_LANG = "PREF_KEY_LANG"
const val PREF_KEY_GENRE_LIST = "PREF_KEY_GENRE_LIST"
const val PREF_KEY_SORT_LIST = "PREF_KEY_SORT_LIST"