diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index d5cee5ee3..78915a534 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -60,6 +60,7 @@ abstract class BaseActivity : AppCompatActivity() { } protected fun initTheme() { + window.decorView.setBackgroundColor(ThemeStore.backgroundColor(this)) if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) { setTheme(R.style.AppTheme_Light) } else { diff --git a/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt b/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt index b7d27e01c..1b6d9bccf 100644 --- a/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.main.myconfig -import android.content.Intent import android.os.Bundle import android.util.Log import android.view.MenuItem @@ -9,10 +8,7 @@ import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import io.legado.app.App import io.legado.app.R -import io.legado.app.ui.config.ConfigActivity -import io.legado.app.ui.config.ConfigViewModel import io.legado.app.utils.setIconColor -import kotlinx.android.synthetic.main.fragment_my_config.* import kotlinx.android.synthetic.main.view_titlebar.* class MyConfigFragment : Fragment(R.layout.fragment_my_config), Toolbar.OnMenuItemClickListener { @@ -23,11 +19,7 @@ class MyConfigFragment : Fragment(R.layout.fragment_my_config), Toolbar.OnMenuIt toolbar.inflateMenu(R.menu.my_config) toolbar.menu.setIconColor(App.INSTANCE) toolbar.setOnMenuItemClickListener(this) - tv_theme_config.setOnClickListener { - val intent = Intent(context, ConfigActivity::class.java) - intent.putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG) - startActivity(intent) - } + childFragmentManager.beginTransaction().add(R.id.pre_fragment, PreferenceFragment()).commit() } override fun onMenuItemClick(item: MenuItem?): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt b/app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt new file mode 100644 index 000000000..0d5e2416d --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt @@ -0,0 +1,53 @@ +package io.legado.app.ui.main.myconfig + +import android.content.Intent +import android.content.SharedPreferences +import android.os.Bundle +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import io.legado.app.App +import io.legado.app.R +import io.legado.app.ui.config.ConfigActivity +import io.legado.app.ui.config.ConfigViewModel + +class PreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_main) + } + + override fun onResume() { + super.onResume() + preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + super.onPause() + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + when (key) { + "isNightTheme" -> { + App.INSTANCE.initNightTheme() + App.INSTANCE.upThemeStore() + } + } + } + + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + preference?.let { + when (preference.key) { + "setting" -> { + } + "theme_setting" -> { + val intent = Intent(context, ConfigActivity::class.java) + intent.putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG) + startActivity(intent) + } + } + } + return super.onPreferenceTreeClick(preference) + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_my_config.xml b/app/src/main/res/layout/fragment_my_config.xml index 5f568b619..2a2d1f8d5 100644 --- a/app/src/main/res/layout/fragment_my_config.xml +++ b/app/src/main/res/layout/fragment_my_config.xml @@ -1,30 +1,22 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - - - - - + android:layout_height="match_parent" + android:orientation="vertical"/> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index d53b8cac2..71fd9b2ec 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -6,9 +6,9 @@ #69000000 - @color/md_grey_800 - @color/md_grey_900 - @color/md_grey_100 + #008577 + #00574B + #D81B60 #30ffffff diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml new file mode 100644 index 000000000..ba6f6ac78 --- /dev/null +++ b/app/src/main/res/xml/pref_main.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file