|
|
@ -46,11 +46,11 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), |
|
|
|
private val bookGroups = mutableListOf<BookGroup>() |
|
|
|
private val bookGroups = mutableListOf<BookGroup>() |
|
|
|
private val fragmentMap = hashMapOf<Long, BooksFragment>() |
|
|
|
private val fragmentMap = hashMapOf<Long, BooksFragment>() |
|
|
|
private var groupsFlowJob: Job? = null |
|
|
|
private var groupsFlowJob: Job? = null |
|
|
|
override val groupId: Long get() = selectedGroup.groupId |
|
|
|
override val groupId: Long get() = selectedGroup?.groupId ?: 0 |
|
|
|
|
|
|
|
|
|
|
|
override val books: List<Book> |
|
|
|
override val books: List<Book> |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
val fragment = fragmentMap[selectedGroup.groupId] |
|
|
|
val fragment = fragmentMap[groupId] |
|
|
|
return fragment?.getBooks() ?: emptyList() |
|
|
|
return fragment?.getBooks() ?: emptyList() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -60,8 +60,8 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), |
|
|
|
initBookGroupData() |
|
|
|
initBookGroupData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val selectedGroup: BookGroup |
|
|
|
private val selectedGroup: BookGroup? |
|
|
|
get() = bookGroups[tabLayout.selectedTabPosition] |
|
|
|
get() = bookGroups.getOrNull(tabLayout.selectedTabPosition) |
|
|
|
|
|
|
|
|
|
|
|
private fun initView() { |
|
|
|
private fun initView() { |
|
|
|
binding.viewPagerBookshelf.setEdgeEffectColor(primaryColor) |
|
|
|
binding.viewPagerBookshelf.setEdgeEffectColor(primaryColor) |
|
|
@ -113,8 +113,10 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
fragmentMap[selectedGroup.groupId]?.let { |
|
|
|
selectedGroup?.let { group -> |
|
|
|
toastOnUi("${selectedGroup.groupName}(${it.getBooksCount()})") |
|
|
|
fragmentMap[group.groupId]?.let { |
|
|
|
|
|
|
|
toastOnUi("${group.groupName}(${it.getBooksCount()})") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -125,7 +127,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun gotoTop() { |
|
|
|
override fun gotoTop() { |
|
|
|
fragmentMap[selectedGroup.groupId]?.gotoTop() |
|
|
|
fragmentMap[groupId]?.gotoTop() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private inner class TabFragmentPageAdapter(fm: FragmentManager) : |
|
|
|
private inner class TabFragmentPageAdapter(fm: FragmentManager) : |
|
|
|