From 11f0e7347675748c3bf109d4739c3f9e319ac524 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Apr 2020 21:26:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/BookshelfFragment.kt | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) 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 fd065c307..c11bb5107 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 @@ -108,28 +108,28 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b synchronized(this) { tab_layout.removeOnTabSelectedListener(this@BookshelfFragment) } + var noGroupSize = 0 withContext(IO) { - synchronized(this@BookshelfFragment) { - bookGroups.clear() - if (AppConfig.bookGroupAllShow) { - bookGroups.add(AppConst.bookGroupAll) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(AppConst.bookGroupAudio) - } - showGroupNone = if (App.db.bookDao().noGroupSize > 0 && it.isNotEmpty()) { - bookGroups.add(AppConst.bookGroupNone) - true - } else { - false - } - bookGroups.addAll(it) - } + noGroupSize = App.db.bookDao().noGroupSize } synchronized(this@BookshelfFragment) { + bookGroups.clear() + if (AppConfig.bookGroupAllShow) { + bookGroups.add(AppConst.bookGroupAll) + } + if (AppConfig.bookGroupLocalShow) { + bookGroups.add(AppConst.bookGroupLocal) + } + if (AppConfig.bookGroupAudioShow) { + bookGroups.add(AppConst.bookGroupAudio) + } + showGroupNone = if (noGroupSize > 0 && it.isNotEmpty()) { + bookGroups.add(AppConst.bookGroupNone) + true + } else { + false + } + bookGroups.addAll(it) view_pager_bookshelf.adapter?.notifyDataSetChanged() tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() tab_layout.addOnTabSelectedListener(this@BookshelfFragment) @@ -160,31 +160,31 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override fun upGroup() { launch { + var noGroupSize = 0 withContext(IO) { - synchronized(this@BookshelfFragment) { - bookGroups.remove(AppConst.bookGroupAll) - bookGroups.remove(AppConst.bookGroupLocal) - bookGroups.remove(AppConst.bookGroupAudio) - bookGroups.remove(AppConst.bookGroupNone) - showGroupNone = - if (App.db.bookDao().noGroupSize > 0 && bookGroups.isNotEmpty()) { + noGroupSize = App.db.bookDao().noGroupSize + } + synchronized(this@BookshelfFragment) { + bookGroups.remove(AppConst.bookGroupAll) + bookGroups.remove(AppConst.bookGroupLocal) + bookGroups.remove(AppConst.bookGroupAudio) + bookGroups.remove(AppConst.bookGroupNone) + showGroupNone = + if (noGroupSize > 0 && bookGroups.isNotEmpty()) { bookGroups.add(0, AppConst.bookGroupNone) true } else { false } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(0, AppConst.bookGroupAudio) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(0, AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAllShow) { - bookGroups.add(0, AppConst.bookGroupAll) - } + if (AppConfig.bookGroupAudioShow) { + bookGroups.add(0, AppConst.bookGroupAudio) + } + if (AppConfig.bookGroupLocalShow) { + bookGroups.add(0, AppConst.bookGroupLocal) + } + if (AppConfig.bookGroupAllShow) { + bookGroups.add(0, AppConst.bookGroupAll) } - } - synchronized(this@BookshelfFragment) { view_pager_bookshelf.adapter?.notifyDataSetChanged() } }