pull/49/head
kunfei 5 years ago
parent 721a263b00
commit 946cf45393
  1. 26
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 21
      app/src/main/java/io/legado/app/model/Rss.kt
  3. 19
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -3,6 +3,7 @@ package io.legado.app.model
import android.annotation.SuppressLint
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.utils.htmlFormat
@ -55,15 +56,34 @@ object Debug {
log(debugSource, "︾开始解析RSS")
Rss.getArticles(rssSource)
.onSuccess {
log(debugSource, "︽正文页解析完成", state = 1000)
if (it == null) {
log(debugSource, "︽解析失败", state = -1)
} else {
val ruleContent = rssSource.ruleContent
if (it.isNotEmpty() && it[0].description.isNullOrEmpty() && !ruleContent.isNullOrEmpty()) {
log(debugSource, "︽解析完成")
log(debugSource, showTime = false)
rssContentDebug(it[0], ruleContent)
} else {
log(debugSource, "︽解析完成", state = 1000)
}
}
}
.onError {
log(debugSource, it.localizedMessage, state = -1)
}
}
private fun rssContentDebug() {
private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String) {
log(debugSource, "︾开始解析内容")
Rss.getContent(rssArticle, ruleContent)
.onSuccess {
log(debugSource, it)
log(debugSource, "︽解析完成", state = 1000)
}
.onError {
log(debugSource, it.localizedMessage, state = -1)
}
}
fun startDebug(webBook: WebBook, key: String) {

@ -3,8 +3,10 @@ package io.legado.app.model
import io.legado.app.data.entities.RssArticle
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.RssParserByRule
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext
@ -22,4 +24,23 @@ object Rss {
RssParserByRule.parseXML(body, rssSource)
}
}
fun getContent(
rssArticle: RssArticle,
ruleContent: String,
scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO
): Coroutine<String> {
return Coroutine.async(scope, context) {
val body = AnalyzeUrl(rssArticle.link, baseUrl = rssArticle.origin)
.getResponseAwait()
.body
val analyzeRule = AnalyzeRule()
analyzeRule.setContent(
body,
NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link)
)
analyzeRule.getString(ruleContent)
}
}
}

@ -7,9 +7,8 @@ import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.Rss
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
var rssSource: RssSource? = null
@ -53,20 +52,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
}
private fun loadContent(rssArticle: RssArticle, ruleContent: String) {
execute {
val body = AnalyzeUrl(rssArticle.link, baseUrl = rssArticle.origin)
.getResponseAwait()
.body
AnalyzeRule().apply {
setContent(
body,
NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link)
)
getString(ruleContent).let { content ->
contentLiveData.postValue(content)
}
Rss.getContent(rssArticle, ruleContent, this)
.onSuccess {
contentLiveData.postValue(it)
}
}
}
fun upRssArticle(rssArticle: RssArticle, success: () -> Unit) {

Loading…
Cancel
Save