优化调试

pull/811/head
gedoor 4 years ago
parent 21a20f26a8
commit 6c965d1ebe
  1. 17
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 4
      app/src/main/java/io/legado/app/model/rss/Rss.kt
  3. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  4. 2
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt

@ -16,8 +16,8 @@ import java.text.SimpleDateFormat
import java.util.*
object Debug {
private var debugSource: String? = null
var callback: Callback? = null
private var debugSource: String? = null
private val tasks: CompositeCoroutine = CompositeCoroutine()
@SuppressLint("ConstantLocale")
@ -59,12 +59,12 @@ object Debug {
}
}
fun startDebug(rssSource: RssSource) {
fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug()
debugSource = rssSource.sourceUrl
log(debugSource, "︾开始解析")
val sort = rssSource.sortUrls().entries.first()
Rss.getArticles(sort.key, sort.value, rssSource, 1)
Rss.getArticles(scope, sort.key, sort.value, rssSource, 1)
.onSuccess {
if (it.articles.isEmpty()) {
log(debugSource, "⇒列表页解析成功,为空")
@ -77,7 +77,7 @@ object Debug {
if (ruleContent.isNullOrEmpty()) {
log(debugSource, "⇒内容规则为空,默认获取整个网页", state = 1000)
} else {
rssContentDebug(it.articles[0], ruleContent, rssSource)
rssContentDebug(scope, it.articles[0], ruleContent, rssSource)
}
} else {
log(debugSource, "⇒存在描述规则,不解析内容页")
@ -90,9 +90,14 @@ object Debug {
}
}
private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String, rssSource: RssSource) {
private fun rssContentDebug(
scope: CoroutineScope,
rssArticle: RssArticle,
ruleContent: String,
rssSource: RssSource
) {
log(debugSource, "︾开始解析内容页")
Rss.getContent(rssArticle, ruleContent, rssSource)
Rss.getContent(scope, rssArticle, ruleContent, rssSource)
.onSuccess {
log(debugSource, it)
log(debugSource, "︽内容页解析完成", state = 1000)

@ -14,11 +14,11 @@ import kotlin.coroutines.CoroutineContext
object Rss {
fun getArticles(
scope: CoroutineScope,
sortName: String,
sortUrl: String,
rssSource: RssSource,
page: Int,
scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO
): Coroutine<RssResult> {
return Coroutine.async(scope, context) {
@ -35,10 +35,10 @@ object Rss {
}
fun getContent(
scope: CoroutineScope,
rssArticle: RssArticle,
ruleContent: String,
rssSource: RssSource?,
scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO
): Coroutine<String> {
return Coroutine.async(scope, context) {

@ -30,7 +30,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun loadContent(rssSource: RssSource) {
isLoading = true
page = 1
Rss.getArticles(sortName, sortUrl, rssSource, page)
Rss.getArticles(this, sortName, sortUrl, rssSource, page)
.onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl
it.articles.let { list ->
@ -60,7 +60,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
page++
val pageUrl = nextPageUrl
if (!pageUrl.isNullOrEmpty()) {
Rss.getArticles(sortName, pageUrl, rssSource, page)
Rss.getArticles(this, sortName, pageUrl, rssSource, page)
.onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl
loadMoreSuccess(it.articles)

@ -94,7 +94,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
}
private fun loadContent(rssArticle: RssArticle, ruleContent: String) {
Rss.getContent(rssArticle, ruleContent, rssSource, this)
Rss.getContent(this, rssArticle, ruleContent, rssSource)
.onSuccess(IO) { body ->
rssArticle.description = body
App.db.rssArticleDao.insert(rssArticle)

@ -31,7 +31,7 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
rssSource?.let {
start?.invoke()
Debug.callback = this
Debug.startDebug(it)
Debug.startDebug(this, it)
} ?: error?.invoke()
}

Loading…
Cancel
Save