diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index c8f70d16e..c74597e74 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -19,6 +19,20 @@ data class RssArticle( var read: Boolean = false ) { + override fun hashCode(): Int { + return super.hashCode() + } + + override fun equals(other: Any?): Boolean { + if (other == null) { + return false + } + if (other is RssArticle) { + return origin == other.origin && link == other.link + } + return false + } + fun toStar(): RssStar { return RssStar( origin = origin, diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 3c1c71220..8a93301b9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -72,17 +72,27 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application isLoading = true val source = rssSource val pageUrl = nextPageUrl - if (source != null && pageUrl != null) { + if (source != null && !pageUrl.isNullOrEmpty()) { Rss.getArticles(source, pageUrl) .onSuccess(IO) { nextPageUrl = it?.nextPageUrl it?.articles?.let { list -> - list.forEach { rssArticle -> - rssArticle.order = order-- + if (list.isEmpty()) { + 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 { callBack?.loadFinally(false)