订阅更书籍一样可以put,get

pull/754/head
gedoor 4 years ago
parent 660ff0132d
commit 1a02f43343
  1. 4
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 4
      app/src/main/java/io/legado/app/data/entities/RssStar.kt
  4. 5
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  5. 18
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  6. 10
      app/src/main/java/io/legado/app/model/analyzeRule/RuleData.kt
  7. 9
      app/src/main/java/io/legado/app/model/analyzeRule/RuleDataInterface.kt
  8. 17
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  9. 13
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  10. 1
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  11. 2
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  12. 1
      app/src/main/java/io/legado/app/model/webBook/BookInfo.kt

@ -1,9 +1,9 @@
package io.legado.app.data.entities
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.splitNotBlank
interface BaseBook : RuleData {
interface BaseBook : RuleDataInterface {
var name: String
var author: String
var bookUrl: String

@ -2,7 +2,7 @@ package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.Ignore
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.IgnoredOnParcel
@ -24,7 +24,7 @@ data class RssArticle(
var image: String? = null,
var read: Boolean = false,
var variable: String? = null
) : RuleData {
) : RuleDataInterface {
override fun hashCode() = link.hashCode()

@ -2,7 +2,7 @@ package io.legado.app.data.entities
import androidx.room.Entity
import androidx.room.Ignore
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.IgnoredOnParcel
@ -23,7 +23,7 @@ data class RssStar(
var content: String? = null,
var image: String? = null,
var variable: String? = null
) : RuleData {
) : RuleDataInterface {
@delegate:Transient
@delegate:Ignore

@ -24,7 +24,8 @@ import kotlin.collections.HashMap
*/
@Keep
@Suppress("unused", "RegExpRedundantEscape")
class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
var book: BaseBook? = null
var chapter: BookChapter? = null
private var content: Any? = null
private var baseUrl: String? = null
@ -606,6 +607,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
fun put(key: String, value: String): String {
chapter?.putVariable(key, value)
?: book?.putVariable(key, value)
?: ruleData.putVariable(key, value)
return value
}
@ -620,6 +622,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
}
return chapter?.variableMap?.get(key)
?: book?.variableMap?.get(key)
?: ruleData.variableMap[key]
?: ""
}

@ -40,6 +40,7 @@ class AnalyzeUrl(
var useWebView: Boolean = false,
val book: BaseBook? = null,
val chapter: BookChapter? = null,
private val ruleData: RuleDataInterface? = null,
headerMapF: Map<String, String>? = null
) : JsExtensions {
companion object {
@ -266,12 +267,25 @@ class AnalyzeUrl(
}
fun put(key: String, value: String): String {
book?.putVariable(key, value)
chapter?.putVariable(key, value)
?: book?.putVariable(key, value)
?: ruleData?.putVariable(key, value)
return value
}
fun get(key: String): String {
return book?.variableMap?.get(key) ?: ""
when (key) {
"bookName" -> book?.let {
return it.name
}
"title" -> chapter?.let {
return it.title
}
}
return chapter?.variableMap?.get(key)
?: book?.variableMap?.get(key)
?: ruleData?.variableMap?.get(key)
?: ""
}
suspend fun getStrResponse(

@ -1,9 +1,13 @@
package io.legado.app.model.analyzeRule
interface RuleData {
class RuleData : RuleDataInterface {
val variableMap: HashMap<String, String>
override val variableMap by lazy {
hashMapOf<String, String>()
}
fun putVariable(key: String, value: String)
override fun putVariable(key: String, value: String) {
variableMap[key] = value
}
}

@ -0,0 +1,9 @@
package io.legado.app.model.analyzeRule
interface RuleDataInterface {
val variableMap: HashMap<String, String>
fun putVariable(key: String, value: String)
}

@ -5,6 +5,7 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleData
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -21,13 +22,15 @@ object Rss {
context: CoroutineContext = Dispatchers.IO
): Coroutine<RssResult> {
return Coroutine.async(scope, context) {
val ruleData = RuleData()
val analyzeUrl = AnalyzeUrl(
sortUrl,
page = page,
ruleData = ruleData,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getStrResponse(rssSource.sourceUrl).body
RssParserByRule.parseXML(sortName, sortUrl, body, rssSource)
RssParserByRule.parseXML(sortName, sortUrl, body, rssSource, ruleData)
}
}
@ -39,12 +42,14 @@ object Rss {
context: CoroutineContext = Dispatchers.IO
): Coroutine<String> {
return Coroutine.async(scope, context) {
val body = AnalyzeUrl(
rssArticle.link, baseUrl = rssArticle.origin,
val analyzeUrl = AnalyzeUrl(
rssArticle.link,
baseUrl = rssArticle.origin,
ruleData = rssArticle,
headerMapF = rssSource?.getHeaderMap()
).getStrResponse(rssArticle.origin)
.body
val analyzeRule = AnalyzeRule()
)
val body = analyzeUrl.getStrResponse(rssArticle.origin).body
val analyzeRule = AnalyzeRule(rssArticle)
analyzeRule.setContent(body)
.setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link))
analyzeRule.getString(ruleContent)

@ -7,6 +7,8 @@ import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.RuleDataInterface
import io.legado.app.utils.GSON
import io.legado.app.utils.NetworkUtils
import java.util.*
@ -18,16 +20,14 @@ object RssParserByRule {
sortName: String,
sortUrl: String,
body: String?,
rssSource: RssSource
rssSource: RssSource,
ruleData: RuleDataInterface
): RssResult {
val sourceUrl = rssSource.sourceUrl
var nextUrl: String? = null
if (body.isNullOrBlank()) {
throw Exception(
App.INSTANCE.getString(
R.string.error_get_web_content,
rssSource.sourceUrl
)
App.INSTANCE.getString(R.string.error_get_web_content, rssSource.sourceUrl)
)
}
Debug.log(sourceUrl, "≡获取成功:$sourceUrl")
@ -37,7 +37,7 @@ object RssParserByRule {
return RssParserDefault.parseXML(sortName, body, sourceUrl)
} else {
val articleList = mutableListOf<RssArticle>()
val analyzeRule = AnalyzeRule()
val analyzeRule = AnalyzeRule(ruleData)
analyzeRule.setContent(body).setBaseUrl(sortUrl)
var reverse = false
if (ruleArticles.startsWith("-")) {
@ -114,6 +114,7 @@ object RssParserByRule {
Debug.log(sourceUrl, "┌获取文章链接", log)
rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink))
Debug.log(sourceUrl, "${rssArticle.link}", log)
rssArticle.variable = GSON.toJson(analyzeRule.ruleData.variableMap)
if (rssArticle.title.isBlank()) {
return null
}

@ -211,6 +211,7 @@ object BookChapterList {
): ChapterData<List<String>> {
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.book = book
val chapterList = arrayListOf<BookChapter>()
val nextUrlList = arrayListOf<String>()
val nextTocRule = tocRule.nextTocUrl

@ -35,6 +35,7 @@ object BookContent {
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
val analyzeRule = AnalyzeRule(book).setContent(body, baseUrl)
analyzeRule.book = book
var contentData = analyzeContent(
book, baseUrl, body, contentRule, bookChapter, bookSource
)
@ -118,6 +119,7 @@ object BookContent {
): ContentData<List<String>> {
val analyzeRule = AnalyzeRule(book)
analyzeRule.setContent(body).setBaseUrl(baseUrl)
analyzeRule.book = book
val nextUrlList = arrayListOf<String>()
analyzeRule.chapter = chapter
val nextUrlRule = contentRule.nextContentUrl

@ -27,6 +27,7 @@ object BookInfo {
Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}")
val infoRule = bookSource.getBookInfoRule()
val analyzeRule = AnalyzeRule(book)
analyzeRule.book = book
analyzeRule.setContent(body).setBaseUrl(baseUrl)
infoRule.init?.let {
if (it.isNotBlank()) {

Loading…
Cancel
Save