feat: 优化

pull/219/head
kunfei 5 years ago
parent a0a2cd9402
commit e492e27fc2
  1. 26
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  2. 10
      app/src/main/res/menu/theme_config.xml

@ -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<NameListPreference>(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) {

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_theme_mode"
android:title="@string/theme_mode"
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save