From e492e27fc23050eb0e48a9eba52af7c7ac7d624b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 19 May 2020 14:39:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/config/ThemeConfigFragment.kt | 26 ++++++++++++++----- app/src/main/res/menu/theme_config.xml | 10 +++++++ 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/menu/theme_config.xml 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 488fe3b05..770b1830a 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 @@ -4,6 +4,9 @@ import android.annotation.SuppressLint import android.content.SharedPreferences import android.os.Build import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -20,7 +23,6 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ColorUtils import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.IconListPreference -import io.legado.app.ui.widget.prefs.NameListPreference import io.legado.app.utils.* @@ -35,18 +37,13 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar preferenceScreen.removePreference(it) } } - findPreference(PreferKey.themeMode)?.let { - it.setOnPreferenceChangeListener { _, _ -> - view?.post { App.INSTANCE.applyDayNight() } - true - } - } upPreferenceSummary("barElevation", AppConfig.elevation.toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ATH.applyEdgeEffectColor(listView) + setHasOptionsMenu(true) } override fun onResume() { @@ -59,6 +56,21 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar super.onPause() } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + super.onCreateOptionsMenu(menu, inflater) + inflater.inflate(R.menu.theme_config, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_theme_mode -> { + AppConfig.isNightTheme = !AppConfig.isNightTheme + App.INSTANCE.applyDayNight() + } + } + return super.onOptionsItemSelected(item) + } + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { sharedPreferences ?: return when (key) { diff --git a/app/src/main/res/menu/theme_config.xml b/app/src/main/res/menu/theme_config.xml new file mode 100644 index 000000000..5033089ac --- /dev/null +++ b/app/src/main/res/menu/theme_config.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file