HH progress

hh
Laurent 6 years ago
parent 506c4bd931
commit 5799a17fa9
  1. 24
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  3. 10
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  4. 8
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  5. 77
      app/src/main/java/net/pokeranalytics/android/ui/adapter/HandHistoryAdapter.kt
  6. 20
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HandHistoryFragment.kt
  7. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/handhistory/KeyboardContainer.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/HandHistoryViewModel.kt
  9. 19
      app/src/main/res/layout/row_hand_action.xml

@ -62,6 +62,28 @@ class ComputedAction(var action: Action,
* SB / BB cannot have their action type edited
*/
val actionTypeCanBeEdited: Boolean
get() { return action.index > 1 }
get() {
val actionCanBeEdited = when (this.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB -> false
else -> true
}
Timber.d("Can be edited = $actionCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}")
return actionCanBeEdited
}
/***
* Returns whether the amount can be edited
*/
val amountCanBeEdited: Boolean
get() {
val amountCanBeEdited = when (this.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB,
Action.Type.BET, Action.Type.RAISE -> true
Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN -> (this.playerRemainingStack == null)
else -> false
}
// Timber.d("Can be edited = $amountCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}")
return amountCanBeEdited
}
}

@ -152,7 +152,10 @@ class HHBuilder {
Timber.d(">>> Sets $actionType at index: $index")
val computedAction = this.actionForIndex(index)
computedAction.action.type = actionType
if (computedAction.action.type != actionType) {
computedAction.action.type = actionType
computedAction.action.amount = null
}
dropNextActionsIfNecessary(index)
@ -328,15 +331,21 @@ class HHBuilder {
/***
* Finds the index of the first incomplete action, if existing
* If the same selection is the same than current, pass to the next row
*/
fun findIndexForEdition(startIndex: Int): HHSelection? {
fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHSelection? {
this.currentRowRepresentables.forEachIndexed { index, rowRepresentable ->
if (index >= startIndex && rowRepresentable is HandHistoryRow) {
// Timber.d("Check keyboard for index = $index")
rowRepresentable.keyboardForCompletion()?.let { keyboard ->
return HHSelection(index, keyboard)
val foundKeyboard = rowRepresentable.keyboardForCompletion()
if (foundKeyboard != null && !(index == startIndex && keyboard == foundKeyboard)) {
return HHSelection(index, foundKeyboard)
}
// rowRepresentable.keyboardForCompletion()?.let { keyboard ->
// return HHSelection(index, keyboard)
// }
}
}
return null

@ -5,6 +5,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.formatted
open class Action : RealmObject() {
@ -85,4 +86,13 @@ open class Action : RealmObject() {
return this.type?.isSignificant ?: false
}
val displayedFormattedAmount: String?
get() {
val amount = when (type) {
Type.CALL, Type.CALL_ALLIN -> this.effectiveAmount
else -> this.amount
}
return amount?.formatted()
}
}

@ -107,10 +107,10 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
action.type = Action.Type.POST_SB
action.amount = this.smallBlind
}
1 -> {
action.type = Action.Type.POST_BB
action.amount = this.bigBlind
}
// 1 -> {
// action.type = Action.Type.POST_BB
// action.amount = this.bigBlind
// }
else -> {}
}
this.actions.add(action)

@ -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()
}
}

@ -105,26 +105,26 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
findNextActionToEdit(0)
}
private fun closeEdition() {
this.model.isEdited = false
}
private fun findNextActionToEdit() {
val index = this.model.currentSelection?.index ?: throw PAIllegalStateException("Request next with no selection")
this.findNextActionToEdit(index)
val selection = this.model.currentSelection
val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection")
this.findNextActionToEdit(index, selection.keyboard)
}
private fun findNextActionToEdit(startIndex: Int) {
this.model.findIndexForEdition(startIndex)?.let {
private fun findNextActionToEdit(startIndex: Int, keyboard: HHKeyboard? = null) {
this.model.findIndexForEdition(startIndex, keyboard)?.let {
this.keyboard.show(it)
this.highlightCell(startIndex)
this.refreshCells(startIndex)
} ?: run {
this.keyboard.hide()
}
}
private fun closeEdition() {
this.model.isEdited = false
}
private fun highlightCell(oldIndex: Int) {
private fun refreshCells(oldIndex: Int) {
this.handHistoryAdapter.notifyItemChanged(oldIndex)
this.model.currentSelection?.index?.let {

@ -2,6 +2,7 @@ package net.pokeranalytics.android.ui.view.handhistory
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
@ -51,6 +52,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
HHKeyboard.CARD -> { KeyboardCardView(context) }
}
view.keyboardListener = this.keyboardListener
this.keyboards[type] = view
addView(view)
}
@ -59,7 +61,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
private fun show(keyboardView: AbstractKeyboardView) {
this.keyboards.values.forEach { kbView ->
kbView.isVisible = (kbView == keyboardView)
kbView.visibility = if (kbView == keyboardView) View.VISIBLE else View.GONE
}
}

@ -75,10 +75,10 @@ class HandHistoryViewModel : ViewModel() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
fun findIndexForEdition(startIndex: Int) : HHKeyboard? {
fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null) : HHKeyboard? {
builder.value?.let { builder ->
this.currentSelection = builder.findIndexForEdition(startIndex)
this.currentSelection = builder.findIndexForEdition(startIndex, keyboard)
return currentSelection?.keyboard
} ?: throw PAIllegalStateException("Builder not defined")

@ -2,7 +2,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/playerButton"
@ -18,32 +20,25 @@
android:layout_height="44dp"
android:layout_marginStart="8dp"/>
<!-- <com.google.android.material.button.MaterialButton-->
<!-- android:id="@+id/actionButton"-->
<!-- style="@style/PokerAnalyticsTheme.HHButton"-->
<!-- android:layout_width="120dp"-->
<!-- android:layout_height="44dp"-->
<!-- android:layout_marginStart="8dp"/>-->
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/actionEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:imeOptions="actionDone"
android:gravity="center"
android:maxLines="1" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/amountEditText"
style="@style/PokerAnalyticsTheme.EditText"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:imeOptions="actionDone"
android:gravity="end"
android:maxLines="1" />
</LinearLayout>
Loading…
Cancel
Save