@ -166,8 +166,14 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(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 {
tv_loading.onClick { }
@ -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)