feat: 优化代码

pull/173/head
kunfei 5 years ago
parent cdfb24e833
commit 56704f1d11
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt

@ -33,6 +33,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'")
fun liveDataSearch(key: String): LiveData<List<Book>> fun liveDataSearch(key: String): LiveData<List<Book>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun getBooksByGroup(group: Int): List<Book>
@Query("SELECT * FROM books WHERE `name` in (:names)") @Query("SELECT * FROM books WHERE `name` in (:names)")
fun findByName(vararg names: String): List<Book> fun findByName(vararg names: String): List<Book>

@ -32,6 +32,13 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
fun delGroup(vararg bookGroup: BookGroup) { fun delGroup(vararg bookGroup: BookGroup) {
execute { execute {
App.db.bookGroupDao().delete(*bookGroup) App.db.bookGroupDao().delete(*bookGroup)
bookGroup.forEach { group ->
val books = App.db.bookDao().getBooksByGroup(group.groupId)
books.forEach {
it.group = it.group - group.groupId
}
App.db.bookDao().update(*books.toTypedArray())
}
} }
} }

Loading…
Cancel
Save