添加发现界面隐藏配置

pull/1006/head
gedoor 4 years ago
parent ec643ab263
commit 9e20cc1972
  1. 2
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 5
      app/src/main/java/io/legado/app/help/AppConfig.kt
  4. 2
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  5. 87
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  6. 2
      app/src/main/res/layout/activity_book_source_edit.xml
  7. 2
      app/src/main/res/layout/activity_explore_show.xml
  8. 2
      app/src/main/res/layout/fragment_explore.xml
  9. 4
      app/src/main/res/menu/main_bnv.xml
  10. 5
      app/src/main/res/values-ja-rJP/strings.xml
  11. 3
      app/src/main/res/values-pt-rBR/strings.xml
  12. 3
      app/src/main/res/values-zh-rHK/strings.xml
  13. 3
      app/src/main/res/values-zh-rTW/strings.xml
  14. 3
      app/src/main/res/values-zh/strings.xml
  15. 5
      app/src/main/res/values/strings.xml
  16. 6
      app/src/main/res/xml/pref_config_other.xml

@ -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"

@ -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"

@ -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

@ -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)
)

@ -41,35 +41,24 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
private var exploreReselected: Long = 0
private var pagePosition = 0
private val fragmentMap = hashMapOf<Long, Fragment>()
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<ActivityMainBinding, MainViewModel>(),
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<ActivityMainBinding, MainViewModel>(),
(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<ActivityMainBinding, MainViewModel>(),
observeEvent<String>(EventBus.RECREATE) {
recreate()
}
observeEvent<String>(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<String>(EventBus.NOTIFY_MAIN) {
binding.apply {
upBottomMenu()
viewPagerMain.adapter?.notifyDataSetChanged()
viewPagerMain.setCurrentItem(bottomMenuCount - 1, false)
}
}
observeEvent<String>(PreferKey.threadCount) {
@ -189,22 +181,57 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
}
}
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 {
private fun getRealBottomMenuPosition(position: Int): Int {
return when (position) {
2 -> if (AppConfig.isShowRSS) 2 else 3
else -> position.toLong()
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 {

@ -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" />
<TextView
android:layout_width="wrap_content"

@ -12,7 +12,7 @@
android:layout_height="wrap_content"
app:contentInsetStartWithNavigation="0dp"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/find" />
app:title="@string/discovery" />
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:id="@+id/content_view"

@ -13,7 +13,7 @@
app:attachToActivity="false"
app:contentLayout="@layout/view_search"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/find" />
app:title="@string/discovery" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_find"

@ -8,9 +8,9 @@
android:icon="@drawable/ic_bottom_books"
android:title="@string/bookshelf" />
<item
android:id="@+id/menu_explore"
android:id="@+id/menu_discovery"
android:icon="@drawable/ic_bottom_explore"
android:title="@string/find" />
android:title="@string/discovery" />
<item
android:id="@+id/menu_rss"
android:icon="@drawable/ic_bottom_rss_feed"

@ -471,7 +471,7 @@
<string name="sure_del_file">Are you sure to delete this file?</string>
<string name="files_tree">Directory</string>
<string name="intelligent_import">Intelligent import</string>
<string name="find">Discovery</string>
<string name="discovery">Discovery</string>
<string name="switch_display_style">Switch display styles</string>
<string name="import_per">Import local books requires storage permission</string>
<string name="night_theme">Night Theme</string>
@ -803,7 +803,7 @@
<string name="export_bookshelf">Export the list of books</string>
<string name="import_bookshelf">Import the list of books</string>
<string name="pre_download">Download in advance</string>
<string name="pre_download_s">Download 10 chapters in advance</string>
<string name="pre_download_s">Download %s chapters in advance</string>
<string name="is_enabled">Is enabled</string>
<string name="background_image">Background image</string>
<string name="copy_book_url">Copy book URL</string>
@ -839,4 +839,5 @@
<string name="hide">Hide</string>
<string name="hide_when_status_bar_show">Hide when status bar show</string>
<string name="reverse_toc">Reverse toc</string>
<string name="show_discovery">显示发现</string>
</resources>

@ -471,7 +471,7 @@
<string name="sure_del_file">Você tem certeza que quer excluir este arquivo?</string>
<string name="files_tree">Pasta</string>
<string name="intelligent_import">Importação inteligente</string>
<string name="find">Descoberta</string>
<string name="discovery">Descoberta</string>
<string name="switch_display_style">Mudar o modo de exibição</string>
<string name="import_per">Importação de livros locais requer permissão de armazenamento</string>
<string name="night_theme">Tema Noturno</string>
@ -839,5 +839,6 @@
<string name="hide">Hide</string>
<string name="hide_when_status_bar_show">Hide when status bar show</string>
<string name="reverse_toc">反转目录</string>
<string name="show_discovery">显示发现</string>
</resources>

@ -460,7 +460,7 @@
<string name="sure_del_file">確定刪除文件嗎?</string>
<string name="files_tree">手機目錄</string>
<string name="intelligent_import">智能導入</string>
<string name="find">發現</string>
<string name="discovery">發現</string>
<string name="switch_display_style">切換顯示樣式</string>
<string name="import_per">導入本地書籍需存儲權限</string>
<string name="night_theme">夜間模式</string>
@ -837,5 +837,6 @@
<string name="diy_edit_source_group">輸入自訂源分組名稱</string>
<string name="diy_edit_source_group_title">【%s】</string>
<string name="reverse_toc">反转目录</string>
<string name="show_discovery">显示发现</string>
</resources>

@ -470,7 +470,7 @@
<string name="sure_del_file">確定刪除文件嗎?</string>
<string name="files_tree">手機目錄</string>
<string name="intelligent_import">智慧匯入</string>
<string name="find">發現</string>
<string name="discovery">發現</string>
<string name="switch_display_style">切換顯示樣式</string>
<string name="import_per">匯入本機書籍需儲存權限</string>
<string name="night_theme">夜間模式</string>
@ -838,5 +838,6 @@
<string name="hide">隐藏</string>
<string name="hide_when_status_bar_show">状态栏显示时隐藏</string>
<string name="reverse_toc">反转目录</string>
<string name="show_discovery">显示发现</string>
</resources>

@ -470,7 +470,7 @@
<string name="sure_del_file">确定删除文件吗?</string>
<string name="files_tree">手机目录</string>
<string name="intelligent_import">智能导入</string>
<string name="find">发现</string>
<string name="discovery">发现</string>
<string name="switch_display_style">切换显示样式</string>
<string name="import_per">导入本地书籍需存储权限</string>
<string name="night_theme">夜间模式</string>
@ -838,5 +838,6 @@
<string name="hide">隐藏</string>
<string name="hide_when_status_bar_show">状态栏显示时隐藏</string>
<string name="reverse_toc">反转目录</string>
<string name="show_discovery">显示发现</string>
</resources>

@ -471,7 +471,7 @@
<string name="sure_del_file">Are you sure to delete this file?</string>
<string name="files_tree">Directory</string>
<string name="intelligent_import">Intelligent import</string>
<string name="find">Discovery</string>
<string name="discovery">Discovery</string>
<string name="switch_display_style">Switch display styles</string>
<string name="import_per">Import local books requires storage permission</string>
<string name="night_theme">Night Theme</string>
@ -803,7 +803,7 @@
<string name="export_bookshelf">Export the list of books</string>
<string name="import_bookshelf">Import the list of books</string>
<string name="pre_download">Download in advance</string>
<string name="pre_download_s">Download 10 chapters in advance</string>
<string name="pre_download_s">Download %s chapters in advance</string>
<string name="is_enabled">Is enabled</string>
<string name="background_image">Background image</string>
<string name="copy_book_url">Copy book URL</string>
@ -839,4 +839,5 @@
<string name="hide">Hide</string>
<string name="hide_when_status_bar_show">Hide when status bar show</string>
<string name="reverse_toc">Reverse toc</string>
<string name="show_discovery">Show</string>
</resources>

@ -30,6 +30,12 @@
android:title="@string/pt_default_read"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="showDiscovery"
android:title="@string/show_discovery"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="showRss"

Loading…
Cancel
Save