Custom numeric keyboard management - unfinished

hh
Laurent 6 years ago
parent e7782599e1
commit 4c91718967
  1. 10
      app/src/main/java/net/pokeranalytics/android/model/handhistory/ComputedAction.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/ui/adapter/HandHistoryAdapter.kt
  3. 64
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HandHistoryFragment.kt
  4. 31
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/HandHistoryViewModel.kt

@ -93,12 +93,12 @@ class ComputedAction(var action: Action,
*/
val actionTypeCanBeEdited: Boolean
get() {
val actionCanBeEdited = when (this.action.type) {
return when (this.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB -> false
else -> true
}
Timber.d("Can be edited = $actionCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}")
return actionCanBeEdited
// Timber.d("Can be edited = $actionCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}")
// return actionCanBeEdited
}
/***
@ -106,14 +106,14 @@ class ComputedAction(var action: Action,
*/
val amountCanBeEdited: Boolean
get() {
val amountCanBeEdited = when (this.action.type) {
return when (this.action.type) {
Action.Type.POST_SB, Action.Type.POST_BB,
Action.Type.BET, Action.Type.RAISE -> true
Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN -> (this.playerRemainingStack == null)
else -> false
}
// Timber.d("Can be edited = $amountCanBeEdited, action = ${this.action.type}, pure index = ${this.action.index}")
return amountCanBeEdited
// return amountCanBeEdited
}
}

@ -114,7 +114,7 @@ class HandHistoryAdapter(
amountEditText.isFocusableInTouchMode = true
amountEditText.setOnTouchListener { v, event ->
Timber.d("touch action = ${event.action}")
// Timber.d("touch action = ${event.action}")
if (this.amountCanBeEdited) {
if (event.action == MotionEvent.ACTION_UP) {
@ -164,7 +164,7 @@ class HandHistoryAdapter(
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
// Timber.d("onbind @position = $position")
Timber.d("onbind @position = $position")
this.currentPosition = position
@ -212,7 +212,8 @@ class HandHistoryAdapter(
amountEditText.setText(computedAction.action.displayedFormattedAmount)
if (selected) {
requestFocusAndShowKeyboard(amountEditText)
amountEditText.requestFocus()
// requestFocusAndShowKeyboard(amountEditText)
} else {
amountEditText.clearFocus()
}

@ -4,6 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
import android.widget.EditText
import androidx.lifecycle.ViewModelProviders
import kotlinx.android.synthetic.main.fragment_hand_history.*
import kotlinx.android.synthetic.main.fragment_settings.recyclerView
@ -34,6 +37,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
private var rows: List<RowRepresentable> = listOf()
private var inputConnection: InputConnection? = null
companion object {
fun newInstance(id: String? = null): HandHistoryFragment {
@ -64,6 +69,13 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
this.edit()
this.model.currentSelection.value?.index?.let {
Timber.d(">>>> attempt to retrieveEditTextInputConnection")
this.retrieveEditTextInputConnection(it)
}
}
private fun initData() {
@ -77,6 +89,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
this.model.setBuilder(builder)
this.rows = this.model.builder.value?.rowRepresentables() ?: listOf()
}
private fun initUI() {
@ -87,7 +101,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
// SmoothScrollLinearLayoutManager(requireContext())
// val viewManager = LinearLayoutManager(requireContext())
handHistoryAdapter = HandHistoryAdapter(this, this)
this.handHistoryAdapter = HandHistoryAdapter(this, this)
recyclerView.apply {
setHasFixedSize(true)
@ -95,11 +109,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
adapter = handHistoryAdapter
}
this.rows = this.model.builder.value?.rowRepresentables() ?: listOf()
this.model.currentSelection.observeForever { selection ->
Timber.d("Current selection is ${selection.index} / ${selection.keyboard}")
retrieveEditTextInputConnection(selection.index)
}
this.keyboard.keyboardListener = this
this.edit()
}
private fun retrieveEditTextInputConnection(position: Int) {
val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction
holder?.let {
this.inputConnection = it.itemView.findViewById<EditText>(R.id.amountEditText)
.onCreateInputConnection(EditorInfo())
} ?: run {
Timber.d("no holder, or not RowHandAction")
}
}
private fun edit() {
@ -112,7 +140,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
private fun findNextActionToEdit() {
val selection = this.model.currentSelection
val selection = this.model.currentSelection.value
val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection")
this.findNextActionToEdit(index, selection.keyboard)
}
@ -152,12 +180,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
// if (tag == HHKeyboard.ACTION.ordinal) {
this.model.currentSelection?.index?.let { oldIndex ->
this.model.currentSelection.value?.index?.let { oldIndex ->
refreshCells(oldIndex)
}
// }
this.model.currentSelection = HHSelection(position, HHKeyboard.values()[tag])
this.model.currentSelection.value = HHSelection(position, HHKeyboard.values()[tag])
// scrolls to selected position
// this.recyclerView.scrollToPosition(position)
@ -182,7 +210,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
override fun onRowDeselected(position: Int, row: RowRepresentable) {
this.model.currentSelection = null
this.model.currentSelection.value = null
}
override fun onRowValueChanged(value: Any?, row: RowRepresentable) {
@ -191,8 +219,8 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
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)
val isSelectedIndex = (position == currentSelection.value?.index)
val isSelectedAction = (tag == currentSelection.value?.keyboard?.ordinal)
// Timber.d("position = $position, tag = $tag, current index = ${currentSelection?.index}, kb = ${currentSelection?.keyboard}")
return isSelectedIndex && isSelectedAction
}
@ -240,6 +268,22 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
override fun amountKeyTyped(key: NumericKey) {
this.model.amountKeyTyped(key)
this.inputConnection?.let {
when {
key.isBackSpace -> { it.deleteSurroundingText(1, 0) }
key.isDecimalSeparator -> {
val text = it.getSelectedText(0)
if (text != null && !text.contains(key.value)) {
it.commitText(key.value, 1)
} else { false }
}
else -> { it.commitText(key.value, 1) }
}
}
}
// Table refresh
@ -250,7 +294,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
}
private fun refreshCurrentRow() {
this.model.currentSelection?.index?.let {
this.model.currentSelection.value?.index?.let {
Timber.d("refreshes row at index = $it")
this.handHistoryAdapter.notifyItemChanged(it)
}

@ -16,15 +16,17 @@ 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 currentSelection: MutableLiveData<HHSelection> = MutableLiveData()
// 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
@ -42,7 +44,7 @@ class HandHistoryViewModel : ViewModel() {
private val actionIndexForSelection: Int
get() {
this.currentSelection?.let { selection ->
this.currentSelection.value?.let { selection ->
return builder.value?.indexOfComputedAction(selection.index) ?: throw PAIllegalStateException("No builder")
} ?: throw PAIllegalStateException("No selection")
}
@ -68,7 +70,7 @@ class HandHistoryViewModel : ViewModel() {
fun cardValueSelected(value: Int) {
this.currentSelection?.let { selection ->
this.currentSelection.value?.let { selection ->
selection.index
// get the appropriate card list, board or player's hand and give the information
}
@ -81,13 +83,10 @@ class HandHistoryViewModel : ViewModel() {
}
fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null) : HHKeyboard? {
builder.value?.let { builder ->
this.currentSelection = builder.findIndexForEdition(startIndex, keyboard)
return currentSelection?.keyboard
this.currentSelection.value = builder.findIndexForEdition(startIndex, keyboard)
return currentSelection.value?.keyboard
} ?: throw PAIllegalStateException("Builder not defined")
}
fun amountKeyTyped(key: NumericKey) {

Loading…
Cancel
Save