pull/298/head
gedoor 4 years ago
parent bc2de4a6b8
commit 9f6df2b27e
  1. 61
      app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt
  2. 13
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 9
      app/src/main/java/io/legado/app/ui/about/AboutActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  6. 9
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  7. 4
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  8. 4
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  9. 4
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  10. 29
      app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt
  11. 29
      app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt
  12. 32
      app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt
  13. 2
      app/src/main/res/xml/pref_config_aloud.xml
  14. 11
      app/src/main/res/xml/pref_main.xml

@ -0,0 +1,61 @@
package io.legado.app.base
import android.annotation.SuppressLint
import androidx.fragment.app.DialogFragment
import androidx.preference.*
import io.legado.app.ui.widget.prefs.EditTextPreferenceDialog
import io.legado.app.ui.widget.prefs.ListPreferenceDialog
import io.legado.app.ui.widget.prefs.MultiSelectListPreferenceDialog
abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
private val dialogFragmentTag = "androidx.preference.PreferenceFragment.DIALOG"
@SuppressLint("RestrictedApi")
override fun onDisplayPreferenceDialog(preference: Preference) {
var handled = false
if (callbackFragment is OnPreferenceDisplayDialogCallback) {
handled =
(callbackFragment as OnPreferenceDisplayDialogCallback)
.onPreferenceDisplayDialog(this, preference)
}
if (!handled && activity is OnPreferenceDisplayDialogCallback) {
handled = (activity as OnPreferenceDisplayDialogCallback)
.onPreferenceDisplayDialog(this, preference)
}
if (handled) {
return
}
// check if dialog is already showing
if (parentFragmentManager.findFragmentByTag(dialogFragmentTag) != null) {
return
}
val f: DialogFragment = when (preference) {
is EditTextPreference -> {
EditTextPreferenceDialog.newInstance(preference.getKey())
}
is ListPreference -> {
ListPreferenceDialog.newInstance(preference.getKey())
}
is MultiSelectListPreference -> {
MultiSelectListPreferenceDialog.newInstance(preference.getKey())
}
else -> {
throw IllegalArgumentException(
"Cannot display dialog for an unknown Preference type: "
+ preference.javaClass.simpleName
+ ". Make sure to implement onPreferenceDisplayDialog() to handle "
+ "displaying a custom dialog for this Preference."
)
}
}
f.setTargetFragment(this, 0)
f.show(parentFragmentManager, dialogFragmentTag)
}
}

