From d7dba0618dc17e7cb0cf47af1cb860ca18339678 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 11:37:15 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 5 ++--- 2 files changed, 5 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 c48bd6e6b..b06e7ac9e 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 @@ -16,6 +16,9 @@ interface BookGroupDao { @get:Query("SELECT MAX(groupId) FROM book_groups") val maxId: Int + @get:Query("SELECT MAX(`order`) FROM book_groups") + val maxOrder: Int + @Query("SELECT * FROM book_groups ORDER BY `order`") fun all(): List diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 83d3c41a5..536329915 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -10,11 +10,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun addGroup(groupName: String) { execute { - val maxId = App.db.bookGroupDao().maxId val bookGroup = BookGroup( - groupId = maxId.plus(1), + groupId = App.db.bookGroupDao().maxId.plus(1), groupName = groupName, - order = maxId.plus(1) + order = App.db.bookGroupDao().maxOrder.plus(1) ) App.db.bookGroupDao().insert(bookGroup) }