From 406e0b3d9e34af9dd02459b458f01c6764a2ad1c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 23 Dec 2022 12:13:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 ++ .../io/legado/app/ui/book/group/GroupViewModel.kt | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) 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() }