订阅规则下一页规则可以填page

pull/300/head
gedoor 5 years ago
parent d5d844a423
commit 146067fe2f
  1. 2
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 3
      app/src/main/java/io/legado/app/model/Rss.kt
  3. 11
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  4. 12
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -55,7 +55,7 @@ object Debug {
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, null, 1) Rss.getArticles(sort.key, sort.value, rssSource, 1)
.onSuccess { .onSuccess {
if (it.articles.isEmpty()) { if (it.articles.isEmpty()) {
log(debugSource, "⇒列表页解析成功,为空") log(debugSource, "⇒列表页解析成功,为空")

@ -18,14 +18,13 @@ object Rss {
sortName: String, sortName: String,
sortUrl: String, sortUrl: String,
rssSource: RssSource, rssSource: RssSource,
pageUrl: String? = null,
page: Int, page: Int,
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<Result> { ): Coroutine<Result> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl( val analyzeUrl = AnalyzeUrl(
pageUrl ?: sortUrl, sortUrl,
page = page, page = page,
headerMapF = rssSource.getHeaderMap() headerMapF = rssSource.getHeaderMap()
) )

@ -8,6 +8,7 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import java.util.*
@Keep @Keep
object RssParserByRule { object RssParserByRule {
@ -43,9 +44,13 @@ object RssParserByRule {
Debug.log(sourceUrl, "└列表大小:${collections.size}") Debug.log(sourceUrl, "└列表大小:${collections.size}")
if (!rssSource.ruleNextPage.isNullOrEmpty()) { if (!rssSource.ruleNextPage.isNullOrEmpty()) {
Debug.log(sourceUrl, "┌获取下一页链接") Debug.log(sourceUrl, "┌获取下一页链接")
nextUrl = analyzeRule.getString(rssSource.ruleNextPage) if (rssSource.ruleNextPage!!.toUpperCase(Locale.getDefault()) == "PAGE") {
if (nextUrl.isNotEmpty()) { nextUrl = "PAGE"
nextUrl = NetworkUtils.getAbsoluteURL(sortUrl, nextUrl) } else {
nextUrl = analyzeRule.getString(rssSource.ruleNextPage)
if (nextUrl.isNotEmpty()) {
nextUrl = NetworkUtils.getAbsoluteURL(sortUrl, nextUrl)
}
} }
Debug.log(sourceUrl, "$nextUrl") Debug.log(sourceUrl, "$nextUrl")
} }

@ -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, null, page) Rss.getArticles(sortName, sortUrl, rssSource, page)
.onSuccess(Dispatchers.IO) { .onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl nextPageUrl = it.nextPageUrl
it.articles.let { list -> it.articles.let { list ->
@ -49,6 +49,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
isLoading = false isLoading = false
} }
}.onError { }.onError {
it.printStackTrace()
toast(it.localizedMessage) toast(it.localizedMessage)
} }
} }
@ -56,14 +57,19 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun loadMore(rssSource: RssSource) { fun loadMore(rssSource: RssSource) {
isLoading = true isLoading = true
page++ page++
val pageUrl = nextPageUrl val pageUrl = if (nextPageUrl == "PAGE") {
sortUrl
} else {
nextPageUrl
}
if (!pageUrl.isNullOrEmpty()) { if (!pageUrl.isNullOrEmpty()) {
Rss.getArticles(sortName, pageUrl, rssSource, pageUrl, page) Rss.getArticles(sortName, pageUrl, rssSource, page)
.onSuccess(Dispatchers.IO) { .onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl nextPageUrl = it.nextPageUrl
loadMoreSuccess(it.articles) loadMoreSuccess(it.articles)
} }
.onError { .onError {
it.printStackTrace()
loadFinally.postValue(false) loadFinally.postValue(false)
} }
} else { } else {

Loading…
Cancel
Save