pull/2042/head
kunfei 2 years ago
parent 88d13d86ab
commit 6c97d29635
  1. 17
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  2. 1
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  3. 18
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  4. 1
      app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt

@ -8,6 +8,7 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.core.view.MenuProvider
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@ -39,7 +40,8 @@ import splitties.init.appCtx
import kotlin.collections.set import kotlin.collections.set
class BackupConfigFragment : PreferenceFragment(), class BackupConfigFragment : PreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener,
MenuProvider {
private val viewModel by activityViewModels<ConfigViewModel>() private val viewModel by activityViewModels<ConfigViewModel>()
@ -124,23 +126,22 @@ class BackupConfigFragment : PreferenceFragment(),
activity?.setTitle(R.string.backup_restore) activity?.setTitle(R.string.backup_restore)
preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this)
listView.setEdgeEffectColor(primaryColor) listView.setEdgeEffectColor(primaryColor)
setHasOptionsMenu(true) activity?.addMenuProvider(this, viewLifecycleOwner)
if (!LocalConfig.backupHelpVersionIsLast) { if (!LocalConfig.backupHelpVersionIsLast) {
showHelp() showHelp()
} }
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) menuInflater.inflate(R.menu.backup_restore, menu)
inflater.inflate(R.menu.backup_restore, menu)
menu.applyTint(requireContext()) menu.applyTint(requireContext())
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (item.itemId) { when (menuItem.itemId) {
R.id.menu_help -> showHelp() R.id.menu_help -> showHelp()
} }
return super.onOptionsItemSelected(item) return true
} }
private fun showHelp() { private fun showHelp() {

@ -44,7 +44,6 @@ class CoverConfigFragment : PreferenceFragment(),
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.setTitle(R.string.cover_config) activity?.setTitle(R.string.cover_config)
listView.setEdgeEffectColor(primaryColor) listView.setEdgeEffectColor(primaryColor)
setHasOptionsMenu(true)
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

@ -10,6 +10,7 @@ import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.SeekBar import android.widget.SeekBar
import androidx.core.view.MenuProvider
import androidx.preference.Preference import androidx.preference.Preference
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.AppContextWrapper import io.legado.app.base.AppContextWrapper
@ -34,7 +35,8 @@ import java.io.FileOutputStream
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
class ThemeConfigFragment : PreferenceFragment(), class ThemeConfigFragment : PreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener,
MenuProvider {
private val requestCodeBgLight = 121 private val requestCodeBgLight = 121
private val requestCodeBgDark = 122 private val requestCodeBgDark = 122
@ -89,7 +91,7 @@ class ThemeConfigFragment : PreferenceFragment(),
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.setTitle(R.string.theme_setting) activity?.setTitle(R.string.theme_setting)
listView.setEdgeEffectColor(primaryColor) listView.setEdgeEffectColor(primaryColor)
setHasOptionsMenu(true) activity?.addMenuProvider(this, viewLifecycleOwner)
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -102,19 +104,19 @@ class ThemeConfigFragment : PreferenceFragment(),
preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this)
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater) menuInflater.inflate(R.menu.theme_config, menu)
inflater.inflate(R.menu.theme_config, menu) menu.applyTint(requireContext())
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (item.itemId) { when (menuItem.itemId) {
R.id.menu_theme_mode -> { R.id.menu_theme_mode -> {
AppConfig.isNightTheme = !AppConfig.isNightTheme AppConfig.isNightTheme = !AppConfig.isNightTheme
ThemeConfig.applyDayNight(requireContext()) ThemeConfig.applyDayNight(requireContext())
} }
} }
return super.onOptionsItemSelected(item) return true
} }
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {

@ -39,7 +39,6 @@ class WelcomeConfigFragment : PreferenceFragment(),
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
activity?.setTitle(R.string.welcome_style) activity?.setTitle(R.string.welcome_style)
listView.setEdgeEffectColor(primaryColor) listView.setEdgeEffectColor(primaryColor)
setHasOptionsMenu(true)
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

Loading…
Cancel
Save