|
|
|
@ -2,15 +2,81 @@ package net.pokeranalytics.android.ui.view.handhistory |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
import kotlinx.android.synthetic.main.view_hand_keyboard_amount.view.* |
|
|
|
import kotlinx.android.synthetic.main.view_hand_keyboard_amount.view.* |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
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 { |
|
|
|
init { |
|
|
|
LayoutInflater.from(context) |
|
|
|
LayoutInflater.from(context) |
|
|
|
.inflate(R.layout.view_hand_keyboard_amount, this, true) |
|
|
|
.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.nextButton.setOnClickListener { |
|
|
|
this.keyboardListener?.amountValidated() |
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |