|
|
@ -72,17 +72,27 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application |
|
|
|
isLoading = true |
|
|
|
isLoading = true |
|
|
|
val source = rssSource |
|
|
|
val source = rssSource |
|
|
|
val pageUrl = nextPageUrl |
|
|
|
val pageUrl = nextPageUrl |
|
|
|
if (source != null && pageUrl != null) { |
|
|
|
if (source != null && !pageUrl.isNullOrEmpty()) { |
|
|
|
Rss.getArticles(source, pageUrl) |
|
|
|
Rss.getArticles(source, pageUrl) |
|
|
|
.onSuccess(IO) { |
|
|
|
.onSuccess(IO) { |
|
|
|
nextPageUrl = it?.nextPageUrl |
|
|
|
nextPageUrl = it?.nextPageUrl |
|
|
|
it?.articles?.let { list -> |
|
|
|
it?.articles?.let { list -> |
|
|
|
list.forEach { rssArticle -> |
|
|
|
if (list.isEmpty()) { |
|
|
|
rssArticle.order = order-- |
|
|
|
callBack?.loadFinally(false) |
|
|
|
|
|
|
|
return@let |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
callBack?.adapter?.getItems()?.let { adapterItems -> |
|
|
|
|
|
|
|
if (adapterItems.contains(list.first())) { |
|
|
|
|
|
|
|
callBack?.loadFinally(false) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
list.forEach { rssArticle -> |
|
|
|
|
|
|
|
rssArticle.order = order-- |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
App.db.rssArticleDao().insert(*list.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.rssArticleDao().insert(*list.toTypedArray()) |
|
|
|
|
|
|
|
isLoading = false |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
isLoading = false |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
callBack?.loadFinally(false) |
|
|
|
callBack?.loadFinally(false) |
|
|
|