diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index c195fe364..ba1b0dc8e 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -129,7 +129,8 @@ object ATH { } fun setTint( - view: View, @ColorInt color: Int, isDark: + view: View, + @ColorInt color: Int, isDark: Boolean = view.context.isNightTheme ) { TintHelper.setTintAuto(view, color, false, isDark) diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEEditTextPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEEditTextPreference.kt deleted file mode 100644 index 4828e1d66..000000000 --- a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEEditTextPreference.kt +++ /dev/null @@ -1,172 +0,0 @@ -package io.legado.app.lib.theme.prefs - -import android.annotation.SuppressLint -import android.app.Dialog -import android.content.Context -import android.content.DialogInterface -import android.os.Bundle -import android.os.Parcel -import android.os.Parcelable -import android.preference.Preference -import android.util.AttributeSet -import android.view.LayoutInflater -import android.view.View -import android.view.WindowManager -import android.widget.EditText -import android.widget.TextView -import androidx.appcompat.app.AlertDialog -import androidx.preference.EditTextPreference -import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.ThemeStore -import io.legado.app.utils.applyTint - -class ATEEditTextPreference(context: Context?, attrs: AttributeSet?) : - EditTextPreference(context, attrs), - DialogInterface.OnClickListener, DialogInterface.OnDismissListener { - - private var builder: AlertDialog.Builder? = null - private var dialog: AlertDialog? = null - private var editText: EditText? = null - - /** Which button was clicked. */ - private var mWhichButtonClicked: Int = 0 - - override fun onClick() { - if (dialog?.isShowing == true) return - showDialog(null) - } - - protected fun showDialog(state: Bundle?) { - val context = context - - mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE - - builder = AlertDialog.Builder(context) - .setTitle(dialogTitle) - .setIcon(dialogIcon) - .setPositiveButton(positiveButtonText, this) - .setNegativeButton(negativeButtonText, this) - - val builder = this.builder!! - - val contentView = onCreateDialogView() - if (contentView != null) { - onBindDialogView(contentView) - builder.setView(contentView) - } else { - builder.setMessage(dialogMessage) - } - - // Create the dialog - dialog = builder.create() - - val dialog = this.dialog!! - if (state != null) { - dialog.onRestoreInstanceState(state) - } - requestInputMethod(dialog) - dialog.setOnDismissListener(this) - dialog.show() - dialog.applyTint() - } - - protected fun onCreateDialogView(): View? { - if (dialogLayoutResource == 0) { - return null - } - - val inflater = LayoutInflater.from(context) - return inflater.inflate(dialogLayoutResource, null) - } - - private fun requestInputMethod(dialog: Dialog?) { - dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) - } - - - protected fun onBindDialogView(view: View) { - editText = view.findViewById(android.R.id.edit) - - checkNotNull(editText) { "Dialog view must contain an EditText with id" + " @android:id/edit" } - - view.findViewById(android.R.id.message).visibility = View.GONE - - editText?.let { - ATH.setTint(it, ThemeStore.accentColor(context)) - it.requestFocus() - it.setText(text) - // Place cursor at the end - it.setSelection(it.length()) - } - } - - override fun onClick(dialog: DialogInterface?, which: Int) { - mWhichButtonClicked = which - } - - override fun onDismiss(dialog: DialogInterface?) { - if (mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE) { - text = editText?.text.toString() - callChangeListener(text) - } - } - - override fun onSaveInstanceState(): Parcelable { - val superState = super.onSaveInstanceState() - if (dialog == null || !dialog!!.isShowing) { - return superState - } - - val myState = SavedState(superState) - myState.isDialogShowing = true - myState.dialogBundle = dialog!!.onSaveInstanceState() - return myState - } - - override fun onRestoreInstanceState(state: Parcelable?) { - if (state == null || state.javaClass != SavedState::class.java) { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state) - return - } - - val myState = state as SavedState? - super.onRestoreInstanceState(myState!!.superState) - if (myState.isDialogShowing) { - showDialog(myState.dialogBundle) - } - } - - private class SavedState : Preference.BaseSavedState { - internal var isDialogShowing: Boolean = false - internal var dialogBundle: Bundle? = null - - @SuppressLint("ParcelClassLoader") - constructor(source: Parcel) : super(source) { - isDialogShowing = source.readInt() == 1 - dialogBundle = source.readBundle() - } - - override fun writeToParcel(dest: Parcel, flags: Int) { - super.writeToParcel(dest, flags) - dest.writeInt(if (isDialogShowing) 1 else 0) - dest.writeBundle(dialogBundle) - } - - constructor(superState: Parcelable) : super(superState) - - companion object { - - @JvmField - val CREATOR: Parcelable.Creator = object : Parcelable.Creator { - override fun createFromParcel(`in`: Parcel): SavedState { - return SavedState(`in`) - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 0d6e77503..ed55aedfd 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.config import android.os.Bundle import android.text.InputType import android.view.View +import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -10,7 +11,7 @@ import io.legado.app.R import io.legado.app.help.storage.Backup import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH -import io.legado.app.lib.theme.prefs.ATEEditTextPreference +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getPrefString class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { @@ -19,8 +20,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference addPreferencesFromResource(R.xml.pref_config_web_dav) bindPreferenceSummaryToValue(findPreference("web_dav_url")) bindPreferenceSummaryToValue(findPreference("web_dav_account")) - findPreference("web_dav_password")?.let { + findPreference("web_dav_password")?.let { it.setOnBindEditTextListener { editText -> + ATH.setTint(editText, requireContext().accentColor) editText.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT } diff --git a/app/src/main/res/xml/pref_config_web_dav.xml b/app/src/main/res/xml/pref_config_web_dav.xml index c16768a20..84cb363ca 100644 --- a/app/src/main/res/xml/pref_config_web_dav.xml +++ b/app/src/main/res/xml/pref_config_web_dav.xml @@ -2,19 +2,19 @@ - - -