订阅规则支持页数

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,
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,
page = page,
headerMapF = rssSource.getHeaderMap()
)
val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body

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

Loading…
Cancel
Save