|
|
|
@ -9,21 +9,26 @@ import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.widget.Button |
|
|
|
import android.widget.Button |
|
|
|
import android.widget.EditText |
|
|
|
import android.widget.EditText |
|
|
|
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.model.handhistory.ComputedAction |
|
|
|
import net.pokeranalytics.android.model.handhistory.ComputedAction |
|
|
|
import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.formatted |
|
|
|
import net.pokeranalytics.android.ui.adapter.BindableHolder |
|
|
|
import net.pokeranalytics.android.ui.adapter.BindableHolder |
|
|
|
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.extensions.hideKeyboard |
|
|
|
import net.pokeranalytics.android.ui.extensions.hideKeyboard |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.holder.RowViewHolder |
|
|
|
import net.pokeranalytics.android.ui.view.holder.RowViewHolder |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class HandRowType(var layoutRes: Int) : ViewIdentifier { |
|
|
|
enum class HandRowType(var layoutRes: Int) : ViewIdentifier { |
|
|
|
HEADER(R.layout.row_header_title), |
|
|
|
HEADER(R.layout.row_header_title), |
|
|
|
ACTION(R.layout.row_hand_action), |
|
|
|
ACTION(R.layout.row_hand_action), |
|
|
|
@ -90,14 +95,35 @@ class HandHistoryAdapter( |
|
|
|
// |
|
|
|
// |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var currentPosition = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun color(isFocused: Boolean) : Int { |
|
|
|
|
|
|
|
val color = if (isFocused) R.color.kaki else R.color.kaki_medium |
|
|
|
|
|
|
|
return itemView.context.getColor(color) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun editTextSelected(editText: EditText, selected: Boolean, tag: Int) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editText.setBackgroundColor(color(selected)) |
|
|
|
|
|
|
|
val row = dataSource.rowRepresentableForPosition(currentPosition) |
|
|
|
|
|
|
|
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") |
|
|
|
|
|
|
|
val alreadySelected = dataSource.isSelected(currentPosition, row, tag) |
|
|
|
|
|
|
|
if (!alreadySelected && selected) { |
|
|
|
|
|
|
|
delegate?.onRowSelected(currentPosition, row, tag) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display a hand action |
|
|
|
* Display a hand action |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), |
|
|
|
inner class RowHandAction(itemView: View) : RowHandHolder(itemView), |
|
|
|
BindableHolder { |
|
|
|
BindableHolder { |
|
|
|
|
|
|
|
|
|
|
|
// private var listener = TextListener() |
|
|
|
// private var listener = TextListener() |
|
|
|
private var currentPosition = 0 |
|
|
|
|
|
|
|
private var actionCanBeEdited = true |
|
|
|
private var actionCanBeEdited = true |
|
|
|
private var amountCanBeEdited = true |
|
|
|
private var amountCanBeEdited = true |
|
|
|
|
|
|
|
|
|
|
|
@ -129,7 +155,6 @@ class HandHistoryAdapter( |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
|
|
|
|
|
|
|
|
amountEditText.requestFocus() |
|
|
|
amountEditText.requestFocus() |
|
|
|
// requestFocusAndShowKeyboard(amountEditText) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) |
|
|
|
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -137,18 +162,6 @@ class HandHistoryAdapter( |
|
|
|
return@setOnTouchListener true |
|
|
|
return@setOnTouchListener true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// amountEditText.addTextChangedListener(this.listener) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun editTextSelected(editText: EditText, selected: Boolean, tag: Int) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editText.setBackgroundColor(color(selected)) |
|
|
|
|
|
|
|
val row = dataSource.rowRepresentableForPosition(currentPosition) |
|
|
|
|
|
|
|
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") |
|
|
|
|
|
|
|
val alreadySelected = dataSource.isSelected(currentPosition, row, tag) |
|
|
|
|
|
|
|
if (!alreadySelected && selected) { |
|
|
|
|
|
|
|
delegate?.onRowSelected(currentPosition, row, tag) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -164,11 +177,6 @@ class HandHistoryAdapter( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun color(isFocused: Boolean) : Int { |
|
|
|
|
|
|
|
val color = if (isFocused) R.color.kaki else R.color.kaki_medium |
|
|
|
|
|
|
|
return itemView.context.getColor(color) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("onbind @position = $position") |
|
|
|
Timber.d("onbind @position = $position") |
|
|
|
@ -245,11 +253,73 @@ class HandHistoryAdapter( |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display a hand street |
|
|
|
* Display a hand street |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
inner class RowHandStreet(itemView: View) : RecyclerView.ViewHolder(itemView), |
|
|
|
inner class RowHandStreet(itemView: View) : RowHandHolder(itemView), |
|
|
|
BindableHolder { |
|
|
|
BindableHolder { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flop |
|
|
|
|
|
|
|
itemView.findViewById<EditText>(R.id.flopEditText)?.let { flopEditText -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flopEditText.isFocusableInTouchMode = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flopEditText.setOnTouchListener { _, event -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (event.action == MotionEvent.ACTION_UP) { |
|
|
|
|
|
|
|
// Both are required, otherwise requestFocus() fails |
|
|
|
|
|
|
|
flopEditText.isFocusable = true |
|
|
|
|
|
|
|
flopEditText.isFocusableInTouchMode = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flopEditText.requestFocus() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editTextSelected(flopEditText, true, Street.FLOP.ordinal) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return@setOnTouchListener true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val streetCardView = row as StreetCardView |
|
|
|
|
|
|
|
val street = streetCardView.street |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemView.findViewById<EditText>(R.id.flopEditText)?.let { flopEditText -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flopEditText.isFocusable = (street == Street.FLOP) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flopEditText.isVisible = true |
|
|
|
|
|
|
|
val text = streetCardView.cards.take(3).formatted(itemView.context) |
|
|
|
|
|
|
|
flopEditText.setText(text) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemView.findViewById<EditText>(R.id.turnEditText)?.let { turnEditText -> |
|
|
|
|
|
|
|
// turnEditText.isVisible = streetCardView.street.ordinal >= Street.TURN.ordinal |
|
|
|
|
|
|
|
turnEditText.isFocusable = (street == Street.TURN) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (streetCardView.cards.size >= 4) { |
|
|
|
|
|
|
|
val text = streetCardView.cards[3].formatted(itemView.context) |
|
|
|
|
|
|
|
turnEditText.setText(text) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
turnEditText.text = null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemView.findViewById<EditText>(R.id.riverEditText)?.let { riverEditText -> |
|
|
|
|
|
|
|
// riverEditText.isVisible = streetCardView.street.ordinal >= Street.RIVER.ordinal |
|
|
|
|
|
|
|
riverEditText.isFocusable = (street == Street.RIVER) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (streetCardView.cards.size >= 5) { |
|
|
|
|
|
|
|
val text = streetCardView.cards[4].formatted(itemView.context) |
|
|
|
|
|
|
|
riverEditText.setText(text) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
riverEditText.text = null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |