Fixes focus issue on keyboard close

hh
Laurent 6 years ago
parent d9e52e865f
commit eaa5b87c13
  1. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 13
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -201,12 +201,11 @@ class HandHistoryAdapter(
fun editTextSelected(editText: EditText, selected: Boolean, tag: Int) { fun editTextSelected(editText: EditText, selected: Boolean, tag: Int) {
editText.setBackgroundColor(color(selected)) editText.setBackgroundColor(color(selected))
val row = dataSource.rowRepresentableForPosition(currentPosition) val row = dataSource.rowRepresentableForPosition(this.currentPosition)
?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") ?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition")
val alreadySelected = dataSource.isSelected(currentPosition, row, tag)
if (!alreadySelected && selected) { delegate?.onRowSelected(currentPosition, row, tag)
delegate?.onRowSelected(currentPosition, row, tag)
}
} }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -266,13 +265,13 @@ class HandHistoryAdapter(
editText.setText(string) editText.setText(string)
// Focus // Focus
val selected = adapter.dataSource.isSelected(position, row, tag) val focused = adapter.dataSource.isSelected(position, row, tag)
toggleFocus(editText, selected) toggleFocus(editText, focused)
editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag)
editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag)
// Background // Background
editText.setBackgroundColor(color(selected)) editText.setBackgroundColor(color(focused))
} }
@ -298,6 +297,11 @@ class HandHistoryAdapter(
itemView.smallBlindEditText.tag = 0 itemView.smallBlindEditText.tag = 0
itemView.bigBlindEditText.tag = 1 itemView.bigBlindEditText.tag = 1
itemView.anteEditText.tag = 2 itemView.anteEditText.tag = 2
setClickListener(itemView.smallBlindEditText)
setClickListener(itemView.bigBlindEditText)
setClickListener(itemView.anteEditText)
} }
// sb, bb, ante, bb ante // sb, bb, ante, bb ante

@ -210,7 +210,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
Timber.d("onRowSelected: $position, tag = $tag, row = $row") Timber.d("onRowSelected: $position, tag = $tag, row = $row")
if (!this.model.isEdited) { val alreadySelected = this.model.isSelected(position, row, tag)
if (alreadySelected || !this.model.isEdited) {
return return
} }
@ -362,11 +363,13 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.keyboard.setPositions(positions) this.keyboard.setPositions(positions)
} }
/***
* Closes the keyboard and removes any selection
*/
override fun closeKeyboard() { override fun closeKeyboard() {
this.model.selectionLiveData.value?.index?.let { val currentIndex = this.model.currentSelection.index
this.handHistoryAdapter.notifyItemChanged(it) this.model.selectionLiveData.value = null
this.model.selectionLiveData.value = null this.handHistoryAdapter.notifyItemChanged(currentIndex)
}
this.keyboard?.hide() this.keyboard?.hide()
} }

@ -176,9 +176,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
rows.add(HandRowType.PLAYER_NUMBER) rows.add(HandRowType.PLAYER_NUMBER)
rows.add(HandRowType.BLINDS) rows.add(HandRowType.BLINDS)
if (this.isNew) { // don't allow any straddle changes if not new val positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers)
if (this.isNew && positions.size > 2) { // don't allow any straddle changes if not new, or if it's a headsup
val positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers) rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.straddle))
positions.remove(Position.SB) positions.remove(Position.SB)
positions.remove(Position.BB) positions.remove(Position.BB)
rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) rows.add(StraddleRowRepresentable(positions, this.straddlePositions))
@ -576,6 +577,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
override fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean { override fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean {
return when (row) { return when (row) {
HandRowType.BLINDS -> this.isSelected(position, row, tag)
is ComputedAction -> { is ComputedAction -> {
val isSelected = this.isSelected(position, row, tag) val isSelected = this.isSelected(position, row, tag)
when (tag) { when (tag) {

Loading…
Cancel
Save