RssSource.kt: Modify functions into assigning style

Signed-off-by: 1552980358 <1552980358@qq.com>
pull/369/head
1552980358 4 years ago
parent 011b7c8255
commit 7005ad9291
  1. 41
      app/src/main/java/io/legado/app/data/entities/RssSource.kt

@ -43,45 +43,33 @@ data class RssSource(
var customOrder: Int = 0
): Parcelable, JsExtensions {
override fun equals(other: Any?): Boolean {
if (other is RssSource) {
return other.sourceUrl == sourceUrl
}
return false
}
override fun equals(other: Any?) = if (other is RssSource) other.sourceUrl == sourceUrl else false
override fun hashCode(): Int {
return sourceUrl.hashCode()
}
override fun hashCode() = sourceUrl.hashCode()
@Throws(Exception::class)
fun getHeaderMap(): Map<String, String> {
val headerMap = HashMap<String, String>()
headerMap[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: AppConst.userAgent
fun getHeaderMap() = HashMap<String, String>().apply {
this[AppConst.UA_NAME] = App.INSTANCE.getPrefString("user_agent") ?: AppConst.userAgent
header?.let {
val header1 = when {
GSON.fromJsonObject<Map<String, String>>(
when {
it.startsWith("@js:", true) ->
evalJS(it.substring(4)).toString()
it.startsWith("<js>", true) ->
evalJS(it.substring(4, it.lastIndexOf("<"))).toString()
else -> it
}
GSON.fromJsonObject<Map<String, String>>(header1)?.let { map ->
headerMap.putAll(map)
)?.let { map ->
putAll(map)
}
}
return headerMap
}
/**
* 执行JS
*/
@Throws(Exception::class)
private fun evalJS(jsStr: String): Any {
val bindings = SimpleBindings()
bindings["java"] = this
return AppConst.SCRIPT_ENGINE.eval(jsStr, bindings)
}
private fun evalJS(jsStr: String): Any = AppConst.SCRIPT_ENGINE.eval(jsStr, SimpleBindings().apply { this["java"] = this@RssSource })
fun equal(source: RssSource): Boolean {
return equal(sourceUrl, source.sourceUrl)
@ -103,16 +91,15 @@ data class RssSource(
return a == b || (a.isNullOrEmpty() && b.isNullOrEmpty())
}
fun sortUrls(): LinkedHashMap<String, String> {
val sortMap = linkedMapOf<String, String>()
fun sortUrls(): LinkedHashMap<String, String> =
linkedMapOf<String, String>().apply {
sortUrl?.split("(&&|\n)+".toRegex())?.forEach { c ->
val d = c.split("::")
if (d.size > 1)
sortMap[d[0]] = d[1]
this[d[0]] = d[1]
}
if (sortMap.isEmpty()) {
sortMap[""] = sourceUrl
if (isEmpty()) {
this[""] = sourceUrl
}
return sortMap
}
}
Loading…
Cancel
Save