First implementation of numeric keyboard

hh
Laurent 6 years ago
parent 763fb331f9
commit 529a7cc21e
  1. 3
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  2. 36
      app/src/main/java/net/pokeranalytics/android/ui/adapter/HandHistoryAdapter.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HandHistoryFragment.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/ui/view/handhistory/KeyboardActionView.kt
  5. 87
      app/src/main/java/net/pokeranalytics/android/ui/view/handhistory/KeyboardAmountView.kt
  6. 16
      app/src/main/java/net/pokeranalytics/android/ui/view/handhistory/KeyboardContainer.kt
  7. 13
      app/src/main/java/net/pokeranalytics/android/ui/viewmodel/HandHistoryViewModel.kt
  8. 2
      app/src/main/res/layout/fragment_hand_history.xml
  9. 11
      app/src/main/res/layout/view_hand_keyboard_amount.xml

@ -15,7 +15,8 @@ import kotlin.math.min
enum class HHKeyboard {
ACTION,
AMOUNT,
CARD
CARD;
}
class HHSelection(var index: Int, var keyboard: HHKeyboard)

@ -3,9 +3,7 @@ package net.pokeranalytics.android.ui.adapter
import android.app.Activity
import android.content.Context
import android.content.res.ColorStateList
import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
@ -73,28 +71,28 @@ class HandHistoryAdapter(
}
}
inner class TextListener : TextWatcher {
var position: Int = 0
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
val row = dataSource.rowRepresentableForPosition(position)
?: throw PAIllegalStateException("Row Representable not found at index: $position")
delegate?.onRowValueChanged(s.toString(), row)
}
}
// inner class TextListener : TextWatcher {
//
// var position: Int = 0
//
// override fun afterTextChanged(s: Editable?) {}
//
// override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
//
// override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
// val row = dataSource.rowRepresentableForPosition(position)
// ?: throw PAIllegalStateException("Row Representable not found at index: $position")
// delegate?.onRowValueChanged(s.toString(), row)
// }
//
// }
/**
* Display a hand action
*/
inner class RowHandAction(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
private var listener = TextListener()
// private var listener = TextListener()
private var currentPosition = 0
private var actionCanBeEdited = true
private var amountCanBeEdited = true
@ -134,7 +132,7 @@ class HandHistoryAdapter(
return@setOnTouchListener true
}
amountEditText.addTextChangedListener(this.listener)
// amountEditText.addTextChangedListener(this.listener)
}
}

