pull/32/head
kunfei 5 years ago
parent b7798d8910
commit 33a0424a33
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 7
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt

@ -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)
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapter(book)
}
}
}
fun saveBook(success: (() -> Unit)?) {
execute {
bookData.value?.let { book ->

Loading…
Cancel
Save