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) { class BookSourceEditViewModel(application: Application) : BaseViewModel(application) {
val sourceLiveData: MutableLiveData<BookSource> = MutableLiveData() val sourceLiveData: MutableLiveData<BookSource> = MutableLiveData()
var oldSourceUrl: String? = null private var oldSourceUrl: String? = null
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { 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 { execute {
oldSourceUrl?.let { oldSourceUrl?.let {
if (oldSourceUrl != bookSource.bookSourceUrl) { if (oldSourceUrl != bookSource.bookSourceUrl) {
@ -42,9 +42,12 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
} }
oldSourceUrl = bookSource.bookSourceUrl oldSourceUrl = bookSource.bookSourceUrl
App.db.bookSourceDao().insert(bookSource) App.db.bookSourceDao().insert(bookSource)
}.onFinally { }.onSuccess {
finally?.let { it() } success?.invoke()
} }.onError {
toast(it.localizedMessage)
it.printStackTrace()
}
} }
fun pasteSource() { fun pasteSource() {

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

Loading…
Cancel
Save