From 6697e4cb828d0ad963abf28e566d3737280f019a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 13 Feb 2020 18:38:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= 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 | 4 ++-- .../java/io/legado/app/ui/book/group/GroupViewModel.kt | 7 ++++++- 2 files changed, 8 insertions(+), 3 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 af15188bb..eafff6b0e 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 @@ -13,8 +13,8 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @get:Query("SELECT MAX(groupId) FROM book_groups") - val maxId: Int + @get:Query("SELECT count(groupId) FROM book_groups") + val idsCount: Int @get:Query("SELECT MAX(`order`) FROM book_groups") val maxOrder: Int 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 610eff778..e0fdc2b09 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 @@ -9,8 +9,13 @@ class GroupViewModel(application: Application) : BaseViewModel(application) { fun addGroup(groupName: String) { execute { + var id = 1 + val idsCount = App.db.bookGroupDao().idsCount + while (id and idsCount != 0) { + id *= 2 + } val bookGroup = BookGroup( - groupId = App.db.bookGroupDao().maxId.plus(1), + groupId = id, groupName = groupName, order = App.db.bookGroupDao().maxOrder.plus(1) )