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

pull/300/head
gedoor 4 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
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, "⇒列表页解析成功,为空")

@ -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<Result> {
return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(
pageUrl ?: sortUrl,
sortUrl,
page = page,
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.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")
}

@ -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 {

Loading…
Cancel
Save