pull/49/head
kunfei 5 years ago
parent 1567131df0
commit 91a56b2943
  1. 3
      app/src/main/java/io/legado/app/model/Rss.kt
  2. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -15,11 +15,12 @@ object Rss {
fun getArticles(
rssSource: RssSource,
page: Int,
scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO
): Coroutine<MutableList<RssArticle>> {
return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(rssSource.sourceUrl)
val analyzeUrl = AnalyzeUrl(rssSource.sourceUrl, page = page)
val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body
RssParserByRule.parseXML(body, rssSource)
}

@ -14,6 +14,7 @@ import kotlinx.coroutines.withContext
class RssArticlesViewModel(application: Application) : BaseViewModel(application) {
var rssSource: RssSource? = null
val titleLiveData = MutableLiveData<String>()
var page = 1
fun loadContent(url: String, onFinally: () -> Unit, loadMore: (() -> Unit)? = null) {
execute {
@ -24,7 +25,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
rssSource = RssSource(sourceUrl = url)
}
rssSource?.let { rssSource ->
Rss.getArticles(rssSource, this)
Rss.getArticles(rssSource, page, this)
.onSuccess {
it?.let {
withContext(IO) {
@ -51,6 +52,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
fun clear(url: String, onFinally: () -> Unit) {
execute {
App.db.rssArticleDao().delete(url)
page = 1
loadContent(url, onFinally)
}
}

Loading…
Cancel
Save