feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 55a43999c0
commit 6697e4cb82
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  2. 7
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt

@ -13,8 +13,8 @@ interface BookGroupDao {
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): LiveData<List<BookGroup>>
@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

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

Loading…
Cancel
Save