From fcc75190211dad154d0ce3f20ad4192f9ffdc70e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 12 Jul 2020 22:20:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 2 +- .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 8 ++++++++ .../legado/app/ui/book/info/edit/BookInfoEditViewModel.kt | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 0e887fad4..09f1e0254 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -352,7 +352,7 @@ class BookInfoActivity : super.onActivityResult(requestCode, resultCode, data) when (requestCode) { requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) { - viewModel.initData(intent) + viewModel.upEditBook() } requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) { viewModel.bookData.value?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 3820f3655..800024cf5 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -226,4 +226,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { success?.invoke() } } + + fun upEditBook() { + bookData.value?.let { + App.db.bookDao().getBook(it.bookUrl)?.let { book -> + bookData.postValue(book) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt index 66602c1d7..a0604035e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book +import io.legado.app.service.help.ReadBook class BookInfoEditViewModel(application: Application) : BaseViewModel(application) { var book: Book? = null @@ -21,6 +22,9 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio fun saveBook(book: Book, success: (() -> Unit)?) { execute { + if (ReadBook.book?.bookUrl == book.bookUrl) { + ReadBook.book = book + } App.db.bookDao().insert(book) }.onSuccess { success?.invoke()