diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index d88b87669..553b6fee7 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -1,14 +1,25 @@ package io.legado.app.ui.main.my +import android.content.SharedPreferences import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.ui.readbook.ReadBookActivity +import io.legado.app.lib.theme.ATH +import io.legado.app.ui.about.AboutActivity +import io.legado.app.ui.about.DonateActivity +import io.legado.app.ui.booksource.BookSourceActivity +import io.legado.app.ui.config.ConfigActivity +import io.legado.app.ui.config.ConfigViewModel +import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.view_title_bar.* +import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config) { @@ -26,7 +37,64 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { - R.id.action_settings -> startActivity() + R.id.menu_help -> startActivity() } } + + class PreferenceFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_main) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + ATH.applyEdgeEffectColor(listView) + } + + 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.applyDayNight() + } + } + } + + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + preference?.let { + when (preference.key) { + "bookSourceManage" -> context?.startActivity() + "replaceManage" -> context?.startActivity() + "setting" -> context?.startActivity( + Pair("configType", ConfigViewModel.TYPE_CONFIG) + ) + "web_dav_setting" -> context?.startActivity( + Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) + ) + "theme_setting" -> context?.startActivity( + Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) + ) + "donate" -> context?.startActivity() + "about" -> context?.startActivity() + else -> null + } + } + return super.onPreferenceTreeClick(preference) + } + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/PreferenceFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/PreferenceFragment.kt deleted file mode 100644 index 5b6eabd1c..000000000 --- a/app/src/main/java/io/legado/app/ui/main/my/PreferenceFragment.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.legado.app.ui.main.my - -import android.content.SharedPreferences -import android.os.Bundle -import android.view.View -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat -import io.legado.app.App -import io.legado.app.R -import io.legado.app.lib.theme.ATH -import io.legado.app.ui.about.AboutActivity -import io.legado.app.ui.about.DonateActivity -import io.legado.app.ui.booksource.BookSourceActivity -import io.legado.app.ui.config.ConfigActivity -import io.legado.app.ui.config.ConfigViewModel -import io.legado.app.ui.replacerule.ReplaceRuleActivity -import org.jetbrains.anko.startActivity - -class PreferenceFragment : PreferenceFragmentCompat(), - SharedPreferences.OnSharedPreferenceChangeListener { - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.pref_main) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - ATH.applyEdgeEffectColor(listView) - } - - 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.applyDayNight() - } - } - } - - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - preference?.let { - when (preference.key) { - "bookSourceManage" -> context?.startActivity() - "replaceManage" -> context?.startActivity() - "setting" -> context?.startActivity( - Pair("configType", ConfigViewModel.TYPE_CONFIG) - ) - "web_dav_setting" -> context?.startActivity( - Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) - ) - "theme_setting" -> context?.startActivity( - Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) - ) - "donate" -> context?.startActivity() - "about" -> context?.startActivity() - else -> null - } - } - return super.onPreferenceTreeClick(preference) - } - -} \ No newline at end of file diff --git a/app/src/main/res/menu/my_config.xml b/app/src/main/res/menu/my_config.xml index 6d6a37970..e54b68733 100644 --- a/app/src/main/res/menu/my_config.xml +++ b/app/src/main/res/menu/my_config.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto">