From 15a8a506f03cdd0bbc02fbbe689bfdbac37ae808 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 23:58:39 +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/BookGroupDao.kt | 3 +++ .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 4f65a751c..84b2cdc6e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -34,6 +34,9 @@ interface BookGroupDao { @Query("update book_groups set show = 1 where groupId = :groupId") fun enableGroup(groupId: Long) + @Query("select groupName from book_groups where groupId > 0 and (groupId & :id) > 0") + fun getGroupNames(id: Long): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index c4f60e92b..141c690fb 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -119,13 +119,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) { execute { - val groupNames = arrayListOf() - App.db.bookGroupDao().all.forEach { - if (groupId and it.groupId > 0) { - groupNames.add(it.groupName) - } - } - groupNames.joinToString(",") + App.db.bookGroupDao().getGroupNames(groupId).joinToString(",") }.onSuccess { success.invoke(it) }