mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -59,7 +59,6 @@ interface BaseSource : JsExtensions {
|
||||
* 解析header规则
|
||||
*/
|
||||
fun getHeaderMap(hasLoginHeader: Boolean = false) = HashMap<String, String>().apply {
|
||||
this[AppConst.UA_NAME] = AppConfig.userAgent
|
||||
header?.let {
|
||||
GSON.fromJsonObject<Map<String, String>>(
|
||||
when {
|
||||
@@ -73,6 +72,9 @@ interface BaseSource : JsExtensions {
|
||||
putAll(map)
|
||||
}
|
||||
}
|
||||
if (!has(AppConst.UA_NAME, true)) {
|
||||
put(AppConst.UA_NAME, AppConfig.userAgent)
|
||||
}
|
||||
if (hasLoginHeader) {
|
||||
getLoginHeaderMap()?.let {
|
||||
putAll(it)
|
||||
|
||||
19
app/src/main/java/io/legado/app/utils/MapExtensions.kt
Normal file
19
app/src/main/java/io/legado/app/utils/MapExtensions.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
fun HashMap<String, *>.has(key: String, ignoreCase: Boolean = false): Boolean {
|
||||
for (item in this) {
|
||||
if (key.equals(item.key, ignoreCase)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun HashMap<String, *>.get(key: String, ignoreCase: Boolean = false): Any? {
|
||||
for (item in this) {
|
||||
if (key.equals(item.key, ignoreCase)) {
|
||||
return item.value
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user