diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 915a9dbb9..9ffd84818 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -33,6 +33,9 @@ interface BookDao { @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") fun liveDataSearch(key: String): LiveData> + @Query("SELECT * FROM books WHERE (`group` & :group) > 0") + fun getBooksByGroup(group: Int): List + @Query("SELECT * FROM books WHERE `name` in (:names)") fun findByName(vararg names: String): List diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt index eb811766e..23555015f 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt @@ -32,6 +32,13 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { fun delGroup(vararg bookGroup: BookGroup) { execute { 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()) + } } }