|
|
|
|
@ -281,7 +281,7 @@ enum class RowViewType(private var layoutRes: Int) { |
|
|
|
|
// Listener |
|
|
|
|
val listener = View.OnClickListener { |
|
|
|
|
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let { |
|
|
|
|
if (adapter.dataSource.isEnabled(row)) { |
|
|
|
|
if (adapter.dataSource.isEnabled(row, 0)) { |
|
|
|
|
it.isChecked = !it.isChecked |
|
|
|
|
} |
|
|
|
|
} ?: run { |
|
|
|
|
@ -296,7 +296,7 @@ enum class RowViewType(private var layoutRes: Int) { |
|
|
|
|
// Switch |
|
|
|
|
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let { |
|
|
|
|
it.isChecked = adapter.dataSource.boolForRow(row) |
|
|
|
|
it.isEnabled = adapter.dataSource.isEnabled(row) |
|
|
|
|
it.isEnabled = adapter.dataSource.isEnabled(row, 0) |
|
|
|
|
it.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
adapter.delegate?.onRowValueChanged(isChecked, row) |
|
|
|
|
} |
|
|
|
|
@ -304,7 +304,7 @@ enum class RowViewType(private var layoutRes: Int) { |
|
|
|
|
|
|
|
|
|
// Selected row |
|
|
|
|
itemView.findViewById<AppCompatImageView?>(R.id.check)?.let { |
|
|
|
|
it.isSelected = adapter.dataSource.isSelected(row) |
|
|
|
|
it.isSelected = adapter.dataSource.isSelected(position, row, 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -726,6 +726,11 @@ enum class RowViewType(private var layoutRes: Int) { |
|
|
|
|
*/ |
|
|
|
|
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { |
|
|
|
|
|
|
|
|
|
private fun color(isFocused: Boolean) : Int { |
|
|
|
|
val color = if (isFocused) R.color.green_light else R.color.kaki_medium |
|
|
|
|
return itemView.context.getColor(color) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) { |
|
|
|
|
val computedAction = row as ComputedAction |
|
|
|
|
|
|
|
|
|
@ -735,57 +740,50 @@ enum class RowViewType(private var layoutRes: Int) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Action |
|
|
|
|
itemView.findViewById<EditText>(R.id.actionEditText)?.let { button -> |
|
|
|
|
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText -> |
|
|
|
|
val tag = HHKeyboard.ACTION.ordinal |
|
|
|
|
|
|
|
|
|
button.isFocusable = computedAction.actionTypeCanBeEdited |
|
|
|
|
|
|
|
|
|
adapter.dataSource.color(position, row, HHKeyboard.ACTION.ordinal)?.let { color -> |
|
|
|
|
button.setBackgroundColor(color) |
|
|
|
|
} |
|
|
|
|
actionEditText.isFocusable = computedAction.actionTypeCanBeEdited |
|
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
|
Timber.d("Action at $position is selected: $selected") |
|
|
|
|
actionEditText.setBackgroundColor(color(selected)) |
|
|
|
|
|
|
|
|
|
computedAction.action.type?.resId?.let { |
|
|
|
|
button.setText(it) |
|
|
|
|
actionEditText.setText(it) |
|
|
|
|
} |
|
|
|
|
// button.setOnClickListener { |
|
|
|
|
// } |
|
|
|
|
button.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
Timber.d("Action Focus change: $hasFocus") |
|
|
|
|
|
|
|
|
|
if (hasFocus) { |
|
|
|
|
adapter.delegate?.onRowSelected(position, row, HHKeyboard.ACTION.ordinal) |
|
|
|
|
} else { |
|
|
|
|
adapter.delegate?.onRowDeselected(position, row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
adapter.dataSource.color(position, row, HHKeyboard.ACTION.ordinal)?.let { color -> |
|
|
|
|
button.setBackgroundColor(color) |
|
|
|
|
} |
|
|
|
|
if (selected) actionEditText.requestFocus() |
|
|
|
|
|
|
|
|
|
actionEditText.setOnClickListener { |
|
|
|
|
adapter.delegate?.onRowSelected(position, row, tag) |
|
|
|
|
actionEditText.setBackgroundColor(color(true)) |
|
|
|
|
} |
|
|
|
|
actionEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
actionEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Amount |
|
|
|
|
itemView.findViewById<EditText>(R.id.amountEditText)?.let { editText -> |
|
|
|
|
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> |
|
|
|
|
val tag = HHKeyboard.AMOUNT.ordinal |
|
|
|
|
|
|
|
|
|
adapter.dataSource.color(position, row, HHKeyboard.AMOUNT.ordinal)?.let { color -> |
|
|
|
|
editText.setBackgroundColor(color) |
|
|
|
|
} |
|
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
|
Timber.d("Amount at $position is selected: $selected") |
|
|
|
|
amountEditText.setBackgroundColor(color(selected)) |
|
|
|
|
|
|
|
|
|
editText.setText(computedAction.action.amount?.formatted()) |
|
|
|
|
editText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
Timber.d("Amount Focus change: $hasFocus") |
|
|
|
|
if (hasFocus) { |
|
|
|
|
adapter.delegate?.onRowSelected(position, row, HHKeyboard.AMOUNT.ordinal) |
|
|
|
|
} else { |
|
|
|
|
adapter.delegate?.onRowDeselected(position, row) |
|
|
|
|
} |
|
|
|
|
amountEditText.setText(computedAction.action.amount?.formatted()) |
|
|
|
|
|
|
|
|
|
adapter.dataSource.color(position, row, HHKeyboard.AMOUNT.ordinal) |
|
|
|
|
?.let { color -> |
|
|
|
|
editText.setBackgroundColor(color) |
|
|
|
|
} |
|
|
|
|
if (selected) amountEditText.requestFocus() |
|
|
|
|
|
|
|
|
|
amountEditText.setOnClickListener { |
|
|
|
|
adapter.delegate?.onRowSelected(position, row, tag) |
|
|
|
|
amountEditText.setBackgroundColor(color(true)) |
|
|
|
|
} |
|
|
|
|
amountEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
amountEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
} |
|
|
|
|
editText.addTextChangedListener { |
|
|
|
|
amountEditText.addTextChangedListener { |
|
|
|
|
adapter.delegate?.onRowValueChanged(it.toString(), row) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|