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 f9b684592..00efa768b 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 @@ -103,14 +103,14 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme } override fun observeLiveBus() { - viewModel.loadFinally.observe(viewLifecycleOwner, { + viewModel.loadFinally.observe(viewLifecycleOwner) { refresh_recycler_view.stopLoading() if (it) { loadMoreView.startLoad() } else { loadMoreView.noMore() } - }) + } } override fun readRss(rssArticle: RssArticle) { 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 44f125ef2..a1a79121b 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 @@ -49,6 +49,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application isLoading = false } }.onError { + loadFinally.postValue(true) it.printStackTrace() toast(it.localizedMessage) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 34b795a2b..cf21ca604 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -136,7 +136,7 @@ class RssSourceEditActivity : } private fun getRssSource(): RssSource { - val source = viewModel.rssSource?.copy() ?: RssSource() + val source = viewModel.rssSource source.enabled = cb_is_enable.isChecked source.enableJs = cb_enable_js.isChecked source.loadWithBaseUrl = cb_enable_base_url.isChecked diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 88a9a78dd..04e0da7c0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -8,24 +8,23 @@ import io.legado.app.data.entities.RssSource import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import io.legado.app.utils.getClipText +import io.legado.app.utils.msg import kotlinx.coroutines.Dispatchers class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { - var rssSource: RssSource? = null - private var oldSourceUrl: String? = null + var rssSource: RssSource = RssSource() + private var oldSourceUrl: String = "" fun initData(intent: Intent, onFinally: () -> Unit) { execute { val key = intent.getStringExtra("data") - var source: RssSource? = null if (key != null) { - source = App.db.rssSourceDao().getByKey(key) - } - source?.let { - oldSourceUrl = it.sourceUrl - rssSource = it + App.db.rssSourceDao().getByKey(key)?.let { + rssSource = it + } } + oldSourceUrl = rssSource.sourceUrl }.onFinally { onFinally() } @@ -33,14 +32,11 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati fun save(source: RssSource, success: (() -> Unit)) { execute { - oldSourceUrl?.let { - if (oldSourceUrl != source.sourceUrl) { - App.db.rssSourceDao().delete(it) - } + if (oldSourceUrl != source.sourceUrl) { + App.db.rssSourceDao().delete(oldSourceUrl) + oldSourceUrl = source.sourceUrl } - oldSourceUrl = source.sourceUrl App.db.rssSourceDao().insert(source) - rssSource = source }.onSuccess { success() }.onError { @@ -74,7 +70,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati finally.invoke(it) } }.onError { - toast(it.localizedMessage ?: "Error") + toast(it.msg) } }