pull/32/head
parent
57a43b363f
commit
d8a27fb97e
@ -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) |
||||
} |
||||
|
||||
} |
@ -1,30 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
<LinearLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<io.legado.app.ui.widget.TitleBar |
||||
android:id="@+id/title_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:attachToActivity="false" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:title="我的"/> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
<LinearLayout |
||||
android:id="@+id/pre_fragment" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintTop_toBottomOf="@+id/title_bar"> |
||||
|
||||
<TextView |
||||
android:id="@+id/tv_theme_config" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:padding="15dp" |
||||
android:text="@string/theme_setting"/> |
||||
|
||||
</androidx.core.widget.NestedScrollView> |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
</LinearLayout> |
@ -0,0 +1,25 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.preference.PreferenceScreen |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="setting" |
||||
android:title="设置" |
||||
android:summary="与功能相关的一些设置" |
||||
app:iconSpaceReserved="false"/> |
||||
|
||||
<androidx.preference.Preference |
||||
android:key="theme_setting" |
||||
android:title="主题设置" |
||||
android:summary="与界面/颜色相关的一些设置" |
||||
app:iconSpaceReserved="false"/> |
||||
|
||||
<io.legado.app.lib.theme.prefs.ATESwitchPreference |
||||
android:defaultValue="false" |
||||
android:key="isNightTheme" |
||||
android:summary="开启/关闭暗色主题" |
||||
android:title="暗色主题" |
||||
app:iconSpaceReserved="false"/> |
||||
|
||||
</androidx.preference.PreferenceScreen> |
Loading…
Reference in new issue