diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 18dde4e00..235ef4d2e 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.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(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(Bus.ALOUD_STATE) { readAloudStatus = it } diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index dedb9b702..45fd04c68 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -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 {