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( fun getArticles(
rssSource: RssSource, rssSource: RssSource,
page: Int,
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope = Coroutine.DEFAULT,
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<MutableList<RssArticle>> { ): Coroutine<MutableList<RssArticle>> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val analyzeUrl = AnalyzeUrl(rssSource.sourceUrl) val analyzeUrl = AnalyzeUrl(rssSource.sourceUrl, page = page)
val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body
RssParserByRule.parseXML(body, rssSource) RssParserByRule.parseXML(body, rssSource)
} }

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

Loading…
Cancel
Save