mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Encapsulate putItems
This commit is contained in:
@@ -32,6 +32,20 @@ abstract class AnimatedItemsAdapter<Item, T: RecyclerView.ViewHolder>(val contex
|
||||
onListSizeChangedListener?.invoke(previousSize, itemsList.size)
|
||||
}
|
||||
|
||||
open fun putItem(item: Item) {
|
||||
val previousSize = itemsList.size
|
||||
if (itemsList.contains(item)) {
|
||||
val index = itemsList.indexOf(item)
|
||||
itemsList.removeAt(index)
|
||||
itemsList.add(index, item)
|
||||
notifyItemChanged(index)
|
||||
} else {
|
||||
itemsList.add(item)
|
||||
notifyItemInserted(itemsList.indexOf(item))
|
||||
}
|
||||
onListSizeChangedListener?.invoke(previousSize, itemsList.size)
|
||||
}
|
||||
|
||||
fun onBindDeleteButton(holder: T, deleteButton: View, item: Item, position: Int) {
|
||||
deleteButton.apply {
|
||||
visibility = View.VISIBLE
|
||||
|
||||
@@ -42,7 +42,7 @@ class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
}
|
||||
private var mValueViewInputType: Int = 0
|
||||
private var mLastFocused: Field? = null
|
||||
private var mLastFocusedTimestamp: Long = 0
|
||||
private var mLastFocusedTimestamp: Long = 0L
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EntryExtraFieldViewHolder {
|
||||
val view = EntryExtraFieldViewHolder(
|
||||
@@ -97,35 +97,24 @@ class EntryExtraFieldsItemsAdapter(context: Context)
|
||||
}
|
||||
*/
|
||||
|
||||
private fun focusField(field: Field) {
|
||||
private fun focusField(field: Field, force: Boolean = false) {
|
||||
mLastFocused = field
|
||||
mLastFocusedTimestamp = System.currentTimeMillis()
|
||||
mLastFocusedTimestamp = if (force) 0L else System.currentTimeMillis()
|
||||
}
|
||||
|
||||
override fun putItem(item: Field) {
|
||||
focusField(item, true)
|
||||
super.putItem(item)
|
||||
}
|
||||
|
||||
private fun requestFocusOnLastTextFocused(textView: TextView, field: Field) {
|
||||
if (field == mLastFocused) {
|
||||
if ((mLastFocusedTimestamp + 350L) > System.currentTimeMillis())
|
||||
if (mLastFocusedTimestamp == 0L || (mLastFocusedTimestamp + 350L) > System.currentTimeMillis())
|
||||
textView.post { textView.requestFocus() }
|
||||
mLastFocused = null
|
||||
}
|
||||
}
|
||||
|
||||
fun putExtraField(field: Field) {
|
||||
val previousSize = itemsList.size
|
||||
if (itemsList.contains(field)) {
|
||||
val index = itemsList.indexOf(field)
|
||||
itemsList.removeAt(index)
|
||||
itemsList.add(index, field)
|
||||
focusField(field)
|
||||
notifyItemChanged(index)
|
||||
} else {
|
||||
itemsList.add(field)
|
||||
focusField(field)
|
||||
notifyItemInserted(itemsList.indexOf(field))
|
||||
}
|
||||
onListSizeChangedListener?.invoke(previousSize, itemsList.size)
|
||||
}
|
||||
|
||||
inner class EntryExtraFieldViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var extraFieldValueContainer: TextInputLayout = itemView.findViewById(R.id.entry_extra_field_value_container)
|
||||
var extraFieldValue: EditText = itemView.findViewById(R.id.entry_extra_field_value)
|
||||
|
||||
@@ -259,7 +259,7 @@ class EntryEditContentsView @JvmOverloads constructor(context: Context,
|
||||
fun putExtraField(extraField: Field) {
|
||||
extraFieldsContainerView.visibility = View.VISIBLE
|
||||
// TODO setError(R.string.error_label_exists)
|
||||
extraFieldsAdapter.putExtraField(extraField)
|
||||
extraFieldsAdapter.putItem(extraField)
|
||||
}
|
||||
|
||||
/* -------------
|
||||
|
||||
Reference in New Issue
Block a user