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. 15
      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 * SB / BB cannot have their action type edited
*/ */
val actionTypeCanBeEdited: Boolean 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") Timber.d(">>> Sets $actionType at index: $index")
val computedAction = this.actionForIndex(index) val computedAction = this.actionForIndex(index)
if (computedAction.action.type != actionType) {
computedAction.action.type = actionType computedAction.action.type = actionType
computedAction.action.amount = null
}
dropNextActionsIfNecessary(index) dropNextActionsIfNecessary(index)
@ -328,15 +331,21 @@ class HHBuilder {
/*** /***
* Finds the index of the first incomplete action, if existing * 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 -> this.currentRowRepresentables.forEachIndexed { index, rowRepresentable ->
if (index >= startIndex && rowRepresentable is HandHistoryRow) { if (index >= startIndex && rowRepresentable is HandHistoryRow) {
// Timber.d("Check keyboard for index = $index") // Timber.d("Check keyboard for index = $index")
rowRepresentable.keyboardForCompletion()?.let { keyboard -> val foundKeyboard = rowRepresentable.keyboardForCompletion()
return HHSelection(index, keyboard) if (foundKeyboard != null && !(index == startIndex && keyboard == foundKeyboard)) {
return HHSelection(index, foundKeyboard)
} }
// rowRepresentable.keyboardForCompletion()?.let { keyboard ->
// return HHSelection(index, keyboard)
// }
} }
} }
return null return null

@ -5,6 +5,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.formatted
open class Action : RealmObject() { open class Action : RealmObject() {
@ -85,4 +86,13 @@ open class Action : RealmObject() {
return this.type?.isSignificant ?: false 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.type = Action.Type.POST_SB
action.amount = this.smallBlind action.amount = this.smallBlind
} }
1 -> { // 1 -> {
action.type = Action.Type.POST_BB // action.type = Action.Type.POST_BB
action.amount = this.bigBlind // action.amount = this.bigBlind
} // }
else -> {} else -> {}
} }
this.actions.add(action) this.actions.add(action)

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.adapter package net.pokeranalytics.android.ui.adapter
import android.text.Editable import android.text.Editable
import android.text.InputType
import android.text.TextWatcher import android.text.TextWatcher
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View 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.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 net.pokeranalytics.android.util.extensions.formatted
import timber.log.Timber import timber.log.Timber
enum class HandRowType(var layoutRes: Int) : ViewIdentifier { enum class HandRowType(var layoutRes: Int) : ViewIdentifier {
@ -97,20 +97,29 @@ class HandHistoryAdapter(
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
private var listener = TextListener() private var listener = TextListener()
private var currentPosition = 0
init { init {
// Action
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText -> itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText ->
actionEditText.inputType = InputType.TYPE_NULL
actionEditText.setTextIsSelectable(false)
actionEditText.setOnFocusChangeListener { v, hasFocus -> actionEditText.setOnFocusChangeListener { v, hasFocus ->
Timber.d("focus change = $hasFocus at position = $position") Timber.d("ACTION > focus change = $hasFocus at position = $currentPosition")
actionEditText.setBackgroundColor(color(hasFocus)) editTextSelected(actionEditText, hasFocus, HHKeyboard.ACTION.ordinal)
} }
} }
// Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
amountEditText.setOnFocusChangeListener { v, hasFocus -> amountEditText.setOnFocusChangeListener { v, hasFocus ->
Timber.d("focus change = $hasFocus at position = $position") Timber.d("AMOUNT > focus change = $hasFocus at position = $currentPosition")
amountEditText.setBackgroundColor(color(hasFocus)) editTextSelected(amountEditText, hasFocus, HHKeyboard.AMOUNT.ordinal)
} }
amountEditText.addTextChangedListener(this.listener) 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 { private fun color(isFocused: Boolean) : Int {
val color = if (isFocused) R.color.green_light else R.color.kaki_medium val color = if (isFocused) R.color.green_light else R.color.kaki_medium
return itemView.context.getColor(color) return itemView.context.getColor(color)
} }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
this.listener.position = position
this.currentPosition = position
val computedAction = row as ComputedAction val computedAction = row as ComputedAction
@ -137,7 +156,7 @@ class HandHistoryAdapter(
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText -> itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText ->
val tag = HHKeyboard.ACTION.ordinal val tag = HHKeyboard.ACTION.ordinal
actionEditText.isFocusable = computedAction.actionTypeCanBeEdited
val selected = adapter.dataSource.isSelected(position, row, tag) val selected = adapter.dataSource.isSelected(position, row, tag)
// Timber.d("Action at $position is selected: $selected") // Timber.d("Action at $position is selected: $selected")
actionEditText.setBackgroundColor(color(selected)) actionEditText.setBackgroundColor(color(selected))
@ -148,53 +167,23 @@ class HandHistoryAdapter(
actionEditText.text = null actionEditText.text = null
} }
if (selected) actionEditText.requestFocus() else actionEditText.clearFocus() 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))
// }
} }
// Amount // Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
amountEditText.isFocusable = computedAction.amountCanBeEdited
val tag = HHKeyboard.AMOUNT.ordinal val tag = HHKeyboard.AMOUNT.ordinal
val selected = adapter.dataSource.isSelected(position, row, tag) 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.setBackgroundColor(color(selected))
amountEditText.setText(computedAction.action.amount?.formatted()) amountEditText.setText(computedAction.action.displayedFormattedAmount)
if (selected) amountEditText.requestFocus() else amountEditText.clearFocus() if (selected && !amountEditText.hasFocus()) 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)
// }
} }
} }

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

@ -2,6 +2,7 @@ package net.pokeranalytics.android.ui.view.handhistory
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -51,6 +52,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
HHKeyboard.CARD -> { KeyboardCardView(context) } HHKeyboard.CARD -> { KeyboardCardView(context) }
} }
view.keyboardListener = this.keyboardListener view.keyboardListener = this.keyboardListener
this.keyboards[type] = view
addView(view) addView(view)
} }
@ -59,7 +61,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
private fun show(keyboardView: AbstractKeyboardView) { private fun show(keyboardView: AbstractKeyboardView) {
this.keyboards.values.forEach { kbView -> 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. 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 -> builder.value?.let { builder ->
this.currentSelection = builder.findIndexForEdition(startIndex) this.currentSelection = builder.findIndexForEdition(startIndex, keyboard)
return currentSelection?.keyboard return currentSelection?.keyboard
} ?: throw PAIllegalStateException("Builder not defined") } ?: throw PAIllegalStateException("Builder not defined")

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