mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -53,8 +53,9 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
private var exploreReselected: Long = 0
|
||||
private var pagePosition = 0
|
||||
private val fragmentMap = hashMapOf<Int, Fragment>()
|
||||
private var bottomMenuCount = 2
|
||||
private val realPositions = arrayOf(0, 1, 2, 3)
|
||||
private var bottomMenuCount = 4
|
||||
private val realPositions =
|
||||
arrayOf(BaseBookshelfFragment.id, ExploreFragment.id, RssFragment.id, MyFragment.id)
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
upBottomMenu()
|
||||
@@ -197,31 +198,23 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
menu.findItem(R.id.menu_discovery).isVisible = showDiscovery
|
||||
menu.findItem(R.id.menu_rss).isVisible = showRss
|
||||
}
|
||||
bottomMenuCount = 2
|
||||
realPositions[1] = 1
|
||||
realPositions[2] = 2
|
||||
when {
|
||||
showDiscovery -> bottomMenuCount++
|
||||
showRss -> {
|
||||
realPositions[1] = 2
|
||||
realPositions[2] = 3
|
||||
}
|
||||
else -> {
|
||||
realPositions[1] = 3
|
||||
realPositions[2] = 3
|
||||
}
|
||||
bottomMenuCount = 1
|
||||
if (showDiscovery) {
|
||||
realPositions[bottomMenuCount] = ExploreFragment.id
|
||||
bottomMenuCount++
|
||||
}
|
||||
if (showRss) {
|
||||
realPositions[bottomMenuCount] = RssFragment.id
|
||||
bottomMenuCount++
|
||||
} else {
|
||||
realPositions[2] = 3
|
||||
}
|
||||
realPositions[bottomMenuCount] = MyFragment.id
|
||||
bottomMenuCount++
|
||||
}
|
||||
|
||||
private fun getFragmentId(position: Int): Int {
|
||||
val p = realPositions[position]
|
||||
if (p == 0) {
|
||||
return if (AppConfig.bookGroupStyle == 1) 11 else 0
|
||||
if (p == BaseBookshelfFragment.id) {
|
||||
return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id
|
||||
}
|
||||
return p
|
||||
}
|
||||
@@ -250,10 +243,10 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (getId(position)) {
|
||||
0 -> BookshelfFragment1()
|
||||
11 -> BookshelfFragment2()
|
||||
1 -> ExploreFragment()
|
||||
2 -> RssFragment()
|
||||
BookshelfFragment1.id -> BookshelfFragment1()
|
||||
BookshelfFragment2.id -> BookshelfFragment2()
|
||||
ExploreFragment.id -> ExploreFragment()
|
||||
RssFragment.id -> RssFragment()
|
||||
else -> MyFragment()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ import io.legado.app.utils.*
|
||||
|
||||
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId) {
|
||||
|
||||
companion object {
|
||||
const val id = 0
|
||||
}
|
||||
|
||||
val activityViewModel by activityViewModels<MainViewModel>()
|
||||
override val viewModel by viewModels<BookshelfViewModel>()
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
|
||||
TabLayout.OnTabSelectedListener,
|
||||
SearchView.OnQueryTextListener {
|
||||
|
||||
companion object {
|
||||
const val id = 11
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelfBinding::bind)
|
||||
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
||||
private val tabLayout: TabLayout by lazy {
|
||||
|
||||
@@ -42,6 +42,10 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
SearchView.OnQueryTextListener,
|
||||
BaseBooksAdapter.CallBack {
|
||||
|
||||
companion object {
|
||||
const val id = 12
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||
private val rootGroupId = -100L
|
||||
private val bookshelfLayout by lazy {
|
||||
|
||||
@@ -36,6 +36,11 @@ import kotlinx.coroutines.launch
|
||||
*/
|
||||
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
|
||||
ExploreAdapter.CallBack {
|
||||
|
||||
companion object {
|
||||
const val id = 1
|
||||
}
|
||||
|
||||
override val viewModel by viewModels<ExploreViewModel>()
|
||||
private val binding by viewBinding(FragmentExploreBinding::bind)
|
||||
private val adapter by lazy { ExploreAdapter(requireContext(), this) }
|
||||
|
||||
@@ -33,6 +33,10 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
||||
|
||||
companion object {
|
||||
const val id = 3
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentMyConfigBinding::bind)
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -37,6 +37,11 @@ import kotlinx.coroutines.launch
|
||||
*/
|
||||
class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
||||
RssAdapter.CallBack {
|
||||
|
||||
companion object {
|
||||
const val id = 2
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentRssBinding::bind)
|
||||
override val viewModel by viewModels<RssSourceViewModel>()
|
||||
private val adapter by lazy { RssAdapter(requireContext(), this) }
|
||||
|
||||
Reference in New Issue
Block a user