feat: 优化代码

pull/182/head
kunfei 5 years ago
parent a6937bd434
commit 11f0e73476
  1. 16
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -108,7 +108,10 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
synchronized(this) {
tab_layout.removeOnTabSelectedListener(this@BookshelfFragment)
}
var noGroupSize = 0
withContext(IO) {
noGroupSize = App.db.bookDao().noGroupSize
}
synchronized(this@BookshelfFragment) {
bookGroups.clear()
if (AppConfig.bookGroupAllShow) {
@ -120,16 +123,13 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
if (AppConfig.bookGroupAudioShow) {
bookGroups.add(AppConst.bookGroupAudio)
}
showGroupNone = if (App.db.bookDao().noGroupSize > 0 && it.isNotEmpty()) {
showGroupNone = if (noGroupSize > 0 && it.isNotEmpty()) {
bookGroups.add(AppConst.bookGroupNone)
true
} else {
false
}
bookGroups.addAll(it)
}
}
synchronized(this@BookshelfFragment) {
view_pager_bookshelf.adapter?.notifyDataSetChanged()
tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select()
tab_layout.addOnTabSelectedListener(this@BookshelfFragment)
@ -160,14 +160,17 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun upGroup() {
launch {
var noGroupSize = 0
withContext(IO) {
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 (App.db.bookDao().noGroupSize > 0 && bookGroups.isNotEmpty()) {
if (noGroupSize > 0 && bookGroups.isNotEmpty()) {
bookGroups.add(0, AppConst.bookGroupNone)
true
} else {
@ -182,9 +185,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
if (AppConfig.bookGroupAllShow) {
bookGroups.add(0, AppConst.bookGroupAll)
}
}
}
synchronized(this@BookshelfFragment) {
view_pager_bookshelf.adapter?.notifyDataSetChanged()
}
}

Loading…
Cancel
Save