Improvements on the card/board selection

hh
Laurent 6 years ago
parent 4b2638a1dc
commit 71b633c259
  1. 8
      app/src/main/java/net/pokeranalytics/android/ui/extensions/UIExtensions.kt
  2. 76
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  3. 90
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  4. 73
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt

@ -207,11 +207,9 @@ fun Bitmap.toByteArray() : ByteArray {
return baos.toByteArray()
}
fun Activity.hideKeyboard() {
this.currentFocus?.let {
val imm = getSystemService(InputMethodManager::class.java)
imm.hideSoftInputFromWindow(it.windowToken, 0)
}
fun Context.hideKeyboard(v: View) {
val imm = v.context.getSystemService(InputMethodManager::class.java)
imm?.hideSoftInputFromWindow(v.windowToken, 0)
}
//fun Context.showKeyboard(view: View) {

@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
@ -26,6 +27,7 @@ import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.hideKeyboard
import net.pokeranalytics.android.ui.extensions.px
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType
import net.pokeranalytics.android.ui.modules.handhistory.model.*
@ -216,11 +218,47 @@ class HandHistoryAdapter(
this.configureEditTexts(index..index, position, row, adapter)
}
protected fun setClickListener(editText: EditText) {
editText.isFocusableInTouchMode = true
editText.setOnClickListener {
itemView.context.hideKeyboard(it)
editText.isFocusable = true
editText.isFocusableInTouchMode = true
editText.requestFocus()
editTextSelected(editText, true, editText.tag as Int)
}
// editText.setOnTouchListener { _, event ->
//
// if (event.action == MotionEvent.ACTION_UP) {
// // Both are required, otherwise requestFocus() fails
// editText.isFocusable = true
// editText.isFocusableInTouchMode = true
//
// editText.requestFocus()
//
// editTextSelected(editText, true, tag)
// }
// return@setOnTouchListener true
// }
}
protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
tagRange.forEach { tag ->
val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException("Edit Text not found for tag: $tag, class: $this")
// hides soft input view
editText.setTextIsSelectable(true)
// Enabled
editText.isEnabled = adapter.dataSource.isEnabled(row, tag)
@ -415,31 +453,33 @@ class HandHistoryAdapter(
itemView.turnEditText.tag = Street.TURN.ordinal
itemView.riverEditText.tag = Street.RIVER.ordinal
// Flop
itemView.findViewById<EditText>(R.id.flopEditText)?.let { flopEditText ->
flopEditText.isFocusableInTouchMode = true
// hides soft input view
// itemView.flopEditText.setTextIsSelectable(true)
// itemView.turnEditText.setTextIsSelectable(true)
// itemView.riverEditText.setTextIsSelectable(true)
flopEditText.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) {
// Both are required, otherwise requestFocus() fails
flopEditText.isFocusable = true
flopEditText.isFocusableInTouchMode = true
flopEditText.requestFocus()
editTextSelected(flopEditText, true, Street.FLOP.ordinal)
}
return@setOnTouchListener true
}
}
setClickListener(itemView.flopEditText)
setClickListener(itemView.turnEditText)
setClickListener(itemView.riverEditText)
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val streetCardsRow = row as StreetCardsRow
val street = streetCardsRow.street
configureEditTexts(Street.FLOP.ordinal..Street.RIVER.ordinal, position, row, adapter)
itemView.flopEditText.isEnabled = (street == Street.FLOP || street == Street.SUMMARY)
itemView.turnEditText.isEnabled = (street == Street.TURN || street == Street.SUMMARY)
itemView.riverEditText.isEnabled = (street == Street.RIVER || street == Street.SUMMARY)
itemView.flopEditText.isVisible = (street.ordinal >= Street.FLOP.ordinal)
itemView.turnEditText.isVisible = (street.ordinal >= Street.TURN.ordinal)
itemView.riverEditText.isVisible = (street.ordinal >= Street.RIVER.ordinal)
}
}

