mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -48,14 +48,19 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
|
||||
override val binding by viewBinding(ActivityMainBinding::inflate)
|
||||
override val viewModel by viewModels<MainViewModel>()
|
||||
private val idBookshelf = 0
|
||||
private val idBookshelf1 = 11
|
||||
private val idBookshelf2 = 12
|
||||
private val idExplore = 1
|
||||
private val idRss = 2
|
||||
private val idMy = 3
|
||||
private var exitTime: Long = 0
|
||||
private var bookshelfReselected: Long = 0
|
||||
private var exploreReselected: Long = 0
|
||||
private var pagePosition = 0
|
||||
private val fragmentMap = hashMapOf<Int, Fragment>()
|
||||
private var bottomMenuCount = 4
|
||||
private val realPositions =
|
||||
arrayOf(BaseBookshelfFragment.id, ExploreFragment.id, RssFragment.id, MyFragment.id)
|
||||
private val realPositions = arrayOf(idBookshelf, idExplore, idRss, idMy)
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
upBottomMenu()
|
||||
@@ -88,8 +93,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
when (item.itemId) {
|
||||
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false)
|
||||
R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false)
|
||||
R.id.menu_rss -> openPage(RssFragment.id)
|
||||
R.id.menu_my_config -> openPage(MyFragment.id)
|
||||
R.id.menu_rss -> openPage(idRss)
|
||||
R.id.menu_my_config -> openPage(idMy)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -204,21 +209,21 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
}
|
||||
bottomMenuCount = 1
|
||||
if (showDiscovery) {
|
||||
realPositions[bottomMenuCount] = ExploreFragment.id
|
||||
realPositions[bottomMenuCount] = idExplore
|
||||
bottomMenuCount++
|
||||
}
|
||||
if (showRss) {
|
||||
realPositions[bottomMenuCount] = RssFragment.id
|
||||
realPositions[bottomMenuCount] = idRss
|
||||
bottomMenuCount++
|
||||
}
|
||||
realPositions[bottomMenuCount] = MyFragment.id
|
||||
realPositions[bottomMenuCount] = idMy
|
||||
bottomMenuCount++
|
||||
}
|
||||
|
||||
private fun getFragmentId(position: Int): Int {
|
||||
val id = realPositions[position]
|
||||
if (id == BaseBookshelfFragment.id) {
|
||||
return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id
|
||||
if (id == idBookshelf) {
|
||||
return if (AppConfig.bookGroupStyle == 1) idBookshelf2 else idBookshelf1
|
||||
}
|
||||
return id
|
||||
}
|
||||
@@ -247,10 +252,10 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (getId(position)) {
|
||||
BookshelfFragment1.id -> BookshelfFragment1()
|
||||
BookshelfFragment2.id -> BookshelfFragment2()
|
||||
ExploreFragment.id -> ExploreFragment()
|
||||
RssFragment.id -> RssFragment()
|
||||
idBookshelf1 -> BookshelfFragment1()
|
||||
idBookshelf2 -> BookshelfFragment2()
|
||||
idExplore -> ExploreFragment()
|
||||
idRss -> RssFragment()
|
||||
else -> MyFragment()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,6 @@ 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,10 +35,6 @@ 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,10 +42,6 @@ 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 {
|
||||
|
||||
@@ -37,10 +37,6 @@ 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,10 +33,6 @@ 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?) {
|
||||
|
||||
@@ -38,10 +38,6 @@ 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