pull/32/head
GKF 6 years ago
parent 57a43b363f
commit d8a27fb97e
  1. 1
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/main/myconfig/MyConfigFragment.kt
  3. 53
      app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt
  4. 24
      app/src/main/res/layout/fragment_my_config.xml
  5. 6
      app/src/main/res/values-night/colors.xml
  6. 25
      app/src/main/res/xml/pref_main.xml

@ -60,6 +60,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() {
} }
protected fun initTheme() { protected fun initTheme() {
window.decorView.setBackgroundColor(ThemeStore.backgroundColor(this))
if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) { if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) {
setTheme(R.style.AppTheme_Light) setTheme(R.style.AppTheme_Light)
} else { } else {

@ -1,6 +1,5 @@
package io.legado.app.ui.main.myconfig package io.legado.app.ui.main.myconfig
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.MenuItem import android.view.MenuItem
@ -9,10 +8,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.App import io.legado.app.App
import io.legado.app.R 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 io.legado.app.utils.setIconColor
import kotlinx.android.synthetic.main.fragment_my_config.*
import kotlinx.android.synthetic.main.view_titlebar.* import kotlinx.android.synthetic.main.view_titlebar.*
class MyConfigFragment : Fragment(R.layout.fragment_my_config), Toolbar.OnMenuItemClickListener { 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.inflateMenu(R.menu.my_config)
toolbar.menu.setIconColor(App.INSTANCE) toolbar.menu.setIconColor(App.INSTANCE)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
tv_theme_config.setOnClickListener { childFragmentManager.beginTransaction().add(R.id.pre_fragment, PreferenceFragment()).commit()
val intent = Intent(context, ConfigActivity::class.java)
intent.putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG)
startActivity(intent)
}
} }
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {

@ -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"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical">
<io.legado.app.ui.widget.TitleBar <io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:attachToActivity="false" app:attachToActivity="false"
app:layout_constraintTop_toTopOf="parent"
app:title="我的"/> app:title="我的"/>
<androidx.core.widget.NestedScrollView <LinearLayout
android:id="@+id/pre_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar"> android:orientation="vertical"/>
<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>
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>

@ -6,9 +6,9 @@
<color name="night_mask">#69000000</color> <color name="night_mask">#69000000</color>
<color name="colorPrimary">@color/md_grey_800</color> <color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">@color/md_grey_900</color> <color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">@color/md_grey_100</color> <color name="colorAccent">#D81B60</color>
<color name="transparent30">#30ffffff</color> <color name="transparent30">#30ffffff</color>

@ -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…
Cancel
Save