@ -4,10 +4,8 @@ import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmModel
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
interface CardHolder : RealmModel {
val cards: RealmList<Card>
@ -28,25 +26,10 @@ abstract class CardsRow : HandHistoryRow {
abstract val cardHolder: CardHolder?
// override fun tagsForCompletion(): List<Int> {
//
// }
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return this.canAddMoreCards()
}
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return when {
// this.cardCount < cardLimit() ?: MAXCARDS -> 0
// this.cardHolder?.cards?.lastOrNull()?.suit == null -> 0
// else -> null
// }
// }
override fun keyboardForTag(tag: Int): HHKeyboard? {
return HHKeyboard.CARD
}
@ -152,76 +135,3 @@ abstract class CardsRow : HandHistoryRow {
}
}
class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRow() {
override val viewType: Int = HandRowType.STREET.ordinal
override val cardHolder: CardHolder?
get() { return this.handHistory }
override fun createHolder() {
throw PAIllegalStateException("This cannot happen")
}
override fun tagsForCompletion(): List<Int> {
return listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal)
}
override fun isFieldNeedsInput(
tag: Int,
handHistory: HandHistory
): Boolean {
return cardsForTag(tag)?.isEmpty() ?: true
}
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return if (canAddMoreCards()) {
// this.street.ordinal
// } else {
// null
// }
// }
override fun cardLimit() : Int {
return this.street.totalBoardCards
}
override val realmInstance: Realm
get() { return this.handHistory.realm }
override fun lastCard(): Card? {
return when (this.street) {
Street.SUMMARY -> this.cardHolder?.cards?.lastOrNull()
else -> this.cardHolder?.cards?.lastOrNull { it.street == this.street }
}
}
override fun clear() {
when (this.street) {
Street.SUMMARY -> this.cardHolder?.cards?.clear()
else -> this.cardHolder?.cards?.removeAll { it.street == this.street }
}
}
fun cardsForTag(tag: Int): List<Card>? {
this.cardHolder?.cards?.let { cards ->
return when (tag) {
Street.PREFLOP.ordinal -> listOf()
Street.FLOP.ordinal -> cards.take(3)
Street.TURN.ordinal -> {
if (cards.size > 3) { listOf(cards[3]!!) } else { null }
}
Street.RIVER.ordinal -> {
if (cards.size > 4) { listOf(cards[4]!!) } else { null }
}
else -> throw PAIllegalStateException("unmanaged tag $tag")
}
}
return null
}
}

@ -0,0 +1,73 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRow() {
override val viewType: Int = HandRowType.STREET.ordinal
override val cardHolder: CardHolder?
get() { return this.handHistory }
override fun createHolder() {
throw PAIllegalStateException("This cannot happen")
}
override fun tagsForCompletion(): List<Int> {
return when (this.street) {
Street.PREFLOP -> listOf()
Street.FLOP -> listOf(Street.FLOP.ordinal)
Street.TURN -> listOf(Street.FLOP.ordinal, Street.TURN.ordinal)
Street.RIVER, Street.SUMMARY -> listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal)
}
}
override fun cardLimit() : Int {
return this.street.totalBoardCards
}
override val realmInstance: Realm
get() { return this.handHistory.realm }
override fun lastCard(): Card? {
return when (this.street) {
Street.SUMMARY -> this.cardHolder?.cards?.lastOrNull()
else -> this.handHistory.cards.lastOrNull { it.street == this.street }
}
}
override fun clear() {
when (this.street) {
Street.SUMMARY -> this.cardHolder?.cards?.clear()
else -> this.handHistory.cards.removeAll { it.street == this.street }
}
}
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
val street = Street.values()[tag]
return this.cardCount < street.totalBoardCards || this.handHistory.cards.elementAtOrNull(street.totalBoardCards - 1)?.suit == null
}
fun cardsForTag(tag: Int): List<Card>? {
this.handHistory.cards.let { cards ->
return when (tag) {
Street.PREFLOP.ordinal -> listOf()
Street.FLOP.ordinal -> cards.take(3)
Street.TURN.ordinal -> {
if (cards.size > 3) { listOf(cards[3]!!) } else { null }
}
Street.RIVER.ordinal -> {
if (cards.size > 4) { listOf(cards[4]!!) } else { null }
}
else -> throw PAIllegalStateException("unmanaged tag $tag")
}
}
}
}
Loading…
Cancel
Save