Various fixes and improvements

hh
Laurent 6 years ago
parent 808006e074
commit 024ce91040
  1. 26
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  5. 18
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  6. 23
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  7. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt
  8. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/CardSuitAdapter.kt
  9. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/CardsRow.kt
  10. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardActionView.kt
  11. 18
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardAmountView.kt
  12. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt
  13. 9
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  14. 24
      app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt

@ -113,7 +113,7 @@ class HHBuilder {
/***
* Returns the list of available user actions at [index]
*/
private fun availableActions(index: Int) : Set<Action.Type> {
fun availableActions(index: Int) : Set<Action.Type> {
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index)
val lastUserAction: ComputedAction? = getLastUserAction(index)
@ -323,12 +323,18 @@ class HHBuilder {
/***
* Returns the list of position still in play before the given [index]
*/
private fun activePositions(index: Int): MutableList<Position> {
private fun activePositions(index: Int, showDown: Boolean = false): MutableList<Position> {
val oustedPositions = this.sortedActions.take(index + 1)
.filter { it.action.type?.isPullOut ?: false }
.filter {
if (showDown) {
it.action.type == Action.Type.FOLD
} else {
it.action.type?.isPullOut ?: false
}
}
.map { it.position }
val allPositions = this.positions
val allPositions = this.positions.clone() as LinkedHashSet<Position>
allPositions.removeAll(oustedPositions)
return allPositions.toMutableList()
}
@ -360,7 +366,8 @@ class HHBuilder {
addStreetHeader(this.rowRepresentables, street, totalPotSize)
val lastActionIndex = lastComputedAction.action.index
activePositions(lastActionIndex).sortedBy { it.ordinal }.forEach {
val isShowDown = street == Street.SUMMARY
activePositions(lastActionIndex, isShowDown).sortedBy { it.ordinal }.forEach {
when (street) {
Street.SUMMARY -> {
@ -398,6 +405,7 @@ class HHBuilder {
}
val sizeBefore = this.sortedActions.size
this.sortedActions = this.sortedActions.take(index + defaultRowsCount).toMutableList()
this.createRowRepresentation()
val sizeAfter = this.sortedActions.size
return sizeAfter != sizeBefore
@ -815,7 +823,13 @@ class HHBuilder {
rowRepresentables.add(headerView)
if (street.totalBoardCards > 0) {
val boardView = StreetCardsRow(street, this.handHistory.cardsForStreet(street))
// get board from last street
val lastBoardRow = this.rowRepresentables.lastOrNull { it is StreetCardsRow } as? StreetCardsRow
val cards = lastBoardRow?.cards ?: listOf<Card>()
// create new StreetCardsRow
val boardView = StreetCardsRow(street, cards)
rowRepresentables.add(boardView)
}

@ -73,8 +73,9 @@ open class Action : RealmObject() {
companion object {
val defaultTypes: List<Type>
get() { return listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) }
val defaultTypes: List<Type> by lazy {
listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN)
}
}
@ -129,7 +130,7 @@ open class Action : RealmObject() {
return this.type?.isSignificant ?: false
}
val displayedFormattedAmount: String?
val formattedAmount: String?
get() {
val amount = when (type) {
Type.CALL, Type.CALL_ALLIN -> this.effectiveAmount

@ -82,6 +82,11 @@ open class Card : RealmObject() {
CLOVER("");
companion object {
val displaySuits: List<Suit> by lazy {
listOf(SPADES, HEART, DIAMOND, CLOVER, UNDEFINED)
}
fun format(suit: Suit?) : String {
return suit?.value ?: ""
}

@ -109,7 +109,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
val totalActions = this.actions.size
for (i in totalActions until this.numberOfPlayers + totalActions - 1) {
for (i in totalActions until this.numberOfPlayers + totalActions) {
this.addAction(i, i % this.numberOfPlayers)
}

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.modules.handhistory
import android.app.Activity
import android.content.res.ColorStateList
import android.text.InputType
import android.view.LayoutInflater
@ -21,7 +20,6 @@ import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.hideKeyboard
import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow
import net.pokeranalytics.android.ui.view.RowRepresentable
@ -114,7 +112,7 @@ class HandHistoryAdapter(
// Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
actionButton.setOnClickListener {
buttonEdited(actionButton, true, HHKeyboard.ACTION.ordinal)
buttonClicked(actionButton, true, HHKeyboard.ACTION.ordinal)
}
}
@ -141,10 +139,10 @@ class HandHistoryAdapter(
}
}
private fun buttonEdited(button: Button, selected: Boolean, tag: Int) {
private fun buttonClicked(button: Button, selected: Boolean, tag: Int) {
button.backgroundTintList = ColorStateList.valueOf(color(selected))
(itemView.context as Activity).hideKeyboard()
// (itemView.context as Activity).hideKeyboard()
if (selected) {
val row = dataSource.rowRepresentableForPosition(currentPosition)
@ -199,16 +197,16 @@ class HandHistoryAdapter(
amountEditText.isFocusable = selected && computedAction.amountCanBeEdited
amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited
Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
amountEditText.setBackgroundColor(color(selected))
amountEditText.setText(computedAction.action.displayedFormattedAmount)
amountEditText.setText(computedAction.action.formattedAmount)
if (selected) {
amountEditText.requestFocus()
} else {
amountEditText.clearFocus()
}
Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
}
@ -262,7 +260,7 @@ class HandHistoryAdapter(
flopEditText.setText(text)
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) flopEditText.clearFocus()
if (selected) flopEditText.requestFocus() else flopEditText.clearFocus()
}
@ -278,7 +276,7 @@ class HandHistoryAdapter(
}
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) turnEditText.clearFocus()
if (selected) turnEditText.requestFocus() else turnEditText.clearFocus()
}
itemView.findViewById<EditText>(R.id.riverEditText)?.let { riverEditText ->
@ -293,7 +291,7 @@ class HandHistoryAdapter(
}
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) riverEditText.clearFocus()
if (selected) riverEditText.requestFocus() else riverEditText.clearFocus()
}
}

@ -84,8 +84,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
}
this.model.setBuilder(builder)
// this.rows = this.model.builderLiveData.value?.rowRepresentables() ?: listOf()
}
private fun initUI() {
@ -117,7 +115,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
else -> {}
}
} ?: run {
this.keyboard.setEditText(null, null)
this.keyboard.hide()
}
}
@ -141,7 +139,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction
holder?.let {
val amountEditText = it.itemView.findViewById<EditText>(R.id.amountEditText)
this.keyboard.setEditText(amountEditText, computedAction?.action?.amount)
this.keyboard.setAmountEditText(amountEditText, computedAction?.action?.amount)
} ?: run {
Timber.d("no holder, or not RowHandAction")
}
@ -166,8 +164,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun findNextActionToEdit(index: Int? = null) {
val startIndex = index ?: this.model.currentSelection.index
this.model.findIndexForEdition(startIndex)?.let {
this.keyboard.show(it)
this.model.findIndexForEdition(startIndex)?.let { selection ->
this.recyclerView.smoothScrollToPosition(selection.index)
if (selection.keyboard == HHKeyboard.ACTION) {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
}
this.keyboard.show(selection.keyboard)
} ?: run {
this.keyboard.hide()
}
@ -191,7 +196,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val keyboard: HHKeyboard = when (row) {
is ComputedAction -> {
when (tag) {
HHKeyboard.ACTION.ordinal -> HHKeyboard.ACTION
HHKeyboard.ACTION.ordinal -> {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
HHKeyboard.ACTION
}
HHKeyboard.AMOUNT.ordinal -> {
Timber.d("amount = ${row.action.amount}, toString = ${row.action.amount?.noGroupingFormatted}")
this.model.currentAmount = row.action.amount?.noGroupingFormatted

@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.HHBuilder
import net.pokeranalytics.android.model.handhistory.HHKeyboard
import net.pokeranalytics.android.model.handhistory.HHSelection
import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.Action
@ -17,7 +16,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
private var builderLiveData = MutableLiveData<HHBuilder>()
val builder: HHBuilder
private val builder: HHBuilder
get() {
return this.builderLiveData.value ?: throw PAIllegalStateException("Builder not found")
}
@ -82,10 +81,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
this.builder.deleteLastCardProperty(this.currentSelection)
}
fun findIndexForEdition(index: Int): HHKeyboard? {
fun findIndexForEdition(index: Int): HHSelection? {
val selection = this.builder.findIndexForEdition(index)
this.selectionLiveData.value = selection
return selection?.keyboard
return selection
}
fun amountChanged(amount: String?) {
@ -100,6 +99,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
return this.builder.nextActionIndex(this.actionIndexForSelection, position)
}
fun availableActions() : Set<Action.Type> {
return this.builder.availableActions(this.actionIndexForSelection)
}
// Row Representable Datasource
override fun adapterRows(): List<RowRepresentable>? {

@ -21,7 +21,7 @@ class CardSuitAdapter(var keyboardListener: KeyboardListener) :
override var dataSource: RowRepresentableDataSource = this
override var delegate: RowRepresentableDelegate? = this
private val suits = Card.Suit.values().toList()
private val suits = Card.Suit.displaySuits
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_cell, parent, false)

@ -58,6 +58,10 @@ abstract class CardsRow(cards: List<Card>) : HandHistoryRow {
*/
private fun add(card: Card) {
if (!canAddMoreCards()) {
return
}
this.cards.lastOrNull()?.let {
if (it.suit == null) {
it.suit = Card.Suit.UNDEFINED
@ -73,6 +77,13 @@ abstract class CardsRow(cards: List<Card>) : HandHistoryRow {
this.cards.add(card)
}
protected open fun canAddMoreCards(): Boolean {
this.cardLimit()?.let { limit ->
return this.cards.size < limit
}
return true
}
open fun clear() {
this.cards.clear()
}
@ -115,7 +126,6 @@ class StreetCardsRow(var street: Street, cards: List<Card>) : CardsRow(cards) {
this.cards.removeAll { it.street == this.street }
}
}
class PlayerCardsRow(var position: Position, cards: List<Card> = listOf(), var maxCards: Int? = null) : CardsRow(cards) {

@ -24,6 +24,8 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
private var dataAdapter: RowRepresentableAdapter
private lateinit var positionAdapter: PositionAdapter
private var availableActions: Set<Action.Type> = setOf()
init {
LayoutInflater.from(context)
@ -80,6 +82,15 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
this.keyboardListener?.actionSelected(row as Action.Type)
}
override fun isEnabled(row: RowRepresentable, tag: Int): Boolean {
return this.availableActions.contains(row as Action.Type)
}
fun setAvailableActions(availableActions: Set<Action.Type>) {
this.availableActions = availableActions
this.dataAdapter.notifyDataSetChanged()
}
// override fun stringForRow(row: RowRepresentable): String {
// this.context?.let {
// return row.localizedTitle(it)

@ -17,6 +17,7 @@ import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.noGroupingFormatted
import timber.log.Timber
import java.text.DecimalFormatSymbols
class NumericKey : RowRepresentable {
@ -63,7 +64,7 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
private var dataAdapter: RowRepresentableAdapter
private var editText: EditText? = null
private lateinit var editText: EditText
private var inputConnection: InputConnection? = null
@ -90,7 +91,7 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
}
this.clearButton.setOnClickListener {
this.editText?.text = null
this.editText.text = null
this.keyboardListener?.clearAmount()
}
@ -99,12 +100,12 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
}
}
fun setEditText(editText: EditText?, amount: Double?) {
fun setEditText(editText: EditText, amount: Double?) {
this.editText = editText
editText?.setText(amount?.noGroupingFormatted)
editText.setText(amount?.noGroupingFormatted)
this.inputConnection = editText?.onCreateInputConnection(EditorInfo())
this.inputConnection = editText.onCreateInputConnection(EditorInfo())
}
override fun adapterRows(): List<RowRepresentable>? {
@ -139,7 +140,12 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
else -> { it.commitText(key.value, 1) }
}
this.keyboardListener?.amountChanged(this.editText?.text.toString())
Timber.d(">>> text = ${this.editText.text.toString()}")
// this.editText?.setText(this.editText?.text)
// this.editText?.forceLayout()
this.keyboardListener?.amountChanged(this.editText.text.toString())
} ?: run {
throw PAIllegalStateException("Requires an input connection to handle key selections")

@ -96,7 +96,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
}
}
fun setEditText(editText: EditText?, amount: Double?) {
fun setAmountEditText(editText: EditText, amount: Double?) {
val amountKeyboard = this.keyboards[HHKeyboard.AMOUNT] as KeyboardAmountView
amountKeyboard.setEditText(editText, amount)
}
@ -106,6 +106,11 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
actionKeyboard.setPositions(positions)
}
fun setAvailableAction(availableActions: Set<Action.Type>) {
val actionKeyboard = this.keyboards[HHKeyboard.ACTION] as KeyboardActionView
actionKeyboard.setAvailableActions(availableActions)
}
// private fun loadView(layoutId: Int) {
// val layoutInflater = LayoutInflater.from(context)
// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout

@ -107,10 +107,11 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier {
return when (this) {
// Row View Holder
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG, LOCATION_TITLE,
INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_GRID,
TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, CONTENT, TITLE_SUBTITLE, HEADER_SUBTITLE,
DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout)
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG,
LOCATION_TITLE, INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE,
TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_GRID,
TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, CONTENT, TITLE_SUBTITLE,
HEADER_SUBTITLE, DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout)
// Row Session
ROW_SESSION -> RowSessionViewHolder(layout)

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view.holder
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.SwitchCompat
@ -85,9 +86,19 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
}
}
else -> {
else -> { // Standard row
// Classic row
// View background
itemView.findViewById<ViewGroup>(R.id.container)?.let {
val enabled = adapter.dataSource.isEnabled(row, 0)
val color = if (enabled) {
R.color.kaki_light
} else {
R.color.green_darkest
}
it.setBackgroundColor(itemView.context.getColor(color))
it.isEnabled = enabled
}
// Title
itemView.findViewById<AppCompatTextView?>(R.id.title)?.let {
@ -96,6 +107,13 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
} else {
it.text = row.getDisplayName(itemView.context)
}
val color = if (adapter.dataSource.isEnabled(row, 0)) {
R.color.white
} else {
R.color.kaki_light
}
it.setTextColor(itemView.context.getColor(color))
}
// Value
@ -143,9 +161,11 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
it.isChecked = !it.isChecked
}
} ?: run {
if (adapter.dataSource.isEnabled(row, 0)) {
adapter.delegate?.onRowSelected(position, row)
}
}
}
itemView.findViewById<View?>(R.id.container)?.setOnClickListener(listener)
}

Loading…
Cancel
Save