feat: 优化代码

pull/182/head
kunfei 5 years ago
parent 677b99a6f1
commit 05ea83a3d1
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -42,6 +42,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE bookUrl = :bookUrl")
fun getBook(bookUrl: String): Book?
@Query("SELECT * FROM books WHERE name = :name and author = :author")
fun getBook(name: String, author: String): Book?
@get:Query("SELECT * FROM books where origin <> '${BookType.local}' and type = 0")
val webBooks: List<Book>

@ -171,6 +171,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.order == 0) {
book.order = App.db.bookDao().maxOrder + 1
}
App.db.bookDao().getBook(book.name, book.author)?.let {
book.durChapterPos = it.durChapterPos
book.durChapterTitle = it.durChapterTitle
}
App.db.bookDao().insert(book)
}
}.onSuccess {
@ -194,6 +198,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.order == 0) {
book.order = App.db.bookDao().maxOrder + 1
}
App.db.bookDao().getBook(book.name, book.author)?.let {
book.durChapterPos = it.durChapterPos
book.durChapterTitle = it.durChapterTitle
}
App.db.bookDao().insert(book)
}
chapterListData.value?.let {

Loading…
Cancel
Save