@ -20,6 +20,7 @@ import net.pokeranalytics.android.ui.fragment.components.RealmFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager
import net.pokeranalytics.android.ui.view.handhistory.KeyboardListener
import net.pokeranalytics.android.ui.view.handhistory.NumericKey
import net.pokeranalytics.android.ui.view.handhistory.StreetCardHeader
import net.pokeranalytics.android.ui.viewmodel.HandHistoryViewModel
import net.pokeranalytics.android.util.extensions.findById
@ -237,6 +238,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
this.keyboard?.hide()
}
override fun amountKeyTyped(key: NumericKey) {
this.model.amountKeyTyped(key)
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
// Table refresh
private fun refreshCells(oldIndex: Int) {

@ -3,7 +3,7 @@ package net.pokeranalytics.android.ui.view.handhistory
import android.content.Context
import android.view.LayoutInflater
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.bottom_sheet_grid.view.*
import kotlinx.android.synthetic.main.view_hand_keyboard_action.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
@ -22,7 +22,7 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
init {
LayoutInflater.from(context)
.inflate(R.layout.bottom_sheet_grid, this, true)
.inflate(R.layout.view_hand_keyboard_action, this, true)
val viewManager = GridLayoutManager(context, 3)
this.dataAdapter = RowRepresentableAdapter(this, this)

@ -2,15 +2,81 @@ package net.pokeranalytics.android.ui.view.handhistory
import android.content.Context
import android.view.LayoutInflater
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.view_hand_keyboard_amount.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import java.text.DecimalFormatSymbols
class KeyboardAmountView(context: Context) : AbstractKeyboardView(context) {
class NumericKey : RowRepresentable {
private var type: Type
var value: String = ""
private set
constructor(type: Type) {
this.type = type
}
constructor(number: Int) : this(Type.NUMBER) {
this.value = "$number"
}
enum class Type {
NUMBER,
DECIMAL,
BACKSPACE
}
override fun getDisplayName(context: Context): String {
return when (this.type) {
Type.NUMBER -> this.value
Type.BACKSPACE -> ""
Type.DECIMAL -> DecimalFormatSymbols.getInstance().decimalSeparator.toString()
}
}
override val viewType: Int = RowViewType.TITLE_GRID.ordinal
val isBackSpace: Boolean
get() { return this.type == Type.BACKSPACE}
val isDecimalSeparator: Boolean
get() { return this.type == Type.DECIMAL }
}
class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
StaticRowRepresentableDataSource, RowRepresentableDelegate {
private var dataAdapter: RowRepresentableAdapter
init {
LayoutInflater.from(context)
.inflate(R.layout.view_hand_keyboard_amount, this, true)
val viewManager = GridLayoutManager(context, 3)
this.dataAdapter = RowRepresentableAdapter(this, this)
val spanCount = 3
val spacing = 2.px
val includeEdge = false
this.recyclerView.apply {
setHasFixedSize(true)
layoutManager = viewManager
adapter = dataAdapter
addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge))
}
this.nextButton.setOnClickListener {
this.keyboardListener?.amountValidated()
}
@ -24,4 +90,23 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context) {
}
}
override fun adapterRows(): List<RowRepresentable>? {
val keys = mutableListOf<NumericKey>()
(0 until 12).forEach { index ->
val key = when (index) {
in 0 until 9 -> NumericKey(index + 1)
9 -> NumericKey(NumericKey.Type.DECIMAL)
10 -> NumericKey(0)
11 -> NumericKey(NumericKey.Type.BACKSPACE)
else -> throw PAIllegalStateException("index problem in numeric keyboard")
}
keys.add(key)
}
return keys
}
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
this.keyboardListener?.amountKeyTyped(row as NumericKey)
}
}

@ -14,6 +14,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Card
interface KeyboardListener {
fun actionSelected(action: Action.Type)
fun amountKeyTyped(key: NumericKey)
fun cardValueSelected(value: Int)
fun cardSuitSelected(suit: Card.Suit)
fun amountValidated()
@ -50,18 +51,9 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
if (view == null) {
view = when(type) {
HHKeyboard.ACTION -> {
// activity.hideKeyboard()
KeyboardActionView(context)
}
HHKeyboard.AMOUNT -> {
// activity.showKeyboard()
KeyboardAmountView(context)
}
HHKeyboard.CARD -> {
// activity.hideKeyboard()
KeyboardCardView(context)
}
HHKeyboard.ACTION -> { KeyboardActionView(context) }
HHKeyboard.AMOUNT -> { KeyboardAmountView(context) }
HHKeyboard.CARD -> { KeyboardCardView(context) }
}
view.keyboardListener = this.keyboardListener
this.keyboards[type] = view

@ -9,6 +9,7 @@ import net.pokeranalytics.android.model.handhistory.HHSelection
import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.CardProperty
import net.pokeranalytics.android.ui.view.handhistory.NumericKey
import timber.log.Timber
class HandHistoryViewModel : ViewModel() {
@ -89,4 +90,16 @@ class HandHistoryViewModel : ViewModel() {
}
fun amountKeyTyped(key: NumericKey) {
var string = this.currentAmount
if (string == null && !key.isBackSpace) {
string = key.value
} else if (key.isBackSpace) {
string?.dropLast(1)
} else if (!(key.isDecimalSeparator && string!!.contains(key.value))) {
string += key.value
}
this.currentAmount = string
}
}

@ -37,7 +37,7 @@
<net.pokeranalytics.android.ui.view.handhistory.KeyboardContainer
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

@ -10,7 +10,7 @@
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintBottom_toTopOf="@id/recyclerView">
<com.google.android.material.button.MaterialButton
android:id="@+id/closeButton"
@ -52,4 +52,13 @@
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save