pull/78/head
kunfei 5 years ago
parent bbc6067a8f
commit d7dba0618d
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -16,6 +16,9 @@ interface BookGroupDao {
@get:Query("SELECT MAX(groupId) FROM book_groups") @get:Query("SELECT MAX(groupId) FROM book_groups")
val maxId: Int val maxId: Int
@get:Query("SELECT MAX(`order`) FROM book_groups")
val maxOrder: Int
@Query("SELECT * FROM book_groups ORDER BY `order`") @Query("SELECT * FROM book_groups ORDER BY `order`")
fun all(): List<BookGroup> fun all(): List<BookGroup>

@ -10,11 +10,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun addGroup(groupName: String) { fun addGroup(groupName: String) {
execute { execute {
val maxId = App.db.bookGroupDao().maxId
val bookGroup = BookGroup( val bookGroup = BookGroup(
groupId = maxId.plus(1), groupId = App.db.bookGroupDao().maxId.plus(1),
groupName = groupName, groupName = groupName,
order = maxId.plus(1) order = App.db.bookGroupDao().maxOrder.plus(1)
) )
App.db.bookGroupDao().insert(bookGroup) App.db.bookGroupDao().insert(bookGroup)
} }

Loading…
Cancel
Save