pull/32/head
kunfei 5 years ago
parent 630ceb613f
commit dd5d5e15d0
  1. 22
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -33,6 +33,7 @@ import kotlinx.android.synthetic.main.view_book_page.*
import kotlinx.android.synthetic.main.view_read_menu.*
import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.launch
import org.jetbrains.anko.alert
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
@ -311,6 +312,27 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
override fun finish() {
viewModel.bookData.value?.let {
if (!viewModel.inBookshelf) {
alert {
title = getString(R.string.add_to_shelf)
message = getString(R.string.check_add_bookshelf, it.name)
positiveButton(R.string.yes) {
viewModel.inBookshelf = true
}
negativeButton(R.string.no) {
viewModel.removeFromBookshelf {
super.finish()
}
}
}.show()
} else {
super.finish()
}
} ?: super.finish()
}
override fun observeLiveBus() {
super.observeLiveBus()
observeEvent<Int>(Bus.ALOUD_STATE) { readAloudStatus = it }

@ -189,6 +189,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}
}
fun removeFromBookshelf(success: (() -> Unit)?) {
execute {
bookData.value?.let {
App.db.bookDao().delete(it.bookUrl)
}
}.onSuccess {
success?.invoke()
}
}
fun upBookSource() {
execute {
bookData.value?.let {

Loading…
Cancel
Save