|
|
|
@ -1,5 +1,7 @@ |
|
|
|
package net.pokeranalytics.android.ui.adapter |
|
|
|
package net.pokeranalytics.android.ui.adapter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.res.ColorStateList |
|
|
|
import android.content.res.ColorStateList |
|
|
|
import android.text.Editable |
|
|
|
import android.text.Editable |
|
|
|
import android.text.InputType |
|
|
|
import android.text.InputType |
|
|
|
@ -8,6 +10,7 @@ import android.view.LayoutInflater |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.MotionEvent |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import android.view.inputmethod.InputMethodManager |
|
|
|
import android.widget.Button |
|
|
|
import android.widget.Button |
|
|
|
import android.widget.EditText |
|
|
|
import android.widget.EditText |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
@ -15,6 +18,7 @@ import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.model.handhistory.ComputedAction |
|
|
|
import net.pokeranalytics.android.model.handhistory.ComputedAction |
|
|
|
import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.extensions.hideKeyboard |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.holder.RowViewHolder |
|
|
|
import net.pokeranalytics.android.ui.view.holder.RowViewHolder |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier |
|
|
|
@ -114,14 +118,16 @@ class HandHistoryAdapter( |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
|
|
|
|
|
|
|
|
amountEditText.setOnTouchListener { v, event -> |
|
|
|
amountEditText.setOnTouchListener { v, event -> |
|
|
|
|
|
|
|
Timber.d("touch action = ${event.action}") |
|
|
|
if (this.amountCanBeEdited) { |
|
|
|
if (this.amountCanBeEdited) { |
|
|
|
|
|
|
|
|
|
|
|
// Both are required, otherwise requestFocus() fails |
|
|
|
if (event.action == MotionEvent.ACTION_UP) { |
|
|
|
amountEditText.isFocusable = true |
|
|
|
// Both are required, otherwise requestFocus() fails |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
amountEditText.isFocusable = true |
|
|
|
amountEditText.requestFocus() |
|
|
|
amountEditText.isFocusableInTouchMode = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestFocusAndShowKeyboard(amountEditText) |
|
|
|
|
|
|
|
|
|
|
|
if (event.action == MotionEvent.ACTION_DOWN) { |
|
|
|
|
|
|
|
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) |
|
|
|
editTextSelected(amountEditText, true, HHKeyboard.AMOUNT.ordinal) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -146,6 +152,7 @@ class HandHistoryAdapter( |
|
|
|
private fun buttonEdited(button: Button, selected: Boolean, tag: Int) { |
|
|
|
private fun buttonEdited(button: Button, selected: Boolean, tag: Int) { |
|
|
|
|
|
|
|
|
|
|
|
button.backgroundTintList = ColorStateList.valueOf(color(selected)) |
|
|
|
button.backgroundTintList = ColorStateList.valueOf(color(selected)) |
|
|
|
|
|
|
|
(itemView.context as Activity).hideKeyboard() |
|
|
|
|
|
|
|
|
|
|
|
if (selected) { |
|
|
|
if (selected) { |
|
|
|
val row = dataSource.rowRepresentableForPosition(currentPosition) |
|
|
|
val row = dataSource.rowRepresentableForPosition(currentPosition) |
|
|
|
@ -161,7 +168,7 @@ class HandHistoryAdapter( |
|
|
|
|
|
|
|
|
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("onbind @position = $position") |
|
|
|
// Timber.d("onbind @position = $position") |
|
|
|
|
|
|
|
|
|
|
|
this.currentPosition = position |
|
|
|
this.currentPosition = position |
|
|
|
|
|
|
|
|
|
|
|
@ -181,6 +188,9 @@ class HandHistoryAdapter( |
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
val selected = adapter.dataSource.isSelected(position, row, tag) |
|
|
|
// Timber.d("Action at $position is selected: $selected") |
|
|
|
// Timber.d("Action at $position is selected: $selected") |
|
|
|
actionButton.backgroundTintList = ColorStateList.valueOf(color(selected)) |
|
|
|
actionButton.backgroundTintList = ColorStateList.valueOf(color(selected)) |
|
|
|
|
|
|
|
if (selected) { |
|
|
|
|
|
|
|
(itemView.context as Activity).hideKeyboard() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
computedAction.action.type?.resId?.let { |
|
|
|
computedAction.action.type?.resId?.let { |
|
|
|
actionButton.setText(it) |
|
|
|
actionButton.setText(it) |
|
|
|
@ -205,17 +215,26 @@ class HandHistoryAdapter( |
|
|
|
|
|
|
|
|
|
|
|
amountEditText.setText(computedAction.action.displayedFormattedAmount) |
|
|
|
amountEditText.setText(computedAction.action.displayedFormattedAmount) |
|
|
|
|
|
|
|
|
|
|
|
val tookFocus = if (selected) { |
|
|
|
if (selected) { |
|
|
|
amountEditText.requestFocus() |
|
|
|
requestFocusAndShowKeyboard(amountEditText) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
amountEditText.clearFocus() |
|
|
|
amountEditText.clearFocus() |
|
|
|
false |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Timber.d("tookFocus: $tookFocus") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun requestFocusAndShowKeyboard(editText: EditText) { |
|
|
|
|
|
|
|
editText.requestFocus() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (editText.requestFocus()) { |
|
|
|
|
|
|
|
val imm = itemView.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager |
|
|
|
|
|
|
|
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0) |
|
|
|
|
|
|
|
// imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|