From 6c97d2963516669046e14282cdeabba58c1502b1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 9 Jul 2022 00:34:15 +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 --- .../app/ui/config/BackupConfigFragment.kt | 17 +++++++++-------- .../app/ui/config/CoverConfigFragment.kt | 1 - .../app/ui/config/ThemeConfigFragment.kt | 18 ++++++++++-------- .../app/ui/config/WelcomeConfigFragment.kt | 1 - 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 0801eadc7..885696cb9 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -8,6 +8,7 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View +import androidx.core.view.MenuProvider import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope @@ -39,7 +40,8 @@ import splitties.init.appCtx import kotlin.collections.set class BackupConfigFragment : PreferenceFragment(), - SharedPreferences.OnSharedPreferenceChangeListener { + SharedPreferences.OnSharedPreferenceChangeListener, + MenuProvider { private val viewModel by activityViewModels() @@ -124,23 +126,22 @@ class BackupConfigFragment : PreferenceFragment(), activity?.setTitle(R.string.backup_restore) preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) listView.setEdgeEffectColor(primaryColor) - setHasOptionsMenu(true) + activity?.addMenuProvider(this, viewLifecycleOwner) if (!LocalConfig.backupHelpVersionIsLast) { showHelp() } } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.backup_restore, menu) + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { + menuInflater.inflate(R.menu.backup_restore, menu) menu.applyTint(requireContext()) } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { + override fun onMenuItemSelected(menuItem: MenuItem): Boolean { + when (menuItem.itemId) { R.id.menu_help -> showHelp() } - return super.onOptionsItemSelected(item) + return true } private fun showHelp() { diff --git a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt index 45496d0c9..6931ed155 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -44,7 +44,6 @@ class CoverConfigFragment : PreferenceFragment(), super.onViewCreated(view, savedInstanceState) activity?.setTitle(R.string.cover_config) listView.setEdgeEffectColor(primaryColor) - setHasOptionsMenu(true) } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 567217e07..c54203a97 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -10,6 +10,7 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.widget.SeekBar +import androidx.core.view.MenuProvider import androidx.preference.Preference import io.legado.app.R import io.legado.app.base.AppContextWrapper @@ -34,7 +35,8 @@ import java.io.FileOutputStream @Suppress("SameParameterValue") class ThemeConfigFragment : PreferenceFragment(), - SharedPreferences.OnSharedPreferenceChangeListener { + SharedPreferences.OnSharedPreferenceChangeListener, + MenuProvider { private val requestCodeBgLight = 121 private val requestCodeBgDark = 122 @@ -89,7 +91,7 @@ class ThemeConfigFragment : PreferenceFragment(), super.onViewCreated(view, savedInstanceState) activity?.setTitle(R.string.theme_setting) listView.setEdgeEffectColor(primaryColor) - setHasOptionsMenu(true) + activity?.addMenuProvider(this, viewLifecycleOwner) } override fun onCreate(savedInstanceState: Bundle?) { @@ -102,19 +104,19 @@ class ThemeConfigFragment : PreferenceFragment(), preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.theme_config, menu) + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { + menuInflater.inflate(R.menu.theme_config, menu) + menu.applyTint(requireContext()) } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { + override fun onMenuItemSelected(menuItem: MenuItem): Boolean { + when (menuItem.itemId) { R.id.menu_theme_mode -> { AppConfig.isNightTheme = !AppConfig.isNightTheme ThemeConfig.applyDayNight(requireContext()) } } - return super.onOptionsItemSelected(item) + return true } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { diff --git a/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt index 2e9ea30c5..33b1b1689 100644 --- a/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt @@ -39,7 +39,6 @@ class WelcomeConfigFragment : PreferenceFragment(), super.onViewCreated(view, savedInstanceState) activity?.setTitle(R.string.welcome_style) listView.setEdgeEffectColor(primaryColor) - setHasOptionsMenu(true) } override fun onCreate(savedInstanceState: Bundle?) {