From b2d6249cfc3472b8f53a748a29a67fb6d917472b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:35:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/AppDatabase.kt | 25 ++++++++++++++++++- .../app/ui/book/group/GroupManageDialog.kt | 9 +------ .../ui/main/bookshelf/BookshelfFragment.kt | 14 ----------- .../ui/main/bookshelf/BookshelfViewModel.kt | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 781d59057..262fe014d 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -45,7 +45,30 @@ abstract class AppDatabase: RoomDatabase() { private val dbCallback = object : Callback() { override fun onOpen(db: SupportSQLiteDatabase) { - + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -1, '全部', -10 + where not exists (select * from book_groups where groupId = -1) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -2, '本地', -9 + where not exists (select * from book_groups where groupId = -2) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -3, '音频', -8 + where not exists (select * from book_groups where groupId = -3) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -4, '未分组', -7 + where not exists (select * from book_groups where groupId = -4) + """ + ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index c3421e136..6eac527d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -195,14 +195,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - if (srcPosition < 4 || targetPosition < 4) { - return true - } - Collections.swap( - getItems(), - srcPosition - getHeaderCount(), - targetPosition - getHeaderCount() - ) + Collections.swap(getItems(), srcPosition, targetPosition) notifyItemMoved(srcPosition, targetPosition) isMoved = true return true diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index e66699b0e..1647f5a86 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -12,11 +12,9 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment -import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup -import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton @@ -126,18 +124,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b @Synchronized private fun upGroup(data: List) { bookGroups.clear() - if (AppConfig.bookGroupAllShow) { - bookGroups.add(AppConst.bookGroupAll) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(AppConst.bookGroupAudio) - } - if (AppConfig.bookGroupNoneShow) { - bookGroups.add(AppConst.bookGroupNone) - } bookGroups.addAll(data) adapter.notifyDataSetChanged() selectLastTab() 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 e9fb4cd4c..ae14b99f9 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 @@ -64,7 +64,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun checkGroup(groups: List) { groups.forEach { group -> - if (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) {