pull/433/head
gedoor 4 years ago
parent eabc8a2d92
commit 9f63cff7f4
  1. 5
      app/src/main/java/io/legado/app/model/rss/Result.kt
  2. 4
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  3. 11
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  4. 6
      app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt
  5. 5
      app/src/main/java/io/legado/app/model/rss/RssResult.kt

@ -1,5 +0,0 @@
package io.legado.app.model.rss
import io.legado.app.data.entities.RssArticle
data class Result(val articles: MutableList<RssArticle>, val nextPageUrl: String?)

@ -5,8 +5,6 @@ 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.rss.Result
import io.legado.app.model.rss.RssParserByRule
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -21,7 +19,7 @@ object Rss {
page: Int,
scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO
): Coroutine<Result> {
): Coroutine<RssResult> {
return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(
sortUrl,

@ -14,7 +14,12 @@ import java.util.*
object RssParserByRule {
@Throws(Exception::class)
fun parseXML(sortName: String, sortUrl: String, body: String?, rssSource: RssSource): Result {
fun parseXML(
sortName: String,
sortUrl: String,
body: String?,
rssSource: RssSource
): RssResult {
val sourceUrl = rssSource.sourceUrl
var nextUrl: String? = null
if (body.isNullOrBlank()) {
@ -29,7 +34,7 @@ object RssParserByRule {
var ruleArticles = rssSource.ruleArticles
if (ruleArticles.isNullOrBlank()) {
Debug.log(sourceUrl, "⇒列表规则为空, 使用默认规则解析")
return RssParser.parseXML(sortName, body, sourceUrl)
return RssParserDefault.parseXML(sortName, body, sourceUrl)
} else {
val articleList = mutableListOf<RssArticle>()
val analyzeRule = AnalyzeRule()
@ -72,7 +77,7 @@ object RssParserByRule {
if (reverse) {
articleList.reverse()
}
return Result(articleList, nextUrl)
return RssResult(articleList, nextUrl)
}
}

@ -8,10 +8,10 @@ import org.xmlpull.v1.XmlPullParserFactory
import java.io.IOException
import java.io.StringReader
object RssParser {
object RssParserDefault {
@Throws(XmlPullParserException::class, IOException::class)
fun parseXML(sortName: String, xml: String, sourceUrl: String): Result {
fun parseXML(sortName: String, xml: String, sourceUrl: String): RssResult {
val articleList = mutableListOf<RssArticle>()
var currentArticle = RssArticle()
@ -105,7 +105,7 @@ object RssParser {
Debug.log(sourceUrl, "┌获取文章链接")
Debug.log(sourceUrl, "${it.link}")
}
return Result(articleList, null)
return RssResult(articleList, null)
}
/**

@ -0,0 +1,5 @@
package io.legado.app.model.rss
import io.legado.app.data.entities.RssArticle
data class RssResult(val articles: MutableList<RssArticle>, val nextPageUrl: String?)
Loading…
Cancel
Save