pull/34/head
kunfei 5 years ago
parent 8895a8dc5e
commit 5505659dcf
  1. 72
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  2. 71
      app/src/main/java/io/legado/app/ui/main/my/PreferenceFragment.kt
  3. 2
      app/src/main/res/menu/my_config.xml

@ -1,14 +1,25 @@
package io.legado.app.ui.main.my package io.legado.app.ui.main.my
import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View 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.R
import io.legado.app.base.BaseFragment 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 io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity
class MyFragment : BaseFragment(R.layout.fragment_my_config) { 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) { override fun onCompatOptionsItemSelected(item: MenuItem) {
when (item.itemId) { when (item.itemId) {
R.id.action_settings -> startActivity<ReadBookActivity>() R.id.menu_help -> startActivity<AboutActivity>()
} }
} }
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<BookSourceActivity>()
"replaceManage" -> context?.startActivity<ReplaceRuleActivity>()
"setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_CONFIG)
)
"web_dav_setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
)
"theme_setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
)
"donate" -> context?.startActivity<DonateActivity>()
"about" -> context?.startActivity<AboutActivity>()
else -> null
}
}
return super.onPreferenceTreeClick(preference)
}
}
} }

@ -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<BookSourceActivity>()
"replaceManage" -> context?.startActivity<ReplaceRuleActivity>()
"setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_CONFIG)
)
"web_dav_setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
)
"theme_setting" -> context?.startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
)
"donate" -> context?.startActivity<DonateActivity>()
"about" -> context?.startActivity<AboutActivity>()
else -> null
}
}
return super.onPreferenceTreeClick(preference)
}
}

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_settings" android:id="@+id/menu_help"
android:title="@string/help" android:title="@string/help"
android:icon="@drawable/ic_live_help_black_24dp" android:icon="@drawable/ic_live_help_black_24dp"
app:showAsAction="always" /> app:showAsAction="always" />

Loading…
Cancel
Save