pull/467/head
gedoor 4 years ago
parent 55aedfecee
commit 46b8e236c7
  1. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  2. 1
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  4. 26
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt

@ -103,14 +103,14 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
} }
override fun observeLiveBus() { override fun observeLiveBus() {
viewModel.loadFinally.observe(viewLifecycleOwner, { viewModel.loadFinally.observe(viewLifecycleOwner) {
refresh_recycler_view.stopLoading() refresh_recycler_view.stopLoading()
if (it) { if (it) {
loadMoreView.startLoad() loadMoreView.startLoad()
} else { } else {
loadMoreView.noMore() loadMoreView.noMore()
} }
}) }
} }
override fun readRss(rssArticle: RssArticle) { override fun readRss(rssArticle: RssArticle) {

@ -49,6 +49,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
isLoading = false isLoading = false
} }
}.onError { }.onError {
loadFinally.postValue(true)
it.printStackTrace() it.printStackTrace()
toast(it.localizedMessage) toast(it.localizedMessage)
} }

@ -136,7 +136,7 @@ class RssSourceEditActivity :
} }
private fun getRssSource(): RssSource { private fun getRssSource(): RssSource {
val source = viewModel.rssSource?.copy() ?: RssSource() val source = viewModel.rssSource
source.enabled = cb_is_enable.isChecked source.enabled = cb_is_enable.isChecked
source.enableJs = cb_enable_js.isChecked source.enableJs = cb_enable_js.isChecked
source.loadWithBaseUrl = cb_enable_base_url.isChecked source.loadWithBaseUrl = cb_enable_base_url.isChecked

@ -8,24 +8,23 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getClipText import io.legado.app.utils.getClipText
import io.legado.app.utils.msg
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
var rssSource: RssSource? = null var rssSource: RssSource = RssSource()
private var oldSourceUrl: String? = null private var oldSourceUrl: String = ""
fun initData(intent: Intent, onFinally: () -> Unit) { fun initData(intent: Intent, onFinally: () -> Unit) {
execute { execute {
val key = intent.getStringExtra("data") val key = intent.getStringExtra("data")
var source: RssSource? = null
if (key != null) { if (key != null) {
source = App.db.rssSourceDao().getByKey(key) App.db.rssSourceDao().getByKey(key)?.let {
} rssSource = it
source?.let { }
oldSourceUrl = it.sourceUrl
rssSource = it
} }
oldSourceUrl = rssSource.sourceUrl
}.onFinally { }.onFinally {
onFinally() onFinally()
} }
@ -33,14 +32,11 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
fun save(source: RssSource, success: (() -> Unit)) { fun save(source: RssSource, success: (() -> Unit)) {
execute { execute {
oldSourceUrl?.let { if (oldSourceUrl != source.sourceUrl) {
if (oldSourceUrl != source.sourceUrl) { App.db.rssSourceDao().delete(oldSourceUrl)
App.db.rssSourceDao().delete(it) oldSourceUrl = source.sourceUrl
}
} }
oldSourceUrl = source.sourceUrl
App.db.rssSourceDao().insert(source) App.db.rssSourceDao().insert(source)
rssSource = source
}.onSuccess { }.onSuccess {
success() success()
}.onError { }.onError {
@ -74,7 +70,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
finally.invoke(it) finally.invoke(it)
} }
}.onError { }.onError {
toast(it.localizedMessage ?: "Error") toast(it.msg)
} }
} }

Loading…
Cancel
Save