From 54c8c55b50fbf48971caf028a3e6a51ed781157a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 22 Aug 2019 08:28:44 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/bookinfo/BookInfoActivity.kt | 10 ++++++++-- .../io/legado/app/ui/bookinfo/BookInfoViewModel.kt | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index 88db8e75b..a6ff40a57 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -166,8 +166,14 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } } tv_shelf.onClick { - viewModel.saveBook { - tv_shelf.text = getString(R.string.remove_from_bookshelf) + if (viewModel.inBookshelf) { + viewModel.delBook { + tv_shelf.text = getString(R.string.add_to_shelf) + } + } else { + viewModel.saveBook { + tv_shelf.text = getString(R.string.remove_from_bookshelf) + } } } tv_loading.onClick { } diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index a4f7a1b53..fdc13bb8c 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -106,6 +106,17 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { chapterListData.value?.let { App.db.bookChapterDao().insert(*it.toTypedArray()) } + inBookshelf = true + }.onSuccess { + success?.invoke() + } + } + + fun delBook(success: (() -> Unit)?) { + execute { + bookData.value?.let { + App.db.bookDao().delete(it.bookUrl) + } }.onSuccess { success?.invoke() }