diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index bfb5a2d8f..d4d50c35c 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -48,14 +48,19 @@ class MainActivity : VMBaseActivity(), override val binding by viewBinding(ActivityMainBinding::inflate) override val viewModel by viewModels() + 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() 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(), 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(), } 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(), 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() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt index b80e841f1..e4f0847f0 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt @@ -30,10 +30,6 @@ import io.legado.app.utils.* abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment(layoutId) { - companion object { - const val id = 0 - } - val activityViewModel by activityViewModels() override val viewModel by viewModels() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt index 0b75985cd..afd72e992 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index b2efea745..6cd545f29 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index bb212dde4..8e2b1e049 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -37,10 +37,6 @@ import kotlinx.coroutines.launch class ExploreFragment : VMBaseFragment(R.layout.fragment_explore), ExploreAdapter.CallBack { - companion object { - const val id = 1 - } - override val viewModel by viewModels() private val binding by viewBinding(FragmentExploreBinding::bind) private val adapter by lazy { ExploreAdapter(requireContext(), this) } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index dfde860db..e4464a17c 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -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?) { diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 16e676ca5..4faf5173a 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -38,10 +38,6 @@ import kotlinx.coroutines.launch class RssFragment : VMBaseFragment(R.layout.fragment_rss), RssAdapter.CallBack { - companion object { - const val id = 2 - } - private val binding by viewBinding(FragmentRssBinding::bind) override val viewModel by viewModels() private val adapter by lazy { RssAdapter(requireContext(), this) }