pull/1876/head^2
kunfei 3 years ago
parent 425e20b2bc
commit 9e92cf266d
  1. 14
      app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt
  2. 9
      app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt
  3. 9
      app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt
  4. 9
      app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt
  5. 17
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -3,15 +3,25 @@ package io.legado.app.lib.prefs
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.TextView import android.widget.TextView
import androidx.preference.EditTextPreference.OnBindEditTextListener
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.applyTint
class EditTextPreference(context: Context, attrs: AttributeSet) : class EditTextPreference(context: Context, attrs: AttributeSet) :
androidx.preference.EditTextPreference(context, attrs) { androidx.preference.EditTextPreference(context, attrs) {
private var mOnBindEditTextListener: OnBindEditTextListener? = null
private val onBindEditTextListener = OnBindEditTextListener { editText ->
editText.applyTint(context.accentColor)
mOnBindEditTextListener?.onBindEditText(editText)
}
init { init {
// isPersistent = true // isPersistent = true
layoutResource = R.layout.view_preference layoutResource = R.layout.view_preference
super.setOnBindEditTextListener(onBindEditTextListener)
} }
override fun onBindViewHolder(holder: PreferenceViewHolder) { override fun onBindViewHolder(holder: PreferenceViewHolder) {
@ -19,4 +29,8 @@ class EditTextPreference(context: Context, attrs: AttributeSet) :
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
} }
override fun setOnBindEditTextListener(onBindEditTextListener: OnBindEditTextListener?) {
mOnBindEditTextListener = onBindEditTextListener
}
} }

@ -2,8 +2,10 @@ package io.legado.app.lib.prefs
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.preference.EditTextPreferenceDialogFragmentCompat import androidx.preference.EditTextPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground import io.legado.app.lib.theme.filletBackground
class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() {
@ -23,6 +25,13 @@ class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(requireContext().filletBackground) dialog.window?.setBackgroundDrawable(requireContext().filletBackground)
dialog.window?.decorView?.post {
(dialog as AlertDialog).run {
getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor)
}
}
return dialog return dialog
} }

@ -2,8 +2,10 @@ package io.legado.app.lib.prefs
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.preference.ListPreferenceDialogFragmentCompat import androidx.preference.ListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground import io.legado.app.lib.theme.filletBackground
class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() {
@ -23,6 +25,13 @@ class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(requireContext().filletBackground) dialog.window?.setBackgroundDrawable(requireContext().filletBackground)
dialog.window?.decorView?.post {
(dialog as AlertDialog).run {
getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor)
}
}
return dialog return dialog
} }

@ -2,8 +2,10 @@ package io.legado.app.lib.prefs
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.filletBackground import io.legado.app.lib.theme.filletBackground
class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() { class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() {
@ -25,6 +27,13 @@ class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentC
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setBackgroundDrawable(requireContext().filletBackground) dialog.window?.setBackgroundDrawable(requireContext().filletBackground)
dialog.window?.decorView?.post {
(dialog as AlertDialog).run {
getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor)
getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor)
}
}
return dialog return dialog
} }

@ -25,7 +25,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.prefs.fragment.PreferenceFragment
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
@ -100,28 +99,12 @@ class BackupConfigFragment : PreferenceFragment(),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_backup) addPreferencesFromResource(R.xml.pref_config_backup)
findPreference<EditTextPreference>(PreferKey.webDavUrl)?.let {
it.setOnBindEditTextListener { editText ->
editText.applyTint(requireContext().accentColor)
}
}
findPreference<EditTextPreference>(PreferKey.webDavAccount)?.let {
it.setOnBindEditTextListener { editText ->
editText.applyTint(requireContext().accentColor)
}
}
findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let { findPreference<EditTextPreference>(PreferKey.webDavPassword)?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
editText.applyTint(requireContext().accentColor)
editText.inputType = editText.inputType =
InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT
} }
} }
findPreference<EditTextPreference>(PreferKey.webDavDir)?.let {
it.setOnBindEditTextListener { editText ->
editText.applyTint(requireContext().accentColor)
}
}
upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl)) upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl))
upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount)) upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount))
upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword)) upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword))

Loading…
Cancel
Save