|
|
|
|
@ -3,9 +3,11 @@ package net.pokeranalytics.android.ui.modules.handhistory.views |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.util.AttributeSet |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.inputmethod.InputConnection |
|
|
|
|
import android.widget.FrameLayout |
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.handhistory.HHKeyboard |
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
|
|
|
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
|
|
|
|
@ -23,14 +25,38 @@ interface KeyboardListener { |
|
|
|
|
|
|
|
|
|
class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { |
|
|
|
|
|
|
|
|
|
var keyboardListener: KeyboardListener? = null |
|
|
|
|
|
|
|
|
|
val keyboards = HashMap<HHKeyboard, AbstractKeyboardView>() |
|
|
|
|
private val keyboards = HashMap<HHKeyboard, AbstractKeyboardView>() |
|
|
|
|
|
|
|
|
|
// private lateinit var constraintLayout: ConstraintLayout |
|
|
|
|
var keyboardListener: KeyboardListener? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
HHKeyboard.values().forEach { |
|
|
|
|
this.keyboards[it]?.keyboardListener = value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
this.setBackgroundColor(context.getColor(R.color.kaki_darker)) |
|
|
|
|
createKeyboards() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun createKeyboards() { |
|
|
|
|
|
|
|
|
|
HHKeyboard.values().forEach { |
|
|
|
|
val view = when (it) { |
|
|
|
|
HHKeyboard.ACTION -> { |
|
|
|
|
KeyboardActionView(context) |
|
|
|
|
} |
|
|
|
|
HHKeyboard.AMOUNT -> { |
|
|
|
|
KeyboardAmountView(context) |
|
|
|
|
} |
|
|
|
|
HHKeyboard.CARD -> { |
|
|
|
|
KeyboardCardView(context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.keyboards[it] = view |
|
|
|
|
addView(view) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun show() { |
|
|
|
|
@ -52,20 +78,24 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co |
|
|
|
|
|
|
|
|
|
show() |
|
|
|
|
|
|
|
|
|
var view = this.keyboards[type] |
|
|
|
|
// var view = this.keyboards[type] |
|
|
|
|
// |
|
|
|
|
// if (view == null) { |
|
|
|
|
// view = when(type) { |
|
|
|
|
// HHKeyboard.ACTION -> { KeyboardActionView(context) } |
|
|
|
|
// HHKeyboard.AMOUNT -> { KeyboardAmountView(context) } |
|
|
|
|
// HHKeyboard.CARD -> { KeyboardCardView(context) } |
|
|
|
|
// } |
|
|
|
|
// view.keyboardListener = this.keyboardListener |
|
|
|
|
// this.keyboards[type] = view |
|
|
|
|
// addView(view) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
if (view == null) { |
|
|
|
|
view = when(type) { |
|
|
|
|
HHKeyboard.ACTION -> { KeyboardActionView(context) } |
|
|
|
|
HHKeyboard.AMOUNT -> { KeyboardAmountView(context) } |
|
|
|
|
HHKeyboard.CARD -> { KeyboardCardView(context) } |
|
|
|
|
this.keyboards[type]?.let { |
|
|
|
|
show(it) |
|
|
|
|
} ?: run { |
|
|
|
|
throw PAIllegalStateException("missing keyboard") |
|
|
|
|
} |
|
|
|
|
view.keyboardListener = this.keyboardListener |
|
|
|
|
this.keyboards[type] = view |
|
|
|
|
addView(view) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
show(view) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun show(keyboardView: AbstractKeyboardView) { |
|
|
|
|
@ -74,6 +104,11 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun setInputConnection(inputConnection: InputConnection?) { |
|
|
|
|
val amountKeyboard = this.keyboards[HHKeyboard.AMOUNT] as KeyboardAmountView |
|
|
|
|
amountKeyboard.inputConnection = inputConnection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private fun loadView(layoutId: Int) { |
|
|
|
|
// val layoutInflater = LayoutInflater.from(context) |
|
|
|
|
// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout |
|
|
|
|
|