|
|
|
|
@ -120,22 +120,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
this.keyboard.show(keyboard) |
|
|
|
|
|
|
|
|
|
// when (row) { |
|
|
|
|
// is ComputedAction -> { |
|
|
|
|
// when (it.tag) { |
|
|
|
|
// 0 -> { |
|
|
|
|
// val positions = this.model.positionsToAct() |
|
|
|
|
// this.keyboard.setPositions(positions) |
|
|
|
|
// } |
|
|
|
|
// 1 -> { |
|
|
|
|
// retrieveEditTextInputConnection(selection.index) |
|
|
|
|
// } |
|
|
|
|
// else -> {} |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// else -> {} |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
this.keyboard.hide() |
|
|
|
|
} |
|
|
|
|
@ -230,7 +214,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.model.selectionLiveData.value?.index?.let { oldIndex -> |
|
|
|
|
refreshCells(oldIndex) |
|
|
|
|
refreshRowAtIndexAndCurrent(oldIndex) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.scrollToPosition(position) |
|
|
|
|
@ -245,23 +229,42 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { |
|
|
|
|
when (row) { |
|
|
|
|
HandRowType.COMMENT -> { |
|
|
|
|
this.model.handHistory.comment = value as? String |
|
|
|
|
refreshCells(this.model.indexOfRowRepresentable(row)) |
|
|
|
|
} |
|
|
|
|
HandRowType.PLAYER_NUMBER -> { |
|
|
|
|
this.model.setNumberOfPlayers(value as Int) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
is ComputedAction -> { |
|
|
|
|
this.model.currentAmount = value as String |
|
|
|
|
} |
|
|
|
|
is StraddleRowRepresentable -> { |
|
|
|
|
this.model.changeStraddleSelection(value as LinkedHashSet<Position>) |
|
|
|
|
|
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
|
|
|
|
|
when (row) { |
|
|
|
|
HandRowType.COMMENT -> { |
|
|
|
|
this.model.handHistory.comment = value as? String |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) |
|
|
|
|
} |
|
|
|
|
HandRowType.PLAYER_NUMBER -> { |
|
|
|
|
this.model.setNumberOfPlayers(value as Int) |
|
|
|
|
this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
is ComputedAction -> { |
|
|
|
|
this.model.currentAmount = value as String |
|
|
|
|
} |
|
|
|
|
is StraddleRowRepresentable -> { |
|
|
|
|
this.model.changeStraddleSelection(value as LinkedHashSet<Position>) |
|
|
|
|
} |
|
|
|
|
is PlayerSetupRowRepresentable -> { |
|
|
|
|
when (value) { |
|
|
|
|
is Int -> { |
|
|
|
|
row.playerSetup?.position = value |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the index of the row representable from the rows list |
|
|
|
|
*/ |
|
|
|
|
private fun indexOfRowRepresentable(row: RowRepresentable): Int { |
|
|
|
|
return this.model.indexOfRowRepresentable(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Keyboard Listener |
|
|
|
|
@ -273,19 +276,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun cardValueSelected(value: Card.Value) { |
|
|
|
|
this.model.cardValueSelected(value) |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.cardValueSelected(value) |
|
|
|
|
} |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.findNextActionToEdit() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun cardSuitSelected(suit: Card.Suit) { |
|
|
|
|
this.model.cardSuitSelected(suit) |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.cardSuitSelected(suit) |
|
|
|
|
} |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
this.findNextActionToEdit() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun clearCards() { |
|
|
|
|
this.model.clearCards() |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.clearCards() |
|
|
|
|
} |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -295,13 +304,17 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun cardBackSpaceSelected() { |
|
|
|
|
this.model.deleteLastCardProperty() |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.deleteLastCardProperty() |
|
|
|
|
} |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun amountValidated() { |
|
|
|
|
Timber.d(">>> amount validated") |
|
|
|
|
this.model.amountValidated() |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.amountValidated() |
|
|
|
|
} |
|
|
|
|
// this.handHistoryAdapter.notifyDataSetChanged() |
|
|
|
|
this.findNextActionToEdit() |
|
|
|
|
} |
|
|
|
|
@ -311,12 +324,20 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun amountCleared() { |
|
|
|
|
this.model.clearAmount() |
|
|
|
|
getRealm().executeTransaction { |
|
|
|
|
this.model.clearAmount() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Configures the action keyboard: |
|
|
|
|
* - Sets the available actions |
|
|
|
|
* - Sets the position shortcuts |
|
|
|
|
*/ |
|
|
|
|
private fun configureActionKeyboard() { |
|
|
|
|
val availableActions = this.model.availableActions() |
|
|
|
|
this.keyboard.setAvailableAction(availableActions) |
|
|
|
|
|
|
|
|
|
val positions = this.model.positionsToAct() |
|
|
|
|
this.keyboard.setPositions(positions) |
|
|
|
|
} |
|
|
|
|
@ -347,12 +368,18 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL |
|
|
|
|
this.recyclerView.smoothScrollToPosition(index - 1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun refreshCells(oldIndex: Int) { |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(oldIndex) |
|
|
|
|
refreshCurrentRow() |
|
|
|
|
/*** |
|
|
|
|
* Refreshes the cell at [index] and also selected row |
|
|
|
|
*/ |
|
|
|
|
private fun refreshRowAtIndexAndCurrent(index: Int) { |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(index) |
|
|
|
|
refreshSelectedRow() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun refreshCurrentRow() { |
|
|
|
|
/*** |
|
|
|
|
* Refreshes the selected row |
|
|
|
|
*/ |
|
|
|
|
private fun refreshSelectedRow() { |
|
|
|
|
this.model.selectionLiveData.value?.index?.let { |
|
|
|
|
Timber.d("refreshes row at index = $it") |
|
|
|
|
this.handHistoryAdapter.notifyItemChanged(it) |
|
|
|
|
|