mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Revert EditTextVisibility #660
This commit is contained in:
@@ -22,14 +22,16 @@ package com.kunzisoft.keepass.adapters
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.model.Field
|
||||
import com.kunzisoft.keepass.model.FocusedEditField
|
||||
import com.kunzisoft.keepass.view.EditTextSelectable
|
||||
import com.kunzisoft.keepass.view.EditTextVisibility
|
||||
import com.kunzisoft.keepass.view.applyFontVisibility
|
||||
|
||||
class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
: AnimatedItemsAdapter<Field, EntryExtraFieldsItemsAdapter.EntryExtraFieldViewHolder>(context) {
|
||||
@@ -39,32 +41,40 @@ class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
private var mValueViewInputType: Int = 0
|
||||
private var mLastFocusedEditField = FocusedEditField()
|
||||
private var mLastFocusedTimestamp: Long = 0L
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryExtraFieldViewHolder {
|
||||
return EntryExtraFieldViewHolder(
|
||||
val view = EntryExtraFieldViewHolder(
|
||||
inflater.inflate(R.layout.item_entry_edit_extra_field, parent, false)
|
||||
)
|
||||
mValueViewInputType = view.extraFieldValue.inputType
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: EntryExtraFieldViewHolder, position: Int) {
|
||||
val extraField = itemsList[position]
|
||||
|
||||
holder.itemView.visibility = View.VISIBLE
|
||||
val isProtected = extraField.protectedValue.isProtected
|
||||
holder.extraFieldText.apply {
|
||||
setLabel(extraField.name)
|
||||
// TODO hiddenProtectedValue = isProtected
|
||||
setValue(extraField.protectedValue.toString(), isProtected)
|
||||
if (extraField.protectedValue.isProtected) {
|
||||
holder.extraFieldValueContainer.isPasswordVisibilityToggleEnabled = true
|
||||
holder.extraFieldValue.inputType = EditorInfo.TYPE_TEXT_VARIATION_PASSWORD or mValueViewInputType
|
||||
} else {
|
||||
holder.extraFieldValueContainer.isPasswordVisibilityToggleEnabled = false
|
||||
holder.extraFieldValue.inputType = mValueViewInputType
|
||||
}
|
||||
holder.extraFieldValueContainer.hint = extraField.name
|
||||
holder.extraFieldValue.apply {
|
||||
setText(extraField.protectedValue.toString())
|
||||
// To Fix focus in RecyclerView
|
||||
valueView.setOnFocusChangeListener { _, hasFocus ->
|
||||
setOnFocusChangeListener { _, hasFocus ->
|
||||
if (hasFocus) {
|
||||
setFocusField(extraField, valueView.selectionStart, valueView.selectionEnd)
|
||||
setFocusField(extraField, selectionStart, selectionEnd)
|
||||
} else {
|
||||
// request focus on last text focused
|
||||
if (focusedTimestampNotExpired()) {
|
||||
requestFocusField(valueView, extraField, false)
|
||||
requestFocusField(this, extraField, false)
|
||||
} else {
|
||||
removeFocusField(extraField)
|
||||
}
|
||||
@@ -78,11 +88,12 @@ class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
}
|
||||
}
|
||||
})
|
||||
requestFocusField(valueView, extraField, true)
|
||||
valueView.doOnTextChanged { text, _, _, _ ->
|
||||
requestFocusField(this, extraField, true)
|
||||
doOnTextChanged { text, _, _, _ ->
|
||||
extraField.protectedValue.stringValue = text.toString()
|
||||
}
|
||||
applyFontVisibility(applyFontVisibility)
|
||||
if (applyFontVisibility)
|
||||
applyFontVisibility()
|
||||
}
|
||||
holder.extraFieldDeleteButton.apply {
|
||||
onBindDeleteButton(holder, this, extraField, position)
|
||||
@@ -154,7 +165,8 @@ class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
}
|
||||
|
||||
class EntryExtraFieldViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var extraFieldText: EditTextVisibility = itemView.findViewById(R.id.entry_extra_field_text)
|
||||
var extraFieldValueContainer: TextInputLayout = itemView.findViewById(R.id.entry_extra_field_value_container)
|
||||
var extraFieldValue: EditTextSelectable = itemView.findViewById(R.id.entry_extra_field_value)
|
||||
var extraFieldDeleteButton: View = itemView.findViewById(R.id.entry_extra_field_delete)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class EditTextVisibility @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0)
|
||||
: ConstraintLayout(context, attrs, defStyle) {
|
||||
|
||||
private val labelView: TextInputLayout
|
||||
val valueView: EditTextSelectable
|
||||
private val showButtonView: ImageView
|
||||
private var isProtected = false
|
||||
|
||||
private var mCursorSelectionStart: Int = -1
|
||||
private var mCursorSelectionEnd: Int = -1
|
||||
|
||||
var hiddenProtectedValue: Boolean
|
||||
get() {
|
||||
return showButtonView.isSelected
|
||||
}
|
||||
set(value) {
|
||||
showButtonView.isSelected = !value
|
||||
changeProtectedValueParameters()
|
||||
}
|
||||
|
||||
init {
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
|
||||
inflater?.inflate(R.layout.view_edit_text_visibility, this)
|
||||
|
||||
labelView = findViewById(R.id.edit_text_label)
|
||||
valueView = findViewById(R.id.edit_text_value)
|
||||
showButtonView = findViewById(R.id.edit_text_show)
|
||||
}
|
||||
|
||||
fun applyFontVisibility(fontInVisibility: Boolean) {
|
||||
if (fontInVisibility)
|
||||
valueView.applyFontVisibility()
|
||||
}
|
||||
|
||||
fun setLabel(label: String?) {
|
||||
labelView.hint = label ?: ""
|
||||
}
|
||||
|
||||
fun setLabel(@StringRes labelId: Int) {
|
||||
labelView.hint = resources.getString(labelId)
|
||||
}
|
||||
|
||||
fun setValue(value: String?,
|
||||
isProtected: Boolean = false) {
|
||||
valueView.setText(value ?: "")
|
||||
this.isProtected = isProtected
|
||||
showButtonView.visibility = if (isProtected) View.VISIBLE else View.GONE
|
||||
showButtonView.setOnClickListener {
|
||||
showButtonView.isSelected = !showButtonView.isSelected
|
||||
mCursorSelectionStart = valueView.selectionStart
|
||||
mCursorSelectionEnd = valueView.selectionEnd
|
||||
val focus = hasFocus()
|
||||
changeProtectedValueParameters()
|
||||
setValueSelection()
|
||||
if (focus) {
|
||||
requestFocus()
|
||||
}
|
||||
}
|
||||
changeProtectedValueParameters()
|
||||
}
|
||||
|
||||
fun setValue(@StringRes valueId: Int,
|
||||
isProtected: Boolean = false) {
|
||||
setValue(resources.getString(valueId), isProtected)
|
||||
}
|
||||
|
||||
private fun changeProtectedValueParameters() {
|
||||
valueView.apply {
|
||||
applyHiddenStyle(isProtected && !showButtonView.isSelected, false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setValueSelection() {
|
||||
try {
|
||||
var newCursorPositionStart = mCursorSelectionStart
|
||||
var newCursorPositionEnd = mCursorSelectionEnd
|
||||
// Cursor at end if 0 or less
|
||||
val textLength = (valueView.text?:"").length
|
||||
if (newCursorPositionStart < 0 || newCursorPositionEnd < 0
|
||||
|| newCursorPositionStart > textLength || newCursorPositionEnd > textLength) {
|
||||
newCursorPositionStart = textLength
|
||||
newCursorPositionEnd = newCursorPositionStart
|
||||
}
|
||||
valueView.setSelection(newCursorPositionStart, newCursorPositionEnd)
|
||||
} catch (ignoredException: Exception) {}
|
||||
}
|
||||
|
||||
fun addOnSelectionChangedListener(onSelectionChangedListener: EditTextSelectable.OnSelectionChangedListener) {
|
||||
valueView.addOnSelectionChangedListener(onSelectionChangedListener)
|
||||
}
|
||||
|
||||
fun removeOnSelectionChangedListener(onSelectionChangedListener: EditTextSelectable.OnSelectionChangedListener) {
|
||||
valueView.removeOnSelectionChangedListener(onSelectionChangedListener)
|
||||
}
|
||||
|
||||
fun removeAllOnSelectionChangedListeners() {
|
||||
valueView.removeAllOnSelectionChangedListeners()
|
||||
}
|
||||
}
|
||||
@@ -25,14 +25,25 @@
|
||||
android:layout_height="wrap_content"
|
||||
tools:targetApi="o">
|
||||
|
||||
<com.kunzisoft.keepass.view.EditTextVisibility
|
||||
android:id="@+id/entry_extra_field_text"
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/entry_extra_field_value_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/entry_extra_field_delete" />
|
||||
app:layout_constraintEnd_toStartOf="@+id/entry_extra_field_delete">
|
||||
|
||||
<com.kunzisoft.keepass.view.EditTextSelectable
|
||||
android:id="@+id/entry_extra_field_value"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:importantForAccessibility="no"
|
||||
android:importantForAutofill="no" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/entry_extra_field_delete"
|
||||
@@ -40,6 +51,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:src="@drawable/ic_content_delete_white_24dp"
|
||||
android:contentDescription="@string/menu_delete"
|
||||
|
||||
Reference in New Issue
Block a user