优化调试

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

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

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

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

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

Loading…
Cancel
Save