From 4df9b63022c65e945af9de71d279e72b80d9fe4d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 20 Mar 2022 21:04:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainActivity.kt | 39 ++++++++----------- .../main/bookshelf/BaseBookshelfFragment.kt | 4 ++ .../bookshelf/style1/BookshelfFragment1.kt | 4 ++ .../bookshelf/style2/BookshelfFragment2.kt | 4 ++ .../app/ui/main/explore/ExploreFragment.kt | 5 +++ .../io/legado/app/ui/main/my/MyFragment.kt | 4 ++ .../io/legado/app/ui/main/rss/RssFragment.kt | 5 +++ 7 files changed, 42 insertions(+), 23 deletions(-) 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 781f840d1..70a00573e 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 @@ -53,8 +53,9 @@ class MainActivity : VMBaseActivity(), private var exploreReselected: Long = 0 private var pagePosition = 0 private val fragmentMap = hashMapOf() - 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(), 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(), 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() } } 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 e4f0847f0..b80e841f1 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,6 +30,10 @@ 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 afd72e992..0b75985cd 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,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 { 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 6cd545f29..b2efea745 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,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 { 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 270ce49fc..bb212dde4 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 @@ -36,6 +36,11 @@ 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 e4464a17c..dfde860db 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,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?) { 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 f0e6ee09c..16e676ca5 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 @@ -37,6 +37,11 @@ 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) }