订阅规则支持页数

pull/300/head
gedoor 4 years ago
parent c9d9c22469
commit 3b77b4ef55
  1. 2
      app/src/main/java/io/legado/app/model/Rss.kt
  2. 6
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -19,12 +19,14 @@ object Rss {
sortUrl: String, sortUrl: String,
rssSource: RssSource, rssSource: RssSource,
pageUrl: String? = null, pageUrl: String? = null,
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, pageUrl ?: sortUrl,
page = page,
headerMapF = rssSource.getHeaderMap() headerMapF = rssSource.getHeaderMap()
) )
val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body

@ -18,6 +18,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
private var nextPageUrl: String? = null private var nextPageUrl: String? = null
var sortName: String = "" var sortName: String = ""
var sortUrl: String = "" var sortUrl: String = ""
var page = 1
fun init(bundle: Bundle?) { fun init(bundle: Bundle?) {
bundle?.let { bundle?.let {
@ -29,7 +30,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun loadContent(rssSource: RssSource) { fun loadContent(rssSource: RssSource) {
isLoading = true isLoading = true
Rss.getArticles(sortName, sortUrl, rssSource, null) Rss.getArticles(sortName, sortUrl, rssSource, null, 1)
.onSuccess(Dispatchers.IO) { .onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl nextPageUrl = it.nextPageUrl
it.articles.let { list -> it.articles.let { list ->
@ -54,9 +55,10 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun loadMore(rssSource: RssSource) { fun loadMore(rssSource: RssSource) {
isLoading = true isLoading = true
page++
val pageUrl = nextPageUrl val pageUrl = nextPageUrl
if (!pageUrl.isNullOrEmpty()) { if (!pageUrl.isNullOrEmpty()) {
Rss.getArticles(sortName, pageUrl, rssSource, pageUrl) Rss.getArticles(sortName, pageUrl, rssSource, pageUrl, page)
.onSuccess(Dispatchers.IO) { .onSuccess(Dispatchers.IO) {
nextPageUrl = it.nextPageUrl nextPageUrl = it.nextPageUrl
loadMoreSuccess(it.articles) loadMoreSuccess(it.articles)

Loading…
Cancel
Save