@ -47,4 +47,7 @@ interface BookDao {
@Update
fun update(vararg books: Book)
@Query("delete from books where bookUrl = :bookUrl")
fun delete(bookUrl: String)
}
@ -190,12 +190,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override fun changeTo(book: Book) {
viewModel.bookData.postValue(book)
if (book.tocUrl.isEmpty()) {
viewModel.loadBookInfo(book)
} else {
viewModel.loadChapter(book)
viewModel.changeTo(book)
override fun skipToChapter(index: Int) {
@ -81,6 +81,23 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(book: Book) {
execute {
if (inBookshelf) {
bookData.value?.let {
App.db.bookDao().delete(it.bookUrl)
App.db.bookDao().insert(book)
bookData.postValue(book)
loadBookInfo(book)
loadChapter(book)
fun saveBook(success: (() -> Unit)?) {
bookData.value?.let { book ->