pull/38/head
kunfei 5 years ago
parent a0d6c9f842
commit c0cc09822d
  1. 13
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  2. 3
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt

@ -13,7 +13,7 @@ import io.legado.app.help.storage.OldRule
class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
val sourceLiveData: MutableLiveData<BookSource> = MutableLiveData()
var oldSourceUrl: String? = null
private var oldSourceUrl: String? = null
fun initData(intent: Intent) {
execute {
@ -33,7 +33,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
}
}
fun save(bookSource: BookSource, finally: (() -> Unit)? = null) {
fun save(bookSource: BookSource, success: (() -> Unit)? = null) {
execute {
oldSourceUrl?.let {
if (oldSourceUrl != bookSource.bookSourceUrl) {
@ -42,9 +42,12 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
}
oldSourceUrl = bookSource.bookSourceUrl
App.db.bookSourceDao().insert(bookSource)
}.onFinally {
finally?.let { it() }
}
}.onSuccess {
success?.invoke()
}.onError {
toast(it.localizedMessage)
it.printStackTrace()
}
}
fun pasteSource() {

@ -14,7 +14,7 @@ import io.legado.app.utils.fromJsonObject
class RssSourceEditViewModel(application: Application) : BaseViewModel(application) {
val sourceLiveData: MutableLiveData<RssSource> = MutableLiveData()
var oldSourceUrl: String? = null
private var oldSourceUrl: String? = null
fun initData(intent: Intent) {
execute {
@ -47,6 +47,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
success()
}.onError {
toast(it.localizedMessage)
it.printStackTrace()
}
}

Loading…
Cancel
Save