@ -16,6 +16,9 @@ interface BookGroupDao {
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): LiveData<List<BookGroup>>
@Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`")
fun liveDataSelect(): LiveData<List<BookGroup>>
@get:Query("SELECT sum(groupId) FROM book_groups")
val idsSum: Long
@ -109,7 +109,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
private fun initData() {
App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, {
App.db.bookGroupDao().liveDataSelect().observe(viewLifecycleOwner, {
adapter.setItems(it)
})
@ -64,7 +64,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun checkGroup(groups: List<BookGroup>) {
groups.forEach { group ->
if (group.groupId > 0 && group.groupId and (group.groupId - 1) != 0L) {
if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) {
var id = 1L
val idsSum = App.db.bookGroupDao().idsSum
while (id and idsSum != 0L) {