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 ddf016ce5..9633a8b6d 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 @@ -119,4 +119,6 @@ interface BookDao { @Query("update books set `group` = :newGroupId where `group` = :oldGroupId") fun upGroup(oldGroupId: Long, newGroupId: Long) + @Query("update books set `group` = `group` - :group where `group` & :group > 0") + fun removeGroup(group: Long) } \ No newline at end of file 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 5c71236ef..7ab10d990 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 @@ -29,16 +29,10 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { } } - fun delGroup(vararg bookGroup: BookGroup, finally: () -> Unit) { + fun delGroup(bookGroup: BookGroup, finally: () -> Unit) { execute { - appDb.bookGroupDao.delete(*bookGroup) - bookGroup.forEach { group -> - val books = appDb.bookDao.getBooksByGroup(group.groupId) - books.forEach { - it.group = it.group - group.groupId - } - appDb.bookDao.update(*books.toTypedArray()) - } + appDb.bookGroupDao.delete(bookGroup) + appDb.bookDao.removeGroup(bookGroup.groupId) }.onFinally { finally() }