From 6c965d1ebee37cf43abe3bcc89ceb084b24e6ea7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 15 Jan 2021 21:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/Debug.kt | 17 +++++++++++------ .../main/java/io/legado/app/model/rss/Rss.kt | 4 ++-- .../app/ui/rss/article/RssArticlesViewModel.kt | 4 ++-- .../legado/app/ui/rss/read/ReadRssViewModel.kt | 2 +- .../ui/rss/source/debug/RssSourceDebugModel.kt | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index ec3d31097..c74a36b5e 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.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) diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index afa6c06fd..71aa5b2b3 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -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 { 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 { return Coroutine.async(scope, context) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 5d5008145..1196e2ebd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 0c09f71e6..452f8c87f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt index 2d069deab..d903da070 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt @@ -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() }