feat: 优化

pull/209/head
kunfei 5 years ago
parent 718f312d1d
commit bf9f979106
  1. 2
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  2. 12
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -21,7 +21,7 @@ data class RssArticle(
) {
override fun hashCode(): Int {
return super.hashCode()
return link.hashCode()
}
override fun equals(other: Any?): Boolean {

@ -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<RssArticle>()
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)
}

Loading…
Cancel
Save