From 9e92cf266d86398315946e3c107b539eee6a5c9c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 12 May 2022 21:14:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/lib/prefs/EditTextPreference.kt | 14 ++++++++++++++ .../app/lib/prefs/EditTextPreferenceDialog.kt | 9 +++++++++ .../app/lib/prefs/ListPreferenceDialog.kt | 9 +++++++++ .../prefs/MultiSelectListPreferenceDialog.kt | 9 +++++++++ .../app/ui/config/BackupConfigFragment.kt | 17 ----------------- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt index f32966841..defe645a8 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt @@ -3,15 +3,25 @@ package io.legado.app.lib.prefs import android.content.Context import android.util.AttributeSet import android.widget.TextView +import androidx.preference.EditTextPreference.OnBindEditTextListener import androidx.preference.PreferenceViewHolder import io.legado.app.R +import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint class EditTextPreference(context: Context, attrs: AttributeSet) : androidx.preference.EditTextPreference(context, attrs) { + private var mOnBindEditTextListener: OnBindEditTextListener? = null + private val onBindEditTextListener = OnBindEditTextListener { editText -> + editText.applyTint(context.accentColor) + mOnBindEditTextListener?.onBindEditText(editText) + } + init { // isPersistent = true layoutResource = R.layout.view_preference + super.setOnBindEditTextListener(onBindEditTextListener) } override fun onBindViewHolder(holder: PreferenceViewHolder) { @@ -19,4 +29,8 @@ class EditTextPreference(context: Context, attrs: AttributeSet) : super.onBindViewHolder(holder) } + override fun setOnBindEditTextListener(onBindEditTextListener: OnBindEditTextListener?) { + mOnBindEditTextListener = onBindEditTextListener + } + } diff --git a/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt index f3bd5137f..70066e770 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt @@ -2,8 +2,10 @@ package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.EditTextPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { @@ -23,6 +25,13 @@ class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) 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 } diff --git a/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt index d4e626299..7165ef744 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt @@ -2,8 +2,10 @@ package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.ListPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { @@ -23,6 +25,13 @@ class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) 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 } diff --git a/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt index 6bc6051b1..c1ab77708 100644 --- a/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt @@ -2,8 +2,10 @@ package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() { @@ -25,6 +27,13 @@ class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentC override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) 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 } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index bf3fa55ca..65a72dd9b 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -25,7 +25,6 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat 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.ui.document.HandleFileContract import io.legado.app.ui.widget.dialog.TextDialog @@ -100,28 +99,12 @@ class BackupConfigFragment : PreferenceFragment(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_backup) - findPreference(PreferKey.webDavUrl)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } - findPreference(PreferKey.webDavAccount)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) editText.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT } } - findPreference(PreferKey.webDavDir)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl)) upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount)) upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword))