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