@ -16,6 +16,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.App
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.utils.dp
@ -140,10 +141,7 @@ object ATH {
}
fun setAlertDialogTint(dialog: AlertDialog): AlertDialog {
val background = GradientDrawable()
background.cornerRadius = 3F.dp
background.setColor(dialog.context.backgroundColor)
dialog.window?.setBackgroundDrawable(background)
dialog.window?.setBackgroundDrawable(getDialogBackground())
val colorStateList = Selector.colorBuild()
.setDefaultColor(ThemeStore.accentColor(dialog.context))
.setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(dialog.context)))
@ -233,6 +231,13 @@ object ATH {
}
}
fun getDialogBackground(): GradientDrawable {
val background = GradientDrawable()
background.cornerRadius = 3F.dp
background.setColor(App.INSTANCE.backgroundColor)
return background
}
private val DEFAULT_EFFECT_FACTORY = object : RecyclerView.EdgeEffectFactory() {
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
val edgeEffect = super.createEdgeEffect(view, direction)

@ -1,6 +1,5 @@
package io.legado.app.ui.about
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.text.Spannable
import android.text.SpannableString
@ -9,9 +8,8 @@ import android.view.Menu
import android.view.MenuItem
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.dp
import io.legado.app.utils.openUrl
import kotlinx.android.synthetic.main.activity_about.*
import org.jetbrains.anko.share
@ -20,10 +18,7 @@ import org.jetbrains.anko.share
class AboutActivity : BaseActivity(R.layout.activity_about) {
override fun onActivityCreated(savedInstanceState: Bundle?) {
val background = GradientDrawable()
background.cornerRadius = 3F.dp
background.setColor(backgroundColor)
ll_about.background = background
ll_about.background = ATH.getDialogBackground()
val fTag = "aboutFragment"
var aboutFragment = supportFragmentManager.findFragmentByTag(fTag)
if (aboutFragment == null) aboutFragment = AboutFragment()

@ -10,8 +10,8 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
@ -64,7 +64,7 @@ class MoreConfigDialog : DialogFragment() {
.commit()
}
class ReadPreferenceFragment : PreferenceFragmentCompat(),
class ReadPreferenceFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

@ -10,8 +10,8 @@ import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
@ -59,7 +59,7 @@ class ReadAloudConfigDialog : DialogFragment() {
.commit()
}
class ReadAloudPreferenceFragment : PreferenceFragmentCompat(),
class ReadAloudPreferenceFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

@ -8,17 +8,18 @@ import android.view.View
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.PreferKey
import io.legado.app.help.storage.Restore
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefString
class BackupConfigFragment : PreferenceFragmentCompat(),
class BackupConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener,
FileChooserDialog.CallBack {
@ -125,7 +126,9 @@ class BackupConfigFragment : PreferenceFragmentCompat(),
multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked ->
Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked
}
}.show().setOnDismissListener {
}.show()
.applyTint()
.setOnDismissListener {
Restore.saveIgnoreConfig()
}
}

@ -11,9 +11,9 @@ import android.view.View
import androidx.documentfile.provider.DocumentFile
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
@ -29,7 +29,7 @@ import io.legado.app.utils.*
import java.io.File
class OtherConfigFragment : PreferenceFragmentCompat(),
class OtherConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
private val requestCodeCover = 231

@ -9,9 +9,9 @@ import android.view.MenuInflater
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.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
@ -27,7 +27,7 @@ import io.legado.app.utils.*
@Suppress("SameParameterValue")
class ThemeConfigFragment : PreferenceFragmentCompat(),
class ThemeConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
val items = arrayListOf("极简", "曜夜", "经典", "黑白", "A屏黑")

@ -7,10 +7,10 @@ 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.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
@ -68,7 +68,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.
/**
* 配置
*/
class PreferenceFragment : PreferenceFragmentCompat(),
class PreferenceFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

@ -0,0 +1,29 @@
package io.legado.app.ui.widget.prefs
import android.app.Dialog
import android.os.Bundle
import androidx.preference.EditTextPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.ATH
class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() {
companion object {
fun newInstance(key: String): EditTextPreferenceDialog {
val fragment = EditTextPreferenceDialog()
val b = Bundle(1)
b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(ATH.getDialogBackground())
return dialog
}
}

@ -0,0 +1,29 @@
package io.legado.app.ui.widget.prefs
import android.app.Dialog
import android.os.Bundle
import androidx.preference.ListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.ATH
class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() {
companion object {
fun newInstance(key: String?): ListPreferenceDialog {
val fragment = ListPreferenceDialog()
val b = Bundle(1)
b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(ATH.getDialogBackground())
return dialog
}
}

@ -0,0 +1,32 @@
package io.legado.app.ui.widget.prefs
import android.app.Dialog
import android.os.Bundle
import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.ATH
class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() {
companion object {
fun newInstance(key: String?): MultiSelectListPreferenceDialog {
val fragment =
MultiSelectListPreferenceDialog()
val b = Bundle(1)
b.putString(PreferenceDialogFragmentCompat.ARG_KEY, key)
fragment.arguments = b
return fragment
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(ATH.getDialogBackground())
return dialog
}
}

@ -4,6 +4,8 @@
<io.legado.app.ui.widget.prefs.PreferenceCategory
android:title="@string/aloud_config"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false">
<io.legado.app.ui.widget.prefs.SwitchPreference

@ -2,9 +2,8 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:divider="@color/transparent"
app:allowDividerBelow="false"
app:allowDividerAbove="false"
>
app:allowDividerBelow="false">
<io.legado.app.ui.widget.prefs.Preference
android:key="bookSourceManage"
@ -41,9 +40,9 @@
<io.legado.app.ui.widget.prefs.PreferenceCategory
android:title="@string/setting"
app:iconSpaceReserved="false"
app:allowDividerAbove="true"
app:allowDividerBelow="false" >
app:allowDividerBelow="false"
app:iconSpaceReserved="false">
<io.legado.app.ui.widget.prefs.Preference
android:key="web_dav_setting"
@ -74,8 +73,8 @@
android:key="aboutCategory"
app:allowDividerAbove="true"
app:allowDividerBelow="false"
app:layout="@layout/view_preference_category"
app:iconSpaceReserved="false">
app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference
android:key="donate"

Loading…
Cancel
Save