pull/2661/head
kunfei 2 years ago
parent 02e5b3e81e
commit 406e0b3d9e
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 12
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt

@ -119,4 +119,6 @@ interface BookDao {
@Query("update books set `group` = :newGroupId where `group` = :oldGroupId") @Query("update books set `group` = :newGroupId where `group` = :oldGroupId")
fun upGroup(oldGroupId: Long, newGroupId: Long) fun upGroup(oldGroupId: Long, newGroupId: Long)
@Query("update books set `group` = `group` - :group where `group` & :group > 0")
fun removeGroup(group: Long)
} }

@ -29,16 +29,10 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun delGroup(vararg bookGroup: BookGroup, finally: () -> Unit) { fun delGroup(bookGroup: BookGroup, finally: () -> Unit) {
execute { execute {
appDb.bookGroupDao.delete(*bookGroup) appDb.bookGroupDao.delete(bookGroup)
bookGroup.forEach { group -> appDb.bookDao.removeGroup(bookGroup.groupId)
val books = appDb.bookDao.getBooksByGroup(group.groupId)
books.forEach {
it.group = it.group - group.groupId
}
appDb.bookDao.update(*books.toTypedArray())
}
}.onFinally { }.onFinally {
finally() finally()
} }

Loading…
Cancel
Save