|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.adapter |
|
|
|
|
|
|
|
|
|
import android.text.Editable |
|
|
|
|
import android.text.InputType |
|
|
|
|
import android.text.TextWatcher |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
@ -16,7 +17,6 @@ import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.holder.RowViewHolder |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier |
|
|
|
|
import net.pokeranalytics.android.util.extensions.formatted |
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
enum class HandRowType(var layoutRes: Int) : ViewIdentifier { |
|
|
|
|
@ -97,20 +97,29 @@ class HandHistoryAdapter( |
|
|
|
|
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { |
|
|
|
|
|
|
|
|
|
private var listener = TextListener() |
|
|
|
|
private var currentPosition = 0 |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
// Action |
|
|
|
|
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText -> |
|
|
|
|
|
|
|
|
|
actionEditText.inputType = InputType.TYPE_NULL |
|
|
|
|
actionEditText.setTextIsSelectable(false) |
|
|
|
|
|
|
|
|
|
actionEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
Timber.d("focus change = $hasFocus at position = $position") |
|
|
|
|
actionEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
Timber.d("ACTION > focus change = $hasFocus at position = $currentPosition") |
|
|
|
|
editTextSelected(actionEditText, hasFocus, HHKeyboard.ACTION.ordinal) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Amount |
|
|
|
|
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> |
|
|
|
|
|
|
|
|
|
amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL |
|
|
|
|
|
|
|
|
|
amountEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
Timber.d("focus change = $hasFocus at position = $position") |
|
|
|
|
amountEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
Timber.d("AMOUNT > focus change = $hasFocus at position = $currentPosition") |
|
|
|
|
editTextSelected(amountEditText, hasFocus, HHKeyboard.AMOUNT.ordinal) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
amountEditText.addTextChangedListener(this.listener) |
|
|
|
|
@ -118,13 +127,23 @@ class HandHistoryAdapter( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun editTextSelected(editText: EditText, hasFocus: Boolean, tag: Int) { |
|
|
|
|
editText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
if (hasFocus) { |
|
|
|
|
val row = dataSource.rowRepresentableForPosition(currentPosition) |
|
|
|
|
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") |
|
|
|
|
delegate?.onRowSelected(currentPosition, row, tag) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
|
this.listener.position = position |
|
|
|
|
|
|
|
|
|
this.currentPosition = position |
|
|
|
|
|
|
|
|
|
val computedAction = row as ComputedAction |
|
|
|
|
|
|
|
|
|
@ -137,7 +156,7 @@ class HandHistoryAdapter( |
|
|
|
|
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText -> |
|
|
|
|
val tag = HHKeyboard.ACTION.ordinal |
|
|
|
|
|
|
|
|
|
actionEditText.isFocusable = computedAction.actionTypeCanBeEdited |
|
|
|
|
|
|
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
|
// Timber.d("Action at $position is selected: $selected") |
|
|
|
|
actionEditText.setBackgroundColor(color(selected)) |
|
|
|
|
@ -148,53 +167,23 @@ class HandHistoryAdapter( |
|
|
|
|
actionEditText.text = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (selected) actionEditText.requestFocus() else actionEditText.clearFocus() |
|
|
|
|
|
|
|
|
|
// actionEditText.setOnClickListener { |
|
|
|
|
// |
|
|
|
|
// Timber.d("OnClickListener at $position") |
|
|
|
|
// val isSelected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
|
// if (!isSelected && computedAction.actionTypeCanBeEdited) { |
|
|
|
|
// actionEditText.requestFocus() |
|
|
|
|
// adapter.delegate?.onRowSelected(position, row, tag) |
|
|
|
|
// actionEditText.setBackgroundColor(color(true)) |
|
|
|
|
// } else { |
|
|
|
|
// adapter.delegate?.onRowDeselected(position, row) |
|
|
|
|
// actionEditText.setBackgroundColor(color(false)) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// actionEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
// Timber.d("focus change = $hasFocus at position = $position") |
|
|
|
|
// actionEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
// } |
|
|
|
|
if (selected) actionEditText.requestFocus()// else actionEditText.clearFocus() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Amount |
|
|
|
|
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> |
|
|
|
|
amountEditText.isFocusable = computedAction.amountCanBeEdited |
|
|
|
|
val tag = HHKeyboard.AMOUNT.ordinal |
|
|
|
|
|
|
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
|
Timber.d("Amount at $position is selected: $selected") |
|
|
|
|
// Timber.d("Amount at $position is selected: $selected") |
|
|
|
|
amountEditText.setBackgroundColor(color(selected)) |
|
|
|
|
|
|
|
|
|
amountEditText.setText(computedAction.action.amount?.formatted()) |
|
|
|
|
|
|
|
|
|
if (selected) amountEditText.requestFocus() else amountEditText.clearFocus() |
|
|
|
|
|
|
|
|
|
// amountEditText.setOnTouchListener { v, event -> |
|
|
|
|
// Timber.d("OnClickListener at $position") |
|
|
|
|
// adapter.delegate?.onRowSelected(position, row, tag) |
|
|
|
|
// amountEditText.setBackgroundColor(color(true)) |
|
|
|
|
// return@setOnTouchListener true |
|
|
|
|
// } |
|
|
|
|
// amountEditText.setOnFocusChangeListener { v, hasFocus -> |
|
|
|
|
// Timber.d("focus change = $hasFocus at position = $position") |
|
|
|
|
// amountEditText.setBackgroundColor(color(hasFocus)) |
|
|
|
|
// } |
|
|
|
|
// amountEditText.addTextChangedListener { |
|
|
|
|
// adapter.delegate?.onRowValueChanged(it.toString(), row) |
|
|
|
|
// } |
|
|
|
|
amountEditText.setText(computedAction.action.displayedFormattedAmount) |
|
|
|
|
|
|
|
|
|
if (selected && !amountEditText.hasFocus()) amountEditText.requestFocus()// else amountEditText.clearFocus() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|