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() {
viewModel.loadFinally.observe(viewLifecycleOwner, {
viewModel.loadFinally.observe(viewLifecycleOwner) {
refresh_recycler_view.stopLoading()
if (it) {
loadMoreView.startLoad()
} else {
loadMoreView.noMore()
}
})
}
}
override fun readRss(rssArticle: RssArticle) {

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

@ -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

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

Loading…
Cancel
Save