pull/1738/head
kunfei 3 years ago
parent ee7d31872d
commit 8982fed48a
  1. 31
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  3. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  4. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  5. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  6. 4
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  7. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt

@ -48,14 +48,19 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override val binding by viewBinding(ActivityMainBinding::inflate) override val binding by viewBinding(ActivityMainBinding::inflate)
override val viewModel by viewModels<MainViewModel>() 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 exitTime: Long = 0
private var bookshelfReselected: Long = 0 private var bookshelfReselected: Long = 0
private var exploreReselected: Long = 0 private var exploreReselected: Long = 0
private var pagePosition = 0 private var pagePosition = 0
private val fragmentMap = hashMapOf<Int, Fragment>() private val fragmentMap = hashMapOf<Int, Fragment>()
private var bottomMenuCount = 4 private var bottomMenuCount = 4
private val realPositions = private val realPositions = arrayOf(idBookshelf, idExplore, idRss, idMy)
arrayOf(BaseBookshelfFragment.id, ExploreFragment.id, RssFragment.id, MyFragment.id)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu() upBottomMenu()
@ -88,8 +93,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
when (item.itemId) { when (item.itemId) {
R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false)
R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false) R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false)
R.id.menu_rss -> openPage(RssFragment.id) R.id.menu_rss -> openPage(idRss)
R.id.menu_my_config -> openPage(MyFragment.id) R.id.menu_my_config -> openPage(idMy)
} }
return false return false
} }
@ -204,21 +209,21 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
} }
bottomMenuCount = 1 bottomMenuCount = 1
if (showDiscovery) { if (showDiscovery) {
realPositions[bottomMenuCount] = ExploreFragment.id realPositions[bottomMenuCount] = idExplore
bottomMenuCount++ bottomMenuCount++
} }
if (showRss) { if (showRss) {
realPositions[bottomMenuCount] = RssFragment.id realPositions[bottomMenuCount] = idRss
bottomMenuCount++ bottomMenuCount++
} }
realPositions[bottomMenuCount] = MyFragment.id realPositions[bottomMenuCount] = idMy
bottomMenuCount++ bottomMenuCount++
} }
private fun getFragmentId(position: Int): Int { private fun getFragmentId(position: Int): Int {
val id = realPositions[position] val id = realPositions[position]
if (id == BaseBookshelfFragment.id) { if (id == idBookshelf) {
return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id return if (AppConfig.bookGroupStyle == 1) idBookshelf2 else idBookshelf1
} }
return id return id
} }
@ -247,10 +252,10 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override fun getItem(position: Int): Fragment { override fun getItem(position: Int): Fragment {
return when (getId(position)) { return when (getId(position)) {
BookshelfFragment1.id -> BookshelfFragment1() idBookshelf1 -> BookshelfFragment1()
BookshelfFragment2.id -> BookshelfFragment2() idBookshelf2 -> BookshelfFragment2()
ExploreFragment.id -> ExploreFragment() idExplore -> ExploreFragment()
RssFragment.id -> RssFragment() idRss -> RssFragment()
else -> MyFragment() else -> MyFragment()
} }
} }

@ -30,10 +30,6 @@ import io.legado.app.utils.*
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId) { abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId) {
companion object {
const val id = 0
}
val activityViewModel by activityViewModels<MainViewModel>() val activityViewModel by activityViewModels<MainViewModel>()
override val viewModel by viewModels<BookshelfViewModel>() override val viewModel by viewModels<BookshelfViewModel>()

@ -35,10 +35,6 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf),
TabLayout.OnTabSelectedListener, TabLayout.OnTabSelectedListener,
SearchView.OnQueryTextListener { SearchView.OnQueryTextListener {
companion object {
const val id = 11
}
private val binding by viewBinding(FragmentBookshelfBinding::bind) private val binding by viewBinding(FragmentBookshelfBinding::bind)
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) } private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
private val tabLayout: TabLayout by lazy { private val tabLayout: TabLayout by lazy {

@ -42,10 +42,6 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
SearchView.OnQueryTextListener, SearchView.OnQueryTextListener,
BaseBooksAdapter.CallBack { BaseBooksAdapter.CallBack {
companion object {
const val id = 12
}
private val binding by viewBinding(FragmentBookshelf1Binding::bind) private val binding by viewBinding(FragmentBookshelf1Binding::bind)
private val rootGroupId = -100L private val rootGroupId = -100L
private val bookshelfLayout by lazy { private val bookshelfLayout by lazy {

@ -37,10 +37,6 @@ import kotlinx.coroutines.launch
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore), class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
ExploreAdapter.CallBack { ExploreAdapter.CallBack {
companion object {
const val id = 1
}
override val viewModel by viewModels<ExploreViewModel>() override val viewModel by viewModels<ExploreViewModel>()
private val binding by viewBinding(FragmentExploreBinding::bind) private val binding by viewBinding(FragmentExploreBinding::bind)
private val adapter by lazy { ExploreAdapter(requireContext(), this) } 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) { class MyFragment : BaseFragment(R.layout.fragment_my_config) {
companion object {
const val id = 3
}
private val binding by viewBinding(FragmentMyConfigBinding::bind) private val binding by viewBinding(FragmentMyConfigBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {

@ -38,10 +38,6 @@ import kotlinx.coroutines.launch
class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss), class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
RssAdapter.CallBack { RssAdapter.CallBack {
companion object {
const val id = 2
}
private val binding by viewBinding(FragmentRssBinding::bind) private val binding by viewBinding(FragmentRssBinding::bind)
override val viewModel by viewModels<RssSourceViewModel>() override val viewModel by viewModels<RssSourceViewModel>()
private val adapter by lazy { RssAdapter(requireContext(), this) } private val adapter by lazy { RssAdapter(requireContext(), this) }

Loading…
Cancel
Save