From c0528dc0b5b34c9a499be9f778959ad2036ef83a Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Tue, 25 Oct 2022 15:40:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/rss/article/RssArticlesFragment.kt | 6 ++---- .../io/legado/app/ui/rss/article/RssArticlesViewModel.kt | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index 1e2e09e8e..ec104c359 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -125,11 +125,9 @@ class RssArticlesFragment() : VMBaseFragment(R.layout.frag viewModel.loadErrorLiveData.observe(viewLifecycleOwner) { loadMoreView.error(it) } - viewModel.loadFinallyLiveData.observe(viewLifecycleOwner) { + viewModel.loadFinallyLiveData.observe(viewLifecycleOwner) { hasMore -> binding.refreshLayout.isRefreshing = false - if (it) { - loadMoreView.stopLoad() - } else { + if (!hasMore) { loadMoreView.noMore() } } 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 c8555bbb3..721a1d54c 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 @@ -35,6 +35,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application fun loadContent(rssSource: RssSource) { isLoading = true page = 1 + order = System.currentTimeMillis() Rss.getArticles(viewModelScope, sortName, sortUrl, rssSource, page) .onSuccess(Dispatchers.IO) { nextPageUrl = it.second @@ -45,12 +46,9 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application appDb.rssArticleDao.insert(*list.toTypedArray()) if (!rssSource.ruleNextPage.isNullOrEmpty()) { appDb.rssArticleDao.clearOld(rssSource.sourceUrl, sortName, order) - loadFinallyLiveData.postValue(true) - } else { - withContext(Dispatchers.Main) { - loadFinallyLiveData.postValue(false) - } } + val hasMore = list.isNotEmpty() && !rssSource.ruleNextPage.isNullOrEmpty() + loadFinallyLiveData.postValue(hasMore) isLoading = false } }.onError {