diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 61cc49858..d50601117 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -13,7 +13,7 @@ import io.legado.app.help.storage.OldRule class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { val sourceLiveData: MutableLiveData = 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() { 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 8b0f2cd11..38fb18e98 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 @@ -14,7 +14,7 @@ import io.legado.app.utils.fromJsonObject class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { val sourceLiveData: MutableLiveData = 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() } }