From ee7d31872dd502a1dea4d1f37c386aa85d2ef7e6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 20 Mar 2022 23:24:34 +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 | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 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 70a00573e..bfb5a2d8f 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 @@ -88,12 +88,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 -> if (AppConfig.showDiscovery) { - viewPagerMain.setCurrentItem(2, false) - } else { - viewPagerMain.setCurrentItem(1, false) - } - R.id.menu_my_config -> viewPagerMain.setCurrentItem(bottomMenuCount - 1, false) + R.id.menu_rss -> openPage(RssFragment.id) + R.id.menu_my_config -> openPage(MyFragment.id) } return false } @@ -117,6 +113,14 @@ class MainActivity : VMBaseActivity(), } } + private fun openPage(id: Int) { + realPositions.firstOrNull { + it == id + }?.let { index -> + binding.viewPagerMain.setCurrentItem(index, false) + } + } + private fun upVersion() { if (LocalConfig.versionCode != appInfo.versionCode) { LocalConfig.versionCode = appInfo.versionCode @@ -212,11 +216,11 @@ class MainActivity : VMBaseActivity(), } private fun getFragmentId(position: Int): Int { - val p = realPositions[position] - if (p == BaseBookshelfFragment.id) { + val id = realPositions[position] + if (id == BaseBookshelfFragment.id) { return if (AppConfig.bookGroupStyle == 1) BookshelfFragment2.id else BookshelfFragment1.id } - return p + return id } private inner class PageChangeCallback : ViewPager.SimpleOnPageChangeListener() {