Fixes issues with actions chaining

hh
Laurent 6 years ago
parent bf9223a3f3
commit c0c28c628f
  1. 6
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  2. 9
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  3. 13
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FilterDetailsFragment.kt
  5. 19
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HandHistoryFragment.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ReportCreationFragment.kt
  7. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetMultiSelectionFragment.kt
  8. 7
      app/src/main/java/net/pokeranalytics/android/ui/fragment/data/TransactionTypeDataFragment.kt
  9. 78
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  10. 13
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/HandHistoryViewModel.kt

@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.handhistory
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import timber.log.Timber
interface HandHistoryRow : RowRepresentable {
@ -20,7 +21,7 @@ class ComputedAction(var action: Action,
/***
* Returns whether the action requires the user to enter an amount for the selected action
*/
val requireAmount: Boolean
val requiresAmount: Boolean
get() {
return when(this.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB,
@ -44,8 +45,9 @@ class ComputedAction(var action: Action,
override val viewType: Int = RowViewType.ROW_HAND_ACTION.ordinal
override fun keyboardForCompletion() : HHKeyboard? {
Timber.d("type = ${this.action.type} / amount = ${this.action.amount}")
return if (this.action.type != null) {
if (this.requireAmount) {
if (this.requiresAmount) {
HHKeyboard.AMOUNT
} else {
null

@ -149,7 +149,7 @@ class HHBuilder {
*/
fun selectAction(index: Int, actionType: Action.Type) : Boolean {
Timber.d("Sets $actionType at index: $index")
Timber.d(">>> Sets $actionType at index: $index")
val computedAction = this.actionForIndex(index)
computedAction.action.type = actionType
@ -173,7 +173,7 @@ class HHBuilder {
else -> {}
}
return computedAction.requireAmount
return computedAction.requiresAmount
}
/***
@ -191,10 +191,10 @@ class HHBuilder {
*/
fun setAmount(index: Int, amount: Double) {
Timber.d("Sets $amount at index: $index")
val computedAction = this.actionForIndex(index)
Timber.d(">>> Sets $amount at index: $index, for action ${computedAction.action.type}")
val revisedAmount = computedAction.playerRemainingStack?.let { min(it, amount) } ?: amount
val revisedAmount = computedAction.playerRemainingStack?.let { min(it, amount) } ?: amount
computedAction.action.amount = revisedAmount
// TODO si on change un montant de mise, on change les calls suivants
@ -326,6 +326,7 @@ class HHBuilder {
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)
}

@ -147,19 +147,12 @@ interface DisplayableDataSource {
}
/**
* Returns whether the row, or its component, shoudl be enabled
* Returns whether the row, or its component, should be enabled
*/
fun isEnabled(row: RowRepresentable): Boolean {
fun isEnabled(row: RowRepresentable, tag: Int): Boolean {
return true
}
/**
* Returns whether the row, or its component, shoudl be enabled
*/
fun color(position: Int, row: RowRepresentable, tag: Int): Int? {
return null
}
/**
* Returns whether the row, or its component, shoudl be enabled
*/
@ -188,7 +181,7 @@ interface SelectableDataSource {
/**
* A boolean to indicate if the row is selected or not
*/
fun isSelected(row: RowRepresentable): Boolean {
fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean {
return false
}
}

@ -103,7 +103,11 @@ open class FilterDetailsFragment : RealmFragment(), StaticRowRepresentableDataSo
} ?: NULL_TEXT
}
override fun isSelected(row: RowRepresentable): Boolean {
override fun isSelected(
position: Int,
row: RowRepresentable,
tag: Int
): Boolean {
return selectedRows.contains(row)
}

@ -107,6 +107,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
private fun findNextActionToEdit(startIndex: Int) {
this.model.findIndexForEdition(startIndex)?.let {
// this.handHistoryAdapter.notifyItemChanged(startIndex)
this.keyboard.show(it)
this.highlightCell()
} ?: run {
@ -119,7 +120,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
private fun highlightCell() {
this.handHistoryAdapter.notifyDataSetChanged()
this.model.currentSelection?.index?.let {
this.handHistoryAdapter.notifyItemChanged(it)
}
// this.handHistoryAdapter.notifyDataSetChanged()
}
// RowRepresentableDataSource
@ -173,11 +179,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
this.model.currentAmount = value as String
}
override fun color(position: Int, row: RowRepresentable, tag: Int): Int? {
val isSelectedIndex = (position == this.model.currentSelection?.index)
val isSelectedAction = (tag == this.model.currentSelection?.keyboard?.ordinal)
val color = if (isSelectedIndex && isSelectedAction) R.color.green_light else R.color.kaki_medium
return context?.getColor(color)
override fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean {
val currentSelection = this.model.currentSelection
val isSelectedIndex = (position == currentSelection?.index)
val isSelectedAction = (tag == currentSelection?.keyboard?.ordinal)
Timber.d("position = $position, tag = $tag, current index = ${currentSelection?.index}, kb = ${currentSelection?.keyboard}")
return isSelectedIndex && isSelectedAction
}
// Keyboard Listener

@ -182,7 +182,11 @@ class ReportCreationFragment : RealmFragment(), RowRepresentableDataSource, RowR
}
}
override fun isSelected(row: RowRepresentable): Boolean {
override fun isSelected(
position: Int,
row: RowRepresentable,
tag: Int
): Boolean {
return this.assistant.isSelected(row)
}

@ -35,7 +35,11 @@ open class BottomSheetMultiSelectionFragment : BottomSheetListFragment() {
this.viewModel.onRowSelected(row)
}
override fun isSelected(row: RowRepresentable): Boolean {
override fun isSelected(
position: Int,
row: RowRepresentable,
tag: Int
): Boolean {
return this.viewModel.isSelected(row)
// return selectedRows.contains(row)
}

@ -51,12 +51,15 @@ class TransactionTypeDataFragment : EditableDataFragment(), RowRepresentableData
return row.editingDescriptors(mapOf("defaultValue" to this.transactionType.name))
}
override fun isEnabled(row: RowRepresentable): Boolean {
override fun isEnabled(
row: RowRepresentable,
tag: Int
): Boolean {
return when (row) {
TransactionTypeRow.TRANSACTION_ADDITIVE -> {
return this.transactionType.isValidForDelete(getRealm())
}
else -> super.isEnabled(row)
else -> super.isEnabled(row, 0)
}
}

@ -281,7 +281,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Listener
val listener = View.OnClickListener {
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let {
if (adapter.dataSource.isEnabled(row)) {
if (adapter.dataSource.isEnabled(row, 0)) {
it.isChecked = !it.isChecked
}
} ?: run {
@ -296,7 +296,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Switch
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let {
it.isChecked = adapter.dataSource.boolForRow(row)
it.isEnabled = adapter.dataSource.isEnabled(row)
it.isEnabled = adapter.dataSource.isEnabled(row, 0)
it.setOnCheckedChangeListener { _, isChecked ->
adapter.delegate?.onRowValueChanged(isChecked, row)
}
@ -304,7 +304,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Selected row
itemView.findViewById<AppCompatImageView?>(R.id.check)?.let {
it.isSelected = adapter.dataSource.isSelected(row)
it.isSelected = adapter.dataSource.isSelected(position, row, 0)
}
@ -726,6 +726,11 @@ enum class RowViewType(private var layoutRes: Int) {
*/
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
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 bind(position: Int, row: RowRepresentable, adapter: RowRepresentableAdapter) {
val computedAction = row as ComputedAction
@ -735,57 +740,50 @@ enum class RowViewType(private var layoutRes: Int) {
}
// Action
itemView.findViewById<EditText>(R.id.actionEditText)?.let { button ->
itemView.findViewById<EditText>(R.id.actionEditText)?.let { actionEditText ->
val tag = HHKeyboard.ACTION.ordinal
button.isFocusable = computedAction.actionTypeCanBeEdited
adapter.dataSource.color(position, row, HHKeyboard.ACTION.ordinal)?.let { color ->
button.setBackgroundColor(color)
}
actionEditText.isFocusable = computedAction.actionTypeCanBeEdited
val selected = adapter.dataSource.isSelected(position, row, tag)
Timber.d("Action at $position is selected: $selected")
actionEditText.setBackgroundColor(color(selected))
computedAction.action.type?.resId?.let {
button.setText(it)
actionEditText.setText(it)
}
// button.setOnClickListener {
// }
button.setOnFocusChangeListener { v, hasFocus ->
Timber.d("Action Focus change: $hasFocus")
if (hasFocus) {
adapter.delegate?.onRowSelected(position, row, HHKeyboard.ACTION.ordinal)
} else {
adapter.delegate?.onRowDeselected(position, row)
}
adapter.dataSource.color(position, row, HHKeyboard.ACTION.ordinal)?.let { color ->
button.setBackgroundColor(color)
}
if (selected) actionEditText.requestFocus()
actionEditText.setOnClickListener {
adapter.delegate?.onRowSelected(position, row, tag)
actionEditText.setBackgroundColor(color(true))
}
actionEditText.setOnFocusChangeListener { v, hasFocus ->
actionEditText.setBackgroundColor(color(hasFocus))
}
}
// Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { editText ->
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
val tag = HHKeyboard.AMOUNT.ordinal
adapter.dataSource.color(position, row, HHKeyboard.AMOUNT.ordinal)?.let { color ->
editText.setBackgroundColor(color)
}
val selected = adapter.dataSource.isSelected(position, row, tag)
Timber.d("Amount at $position is selected: $selected")
amountEditText.setBackgroundColor(color(selected))
editText.setText(computedAction.action.amount?.formatted())
editText.setOnFocusChangeListener { v, hasFocus ->
Timber.d("Amount Focus change: $hasFocus")
if (hasFocus) {
adapter.delegate?.onRowSelected(position, row, HHKeyboard.AMOUNT.ordinal)
} else {
adapter.delegate?.onRowDeselected(position, row)
}
amountEditText.setText(computedAction.action.amount?.formatted())
adapter.dataSource.color(position, row, HHKeyboard.AMOUNT.ordinal)
?.let { color ->
editText.setBackgroundColor(color)
}
if (selected) amountEditText.requestFocus()
amountEditText.setOnClickListener {
adapter.delegate?.onRowSelected(position, row, tag)
amountEditText.setBackgroundColor(color(true))
}
amountEditText.setOnFocusChangeListener { v, hasFocus ->
amountEditText.setBackgroundColor(color(hasFocus))
}
editText.addTextChangedListener {
amountEditText.addTextChangedListener {
adapter.delegate?.onRowValueChanged(it.toString(), row)
}
}

@ -16,6 +16,14 @@ class HandHistoryViewModel : ViewModel() {
var isEdited = true
var currentSelection: HHSelection? = null
set(value) {
field = value
value?.let {
Timber.d("Current selection is ${it.index} / ${it.keyboard}")
} ?: run {
Timber.d("No selection")
}
}
var currentAmount: String? = null
@ -72,11 +80,6 @@ class HandHistoryViewModel : ViewModel() {
builder.value?.let { builder ->
this.currentSelection = builder.findIndexForEdition(startIndex)
this.currentSelection?.let {
Timber.d("Current selection is ${it.index} / ${it.keyboard}")
} ?: run {
Timber.d("No selection")
}
return currentSelection?.keyboard
} ?: throw PAIllegalStateException("Builder not defined")

Loading…
Cancel
Save