From 146067fe2f822de42bc3666f0bc5e78f020e7172 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 8 Aug 2020 21:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E9=98=85=E8=A7=84=E5=88=99=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E9=A1=B5=E8=A7=84=E5=88=99=E5=8F=AF=E4=BB=A5=E5=A1=AB?= =?UTF-8?q?page?= 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 | 2 +- app/src/main/java/io/legado/app/model/Rss.kt | 3 +-- .../java/io/legado/app/model/rss/RssParserByRule.kt | 11 ++++++++--- .../app/ui/rss/article/RssArticlesViewModel.kt | 12 +++++++++--- 4 files changed, 19 insertions(+), 9 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 e9089bf68..85c87812c 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -55,7 +55,7 @@ object Debug { debugSource = rssSource.sourceUrl log(debugSource, "︾开始解析") val sort = rssSource.sortUrls().entries.first() - Rss.getArticles(sort.key, sort.value, rssSource, null, 1) + Rss.getArticles(sort.key, sort.value, rssSource, 1) .onSuccess { if (it.articles.isEmpty()) { log(debugSource, "⇒列表页解析成功,为空") diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index 26cf159b8..7b6d2e266 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -18,14 +18,13 @@ object Rss { sortName: String, sortUrl: String, rssSource: RssSource, - pageUrl: String? = null, page: Int, scope: CoroutineScope = Coroutine.DEFAULT, context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( - pageUrl ?: sortUrl, + sortUrl, page = page, headerMapF = rssSource.getHeaderMap() ) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index cd90b6b1d..105d6200e 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -8,6 +8,7 @@ import io.legado.app.data.entities.RssSource import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.utils.NetworkUtils +import java.util.* @Keep object RssParserByRule { @@ -43,9 +44,13 @@ object RssParserByRule { Debug.log(sourceUrl, "└列表大小:${collections.size}") if (!rssSource.ruleNextPage.isNullOrEmpty()) { Debug.log(sourceUrl, "┌获取下一页链接") - nextUrl = analyzeRule.getString(rssSource.ruleNextPage) - if (nextUrl.isNotEmpty()) { - nextUrl = NetworkUtils.getAbsoluteURL(sortUrl, nextUrl) + if (rssSource.ruleNextPage!!.toUpperCase(Locale.getDefault()) == "PAGE") { + nextUrl = "PAGE" + } else { + nextUrl = analyzeRule.getString(rssSource.ruleNextPage) + if (nextUrl.isNotEmpty()) { + nextUrl = NetworkUtils.getAbsoluteURL(sortUrl, nextUrl) + } } Debug.log(sourceUrl, "└$nextUrl") } 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 19f02511b..8f2e00c12 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, null, page) + Rss.getArticles(sortName, sortUrl, rssSource, page) .onSuccess(Dispatchers.IO) { nextPageUrl = it.nextPageUrl it.articles.let { list -> @@ -49,6 +49,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application isLoading = false } }.onError { + it.printStackTrace() toast(it.localizedMessage) } } @@ -56,14 +57,19 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application fun loadMore(rssSource: RssSource) { isLoading = true page++ - val pageUrl = nextPageUrl + val pageUrl = if (nextPageUrl == "PAGE") { + sortUrl + } else { + nextPageUrl + } if (!pageUrl.isNullOrEmpty()) { - Rss.getArticles(sortName, pageUrl, rssSource, pageUrl, page) + Rss.getArticles(sortName, pageUrl, rssSource, page) .onSuccess(Dispatchers.IO) { nextPageUrl = it.nextPageUrl loadMoreSuccess(it.articles) } .onError { + it.printStackTrace() loadFinally.postValue(false) } } else {