mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
fix: change password color dynamically #1490
This commit is contained in:
@@ -2,6 +2,7 @@ KeePassDX(4.0.3)
|
||||
* Fix "Save as" in Read Only mode #1666
|
||||
* Fix username autofill #1665 #530 #1572 #1426 #1523 #1556 #1653 #1658 #1508 #1667
|
||||
* Fix regex OTP recognition #1596
|
||||
* Change password color dynamically #1490
|
||||
* Small fixes #1641 #1656
|
||||
|
||||
KeePassDX(4.0.2)
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.InputFilter
|
||||
import android.text.InputType
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
@@ -17,6 +18,7 @@ import androidx.appcompat.widget.AppCompatImageButton
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
@@ -34,6 +36,9 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
private var valueViewId = ViewCompat.generateViewId()
|
||||
private var actionImageButtonId = ViewCompat.generateViewId()
|
||||
|
||||
private var textModified = false
|
||||
private var isColorizedPasswordActivated = PreferencesUtil.colorizePassword(context)
|
||||
|
||||
private val labelView = TextInputLayout(context).apply {
|
||||
layoutParams = LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
@@ -78,6 +83,20 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
init {
|
||||
// Manually write view to avoid view id bugs
|
||||
buildViews()
|
||||
// To change the password color dynamically
|
||||
valueView.doAfterTextChanged { editable ->
|
||||
editable?.let { text ->
|
||||
if (textModified) {
|
||||
textModified = false
|
||||
} else {
|
||||
textModified = true
|
||||
val selectionStart = valueView.selectionStart
|
||||
val selectionEnd = valueView.selectionEnd
|
||||
value = spannableValue(text.toString()).toString()
|
||||
valueView.setSelection(selectionStart, selectionEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
labelView.addView(valueView)
|
||||
addView(labelView)
|
||||
addView(actionImageButton)
|
||||
@@ -110,6 +129,15 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
return actionImageButton
|
||||
}
|
||||
|
||||
private fun spannableValue(value: String?): Spannable? {
|
||||
if (value == null)
|
||||
return null
|
||||
return if (isColorizedPasswordActivated && TemplateField.isStandardPasswordName(context, label))
|
||||
PasswordGenerator.getColorizedPassword(value)
|
||||
else
|
||||
SpannableString(value)
|
||||
}
|
||||
|
||||
override var label: String
|
||||
get() {
|
||||
return labelView.hint?.toString() ?: ""
|
||||
@@ -128,13 +156,7 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
return valueView.text?.toString() ?: ""
|
||||
}
|
||||
set(value) {
|
||||
val spannableString =
|
||||
if (PreferencesUtil.colorizePassword(context)
|
||||
&& TemplateField.isStandardPasswordName(context, label))
|
||||
PasswordGenerator.getColorizedPassword(value)
|
||||
else
|
||||
SpannableString(value)
|
||||
valueView.setText(spannableString)
|
||||
valueView.setText(spannableValue(value))
|
||||
}
|
||||
|
||||
override var default: String = ""
|
||||
@@ -145,6 +167,7 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
valueView.filters += InputFilter.LengthFilter(MAX_CHARS_LIMIT)
|
||||
}
|
||||
else -> {
|
||||
@Suppress("KotlinConstantConditions")
|
||||
val chars = if (numberChars > MAX_CHARS_LIMIT) MAX_CHARS_LIMIT else numberChars
|
||||
valueView.filters += InputFilter.LengthFilter(chars)
|
||||
}
|
||||
@@ -164,6 +187,7 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
valueView.maxLines = MAX_LINES_LIMIT
|
||||
}
|
||||
else -> {
|
||||
@Suppress("KotlinConstantConditions")
|
||||
val lines = if (numberLines > MAX_LINES_LIMIT) MAX_LINES_LIMIT else numberLines
|
||||
valueView.inputType = valueView.inputType or
|
||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
* Fix "Save as" in Read Only mode #1666
|
||||
* Fix username autofill #1665 #530 #1572 #1426 #1523 #1556 #1653 #1658 #1508 #1667
|
||||
* Fix regex OTP recognition #1596
|
||||
* Change password color dynamically #1490
|
||||
* Small fixes #1641 #1656
|
||||
@@ -1,4 +1,5 @@
|
||||
* Correction "Sauvegarder comme" en mode lecture seule #1666
|
||||
* Correction du nom d'utilisateur dans la reconnaissance automatique #1665 #530 #1572 #1426 #1523 #1556 #1653 #1658 #1508 #1667
|
||||
* Correction de la regex de reconnaissance OTP #1596
|
||||
* Changement de couleur de mot passe dynamique #1490
|
||||
* Petites corrections #1641 #1656
|
||||
|
||||
Reference in New Issue
Block a user