pull/1738/head
kunfei 3 years ago
parent c1b01e6889
commit 4df9b63022
  1. 39
      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. 5
      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. 5
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt

@ -53,8 +53,9 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
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 = 2 private var bottomMenuCount = 4
private val realPositions = arrayOf(0, 1, 2, 3) private val realPositions =
arrayOf(BaseBookshelfFragment.id, ExploreFragment.id, RssFragment.id, MyFragment.id)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu() upBottomMenu()
@ -197,31 +198,23 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
menu.findItem(R.id.menu_discovery).isVisible = showDiscovery menu.findItem(R.id.menu_discovery).isVisible = showDiscovery
menu.findItem(R.id.menu_rss).isVisible = showRss menu.findItem(R.id.menu_rss).isVisible = showRss
} }
bottomMenuCount = 2 bottomMenuCount = 1
realPositions[1] = 1 if (showDiscovery) {
realPositions[2] = 2 realPositions[bottomMenuCount] = ExploreFragment.id
when { bottomMenuCount++
showDiscovery -> bottomMenuCount++
showRss -> {
realPositions[1] = 2
realPositions[2] = 3
}
else -> {
realPositions[1] = 3
realPositions[2] = 3
}
} }
if (showRss) { if (showRss) {
realPositions[bottomMenuCount] = RssFragment.id
bottomMenuCount++ bottomMenuCount++
} else {
realPositions[2] = 3
} }
realPositions[bottomMenuCount] = MyFragment.id
bottomMenuCount++
} }
private fun getFragmentId(position: Int): Int { private fun getFragmentId(position: Int): Int {
val p = realPositions[position] val p = realPositions[position]
if (p == 0) { if (p == BaseBookshelfFragment.id) {
return if (AppConfig.bookGroupStyle == 1) 11 else 0 return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id
} }
return p return p
} }
@ -250,10 +243,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)) {
0 -> BookshelfFragment1() BookshelfFragment1.id -> BookshelfFragment1()
11 -> BookshelfFragment2() BookshelfFragment2.id -> BookshelfFragment2()
1 -> ExploreFragment() ExploreFragment.id -> ExploreFragment()
2 -> RssFragment() RssFragment.id -> RssFragment()
else -> MyFragment() else -> MyFragment()
} }
} }

@ -30,6 +30,10 @@ 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,6 +35,10 @@ 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,6 +42,10 @@ 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 {

@ -36,6 +36,11 @@ 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,6 +33,10 @@ 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?) {

@ -37,6 +37,11 @@ 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