From fa7f69c5efe3d2e1c96141c18a15509a574d24f5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 27 May 2021 10:57:16 +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 --- .../io/legado/app/ui/book/info/BookInfoActivity.kt | 2 ++ .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 10 ++++++++++ 2 files changed, 12 insertions(+) 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 de21ed9b5..51d23caaa 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 @@ -55,6 +55,7 @@ class BookInfoActivity : viewModel.bookData.value?.let { book -> launch { withContext(IO) { + viewModel.durChapterIndex = it.first book.durChapterIndex = it.first book.durChapterPos = it.second appDb.bookDao.update(book) @@ -75,6 +76,7 @@ class BookInfoActivity : private val readBookResult = registerForActivityResult( ActivityResultContracts.StartActivityForResult() ) { + viewModel.refreshData(intent) if (it.resultCode == RESULT_OK) { viewModel.inBookshelf = true upTvBookshelf() 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 f6fb03b3b..0db62f64a 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 @@ -35,6 +35,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } + fun refreshData(intent: Intent) { + execute { + val name = intent.getStringExtra("name") ?: "" + val author = intent.getStringExtra("author") ?: "" + appDb.bookDao.getBook(name, author)?.let { book -> + setBook(book) + } + } + } + private fun setBook(book: Book) { durChapterIndex = book.durChapterIndex bookData.postValue(book)