pull/32/head
kunfei 5 years ago
parent 273ddf83b1
commit 54c8c55b50
  1. 6
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt

@ -166,10 +166,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
} }
tv_shelf.onClick { tv_shelf.onClick {
if (viewModel.inBookshelf) {
viewModel.delBook {
tv_shelf.text = getString(R.string.add_to_shelf)
}
} else {
viewModel.saveBook { viewModel.saveBook {
tv_shelf.text = getString(R.string.remove_from_bookshelf) tv_shelf.text = getString(R.string.remove_from_bookshelf)
} }
} }
}
tv_loading.onClick { } tv_loading.onClick { }
tv_origin.onClick { tv_origin.onClick {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {

@ -106,6 +106,17 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
chapterListData.value?.let { chapterListData.value?.let {
App.db.bookChapterDao().insert(*it.toTypedArray()) 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 { }.onSuccess {
success?.invoke() success?.invoke()
} }

Loading…
Cancel
Save