diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 70fa1d1a5..adb92d961 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -16,7 +16,7 @@ object EventBus { const val AUDIO_PROGRESS = "audioProgress" const val AUDIO_SIZE = "audioSize" const val AUDIO_SPEED = "audioSpeed" - const val SHOW_RSS = "showRss" + const val NOTIFY_MAIN = "notifyMain" const val WEB_SERVICE = "webService" const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 70b4a6b89..a8d2d0ee5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -23,6 +23,7 @@ object PreferKey { const val ttsSpeechRate = "ttsSpeechRate" const val prevKeys = "prevKeyCodes" const val nextKeys = "nextKeyCodes" + const val showDiscovery = "showDiscovery" const val showRss = "showRss" const val bookshelfLayout = "bookshelfLayout" const val bookshelfSort = "bookshelfSort" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index b2c620f63..798d08c5b 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -100,7 +100,10 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { } } - val isShowRSS: Boolean + val showDiscovery: Boolean + get() = appCtx.getPrefBoolean(PreferKey.showDiscovery, true) + + val showRSS: Boolean get() = appCtx.getPrefBoolean(PreferKey.showRss, true) val autoRefreshBook: Boolean diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 86e3ca53a..f08b3c250 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -133,7 +133,7 @@ class OtherConfigFragment : BasePreferenceFragment(), PreferKey.processText -> sharedPreferences?.let { setProcessTextEnable(it.getBoolean(key, true)) } - PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "") + PreferKey.showDiscovery, PreferKey.showRss -> postEvent(EventBus.NOTIFY_MAIN, "") PreferKey.defaultCover -> upPreferenceSummary( key, getPrefString(PreferKey.defaultCover) ) 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 65ca55b42..1987cb286 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 @@ -41,35 +41,24 @@ class MainActivity : VMBaseActivity(), private var exploreReselected: Long = 0 private var pagePosition = 0 private val fragmentMap = hashMapOf() + private var bottomMenuCount = 2 override fun getViewBinding(): ActivityMainBinding { return ActivityMainBinding.inflate(layoutInflater) } override fun onActivityCreated(savedInstanceState: Bundle?) { + upBottomMenu() binding.apply { ATH.applyEdgeEffectColor(viewPagerMain) ATH.applyBottomNavigationColor(bottomNavigationView) viewPagerMain.offscreenPageLimit = 3 viewPagerMain.adapter = TabFragmentPageAdapter() - viewPagerMain.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { - override fun onPageSelected(position: Int) { - pagePosition = position - when (position) { - 0, 1, 3 -> bottomNavigationView.menu.getItem(position).isChecked = true - 2 -> if (AppConfig.isShowRSS) { - bottomNavigationView.menu.getItem(position).isChecked = true - } else { - bottomNavigationView.menu.getItem(3).isChecked = true - } - } - } - }) + viewPagerMain.registerOnPageChangeCallback(PageChangeCallback()) bottomNavigationView.elevation = if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat() bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity) bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity) - bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS } } @@ -90,9 +79,13 @@ class MainActivity : VMBaseActivity(), override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { when (item.itemId) { R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) - R.id.menu_explore -> viewPagerMain.setCurrentItem(1, false) - R.id.menu_rss -> viewPagerMain.setCurrentItem(2, false) - R.id.menu_my_config -> viewPagerMain.setCurrentItem(3, 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) } return false } @@ -106,7 +99,7 @@ class MainActivity : VMBaseActivity(), (fragmentMap[0] as? BookshelfFragment)?.gotoTop() } } - R.id.menu_explore -> { + R.id.menu_discovery -> { if (System.currentTimeMillis() - exploreReselected > 300) { exploreReselected = System.currentTimeMillis() } else { @@ -176,12 +169,11 @@ class MainActivity : VMBaseActivity(), observeEvent(EventBus.RECREATE) { recreate() } - observeEvent(EventBus.SHOW_RSS) { - binding.bottomNavigationView.menu.findItem(R.id.menu_rss).isVisible = - AppConfig.isShowRSS - binding.viewPagerMain.adapter?.notifyDataSetChanged() - if (AppConfig.isShowRSS) { - binding.viewPagerMain.setCurrentItem(3, false) + observeEvent(EventBus.NOTIFY_MAIN) { + binding.apply { + upBottomMenu() + viewPagerMain.adapter?.notifyDataSetChanged() + viewPagerMain.setCurrentItem(bottomMenuCount - 1, false) } } observeEvent(PreferKey.threadCount) { @@ -189,22 +181,57 @@ class MainActivity : VMBaseActivity(), } } - private inner class TabFragmentPageAdapter : - FragmentStateAdapter(this) { + private fun upBottomMenu() { + binding.bottomNavigationView.menu.let { menu -> + menu.findItem(R.id.menu_discovery).isVisible = AppConfig.showDiscovery + menu.findItem(R.id.menu_rss).isVisible = AppConfig.showRSS + } + bottomMenuCount = 2 + if (AppConfig.showDiscovery) { + bottomMenuCount++ + } + if (AppConfig.showRSS) { + bottomMenuCount++ + } + } - override fun getItemId(position: Int): Long { - return when (position) { - 2 -> if (AppConfig.isShowRSS) 2 else 3 - else -> position.toLong() + private fun getRealBottomMenuPosition(position: Int): Int { + return when (position) { + 1 -> when { + AppConfig.showDiscovery -> 1 + AppConfig.showRSS -> 2 + else -> 3 } + 2 -> if (AppConfig.showDiscovery) { + if (AppConfig.showRSS) 2 else 3 + } else { + 3 + } + else -> position + } + } + + private inner class PageChangeCallback : ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + pagePosition = position + binding.bottomNavigationView.menu + .getItem(getRealBottomMenuPosition(position)).isChecked = true } + } + + private inner class TabFragmentPageAdapter : + FragmentStateAdapter(this) { override fun containsItem(itemId: Long): Boolean { return fragmentMap.containsKey(itemId) } override fun getItemCount(): Int { - return if (AppConfig.isShowRSS) 4 else 3 + return bottomMenuCount + } + + override fun getItemId(position: Int): Long { + return getRealBottomMenuPosition(position).toLong() } override fun createFragment(position: Int): Fragment { diff --git a/app/src/main/res/layout/activity_book_source_edit.xml b/app/src/main/res/layout/activity_book_source_edit.xml index fe1470b47..2e8ce28aa 100644 --- a/app/src/main/res/layout/activity_book_source_edit.xml +++ b/app/src/main/res/layout/activity_book_source_edit.xml @@ -31,7 +31,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" - android:text="@string/find" /> + android:text="@string/discovery" /> + app:title="@string/discovery" /> + app:title="@string/discovery" /> + android:title="@string/discovery" /> Are you sure to delete this file? Directory Intelligent import - Discovery + Discovery Switch display styles Import local books requires storage permission Night Theme @@ -803,7 +803,7 @@ Export the list of books Import the list of books Download in advance - Download 10 chapters in advance + Download %s chapters in advance Is enabled Background image Copy book URL @@ -839,4 +839,5 @@ Hide Hide when status bar show Reverse toc + 显示发现 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 366b70c61..70cd3ed3c 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -471,7 +471,7 @@ Você tem certeza que quer excluir este arquivo? Pasta Importação inteligente - Descoberta + Descoberta Mudar o modo de exibição Importação de livros locais requer permissão de armazenamento Tema Noturno @@ -839,5 +839,6 @@ Hide Hide when status bar show 反转目录 + 显示发现 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 4a8e636c0..f46c68166 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -460,7 +460,7 @@ 確定刪除文件嗎? 手機目錄 智能導入 - 發現 + 發現 切換顯示樣式 導入本地書籍需存儲權限 夜間模式 @@ -837,5 +837,6 @@ 輸入自訂源分組名稱 【%s】 反转目录 + 显示发现 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 182ea03aa..aafc932be 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -470,7 +470,7 @@ 確定刪除文件嗎? 手機目錄 智慧匯入 - 發現 + 發現 切換顯示樣式 匯入本機書籍需儲存權限 夜間模式 @@ -838,5 +838,6 @@ 隐藏 状态栏显示时隐藏 反转目录 + 显示发现 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 170d773e0..1c23cf5f2 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -470,7 +470,7 @@ 确定删除文件吗? 手机目录 智能导入 - 发现 + 发现 切换显示样式 导入本地书籍需存储权限 夜间模式 @@ -838,5 +838,6 @@ 隐藏 状态栏显示时隐藏 反转目录 + 显示发现 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0781727fb..557de3291 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -471,7 +471,7 @@ Are you sure to delete this file? Directory Intelligent import - Discovery + Discovery Switch display styles Import local books requires storage permission Night Theme @@ -803,7 +803,7 @@ Export the list of books Import the list of books Download in advance - Download 10 chapters in advance + Download %s chapters in advance Is enabled Background image Copy book URL @@ -839,4 +839,5 @@ Hide Hide when status bar show Reverse toc + Show diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 32b5aa3c1..217fc4156 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -30,6 +30,12 @@ android:title="@string/pt_default_read" app:iconSpaceReserved="false" /> + +