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) }