From f4acb0f80544e50fa8f49e556f5ce9cf4a9c6d4b Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 11 Feb 2020 11:50:18 +0100 Subject: [PATCH] Cleanup keyboard display + fix missing positions shortcuts after flop --- .../modules/handhistory/HandHistoryAdapter.kt | 70 +++++++++---------- .../handhistory/HandHistoryFragment.kt | 62 +++++++++------- .../modules/handhistory/model/ActionList.kt | 5 +- 3 files changed, 73 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index cabf6ef1..817be388 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt @@ -132,41 +132,6 @@ class HandHistoryAdapter( } } - inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) { - - override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { - super.onBind(position, row, adapter) - - val straddleRow = row as StraddleRowRepresentable - - itemView.positionsChipGroup.removeAllViews() - straddleRow.positions.forEach { pos -> - - val chip = Chip(itemView.context) - chip.id = View.generateViewId() -// chip.tag = filter.id - chip.text = pos.shortValue - chip.chipStartPadding = 8f.px - chip.chipEndPadding = 8f.px - - chip.isChecked = straddleRow.selectedPositions.contains(pos) - chip.setOnClickListener { - if (chip.isChecked) { - val added = straddleRow.add(pos) - chip.isChecked = added - } else { - straddleRow.remove(pos) - } - adapter.delegate?.onRowValueChanged(straddleRow.selectedPositions, row) - } - itemView.positionsChipGroup.addView(chip) - - } - - } - - } - abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { var currentPosition = 0 @@ -239,6 +204,41 @@ class HandHistoryAdapter( } + inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) { + + override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + super.onBind(position, row, adapter) + + val straddleRow = row as StraddleRowRepresentable + + itemView.positionsChipGroup.removeAllViews() + straddleRow.positions.forEach { pos -> + + val chip = Chip(itemView.context) + chip.id = View.generateViewId() +// chip.tag = filter.id + chip.text = pos.shortValue + chip.chipStartPadding = 4f.px + chip.chipEndPadding = 4f.px + + chip.isChecked = straddleRow.selectedPositions.contains(pos) + chip.setOnClickListener { + if (chip.isChecked) { + val added = straddleRow.add(pos) + chip.isChecked = added + } else { + straddleRow.remove(pos) + } + adapter.delegate?.onRowValueChanged(straddleRow.selectedPositions, row) + } + itemView.positionsChipGroup.addView(chip) + + } + + } + + } + /** * Display a hand action */ diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index c6766067..6fd8c222 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -105,16 +105,17 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val row = this.model.rowRepresentableForPosition(it.index) as HandHistoryRow - when (row.keyboardForTag(it.tag)) { + val keyboard = row.keyboardForTag(it.tag) + when (keyboard) { HHKeyboard.ACTION -> { - val positions = this.model.positionsToAct() - this.keyboard.setPositions(positions) + configureActionKeyboard() } HHKeyboard.AMOUNT -> { retrieveEditTextInputConnection(selection) } else -> {} } + this.keyboard.show(keyboard) // when (row) { // is ComputedAction -> { @@ -145,7 +146,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL // At first, the selection is defined before the holder is bound, // so we retrieve the editText inputConnection once the recycler view has been rendered this.recyclerView.viewTreeObserver.addOnGlobalLayoutListener { - when (this.model.currentKeyboard) { HHKeyboard.AMOUNT -> { val selection = this.model.currentSelection @@ -153,12 +153,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } else -> {} } - } this.keyboard.keyboardListener = this this.keyboard.setCardCentralizer(this.model) - } private fun retrieveEditTextInputConnection(selection: HHSelection) { @@ -188,17 +186,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL val startIndex = index ?: this.model.currentSelection.index this.model.findSelectionForEdition(startIndex)?.let { selection -> - this.recyclerView.smoothScrollToPosition(selection.index) + this.scrollToPosition(selection.index) - this.model.currentKeyboard?.let { keyboard -> - when (keyboard) { - HHKeyboard.ACTION -> { - val availableActions = this.model.availableActions() - this.keyboard.setAvailableAction(availableActions) - } else -> {} - } - this.keyboard.show(keyboard) - } +// this.model.currentKeyboard?.let { keyboard -> +// when (keyboard) { +// HHKeyboard.ACTION -> { +// configureActionKeyboard() +// } else -> {} +// } +// this.keyboard.show(keyboard) +// } } ?: run { this.keyboard.hide() @@ -222,20 +219,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL refreshCells(oldIndex) } - // scrolls to selected position - this.recyclerView.smoothScrollToPosition(position) + this.scrollToPosition(position) this.model.selectionLiveData.value = HHSelection(position, tag) - val keyboard = (row as HandHistoryRow).keyboardForTag(tag) - if (keyboard == HHKeyboard.ACTION) { - val availableActions = this.model.availableActions() - this.keyboard.setAvailableAction(availableActions) - } +// val keyboard = (row as HandHistoryRow).keyboardForTag(tag) +// if (keyboard == HHKeyboard.ACTION) { +// configureActionKeyboard() +// } +// this.keyboard.show(keyboard) - Timber.d("row $position selected, show keyboard = $keyboard") - this.keyboard.show(keyboard) +// Timber.d("row $position selected, show keyboard = $keyboard") + + } + private fun configureActionKeyboard() { + val availableActions = this.model.availableActions() + this.keyboard.setAvailableAction(availableActions) + val positions = this.model.positionsToAct() + this.keyboard.setPositions(positions) } override fun onRowDeselected(position: Int, row: RowRepresentable) { @@ -321,7 +323,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } ?: throw PAIllegalStateException("Rowrepresentable not fouind at index $rowRepresentableIndex") } - // Table refresh + // Table + + /*** + * Scrolls to the [index] + * We subtract 1 to give space and the ability to see the previously entered data + */ + private fun scrollToPosition(index: Int) { + this.recyclerView.smoothScrollToPosition(index - 1) + } private fun refreshCells(oldIndex: Int) { this.handHistoryAdapter.notifyItemChanged(oldIndex) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index c83c6c12..b1d41a1c 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -514,9 +514,8 @@ class ActionList(var listener: ActionListListener) : ArrayList() * Returns all positions of the street, identified by the action at the given [index] */ fun positionsToActAfterIndex(index: Int): List { - val currentStreet = this[index].street - val streetActions = this.filter { it.street == currentStreet } - return streetActions.drop(index + 1).map { it.position } + val nextActions = this.drop(index + 1) + return nextActions.map { it.position } } /***