From bf9f9791067ac571e210df01e92da099a20914cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 3 May 2020 12:28:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/RssArticle.kt | 2 +- .../app/ui/rss/article/RssArticlesViewModel.kt | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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 15dafa3ab..d9ae5531b 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 @@ -21,7 +21,7 @@ data class RssArticle( ) { override fun hashCode(): Int { - return super.hashCode() + return link.hashCode() } override fun equals(other: Any?): Boolean { 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 3bcfc00ab..4a7c66cf7 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 @@ -5,7 +5,6 @@ import android.os.Bundle import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss import kotlinx.coroutines.Dispatchers @@ -16,7 +15,6 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application var isLoading = true var order = System.currentTimeMillis() private var nextPageUrl: String? = null - private val articles = arrayListOf() var sortName: String = "" var sortUrl: String = "" @@ -62,10 +60,13 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application nextPageUrl = it.nextPageUrl it.articles.let { list -> if (list.isEmpty()) { - loadFinally.postValue(true) + loadFinally.postValue(false) return@let } - if (articles.contains(list.first())) { + val firstArticle = list.first() + if (App.db.rssArticleDao() + .get(firstArticle.origin, firstArticle.link) != null + ) { loadFinally.postValue(false) } else { list.forEach { rssArticle -> @@ -76,6 +77,9 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } isLoading = false } + .onError { + loadFinally.postValue(false) + } } else { loadFinally.postValue(false) }