Various fixes and improvements

hh
Laurent 6 years ago
parent 808006e074
commit 024ce91040
  1. 26
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  5. 18
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  6. 23
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  7. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt
  8. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/CardSuitAdapter.kt
  9. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/CardsRow.kt
  10. 11
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardActionView.kt
  11. 18
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardAmountView.kt
  12. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt
  13. 9
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  14. 26
      app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt

@ -113,7 +113,7 @@ class HHBuilder {
/*** /***
* Returns the list of available user actions at [index] * Returns the list of available user actions at [index]
*/ */
private fun availableActions(index: Int) : Set<Action.Type> { fun availableActions(index: Int) : Set<Action.Type> {
val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index) val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index)
val lastUserAction: ComputedAction? = getLastUserAction(index) val lastUserAction: ComputedAction? = getLastUserAction(index)
@ -323,12 +323,18 @@ class HHBuilder {
/*** /***
* Returns the list of position still in play before the given [index] * Returns the list of position still in play before the given [index]
*/ */
private fun activePositions(index: Int): MutableList<Position> { private fun activePositions(index: Int, showDown: Boolean = false): MutableList<Position> {
val oustedPositions = this.sortedActions.take(index + 1) val oustedPositions = this.sortedActions.take(index + 1)
.filter { it.action.type?.isPullOut ?: false } .filter {
if (showDown) {
it.action.type == Action.Type.FOLD
} else {
it.action.type?.isPullOut ?: false
}
}
.map { it.position } .map { it.position }
val allPositions = this.positions val allPositions = this.positions.clone() as LinkedHashSet<Position>
allPositions.removeAll(oustedPositions) allPositions.removeAll(oustedPositions)
return allPositions.toMutableList() return allPositions.toMutableList()
} }
@ -360,7 +366,8 @@ class HHBuilder {
addStreetHeader(this.rowRepresentables, street, totalPotSize) addStreetHeader(this.rowRepresentables, street, totalPotSize)
val lastActionIndex = lastComputedAction.action.index val lastActionIndex = lastComputedAction.action.index
activePositions(lastActionIndex).sortedBy { it.ordinal }.forEach { val isShowDown = street == Street.SUMMARY
activePositions(lastActionIndex, isShowDown).sortedBy { it.ordinal }.forEach {
when (street) { when (street) {
Street.SUMMARY -> { Street.SUMMARY -> {
@ -398,6 +405,7 @@ class HHBuilder {
} }
val sizeBefore = this.sortedActions.size val sizeBefore = this.sortedActions.size
this.sortedActions = this.sortedActions.take(index + defaultRowsCount).toMutableList() this.sortedActions = this.sortedActions.take(index + defaultRowsCount).toMutableList()
this.createRowRepresentation()
val sizeAfter = this.sortedActions.size val sizeAfter = this.sortedActions.size
return sizeAfter != sizeBefore return sizeAfter != sizeBefore
@ -815,7 +823,13 @@ class HHBuilder {
rowRepresentables.add(headerView) rowRepresentables.add(headerView)
if (street.totalBoardCards > 0) { if (street.totalBoardCards > 0) {
val boardView = StreetCardsRow(street, this.handHistory.cardsForStreet(street))
// get board from last street
val lastBoardRow = this.rowRepresentables.lastOrNull { it is StreetCardsRow } as? StreetCardsRow
val cards = lastBoardRow?.cards ?: listOf<Card>()
// create new StreetCardsRow
val boardView = StreetCardsRow(street, cards)
rowRepresentables.add(boardView) rowRepresentables.add(boardView)
} }

@ -73,8 +73,9 @@ open class Action : RealmObject() {
companion object { companion object {
val defaultTypes: List<Type> val defaultTypes: List<Type> by lazy {
get() { return listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) } listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN)
}
} }
@ -129,7 +130,7 @@ open class Action : RealmObject() {
return this.type?.isSignificant ?: false return this.type?.isSignificant ?: false
} }
val displayedFormattedAmount: String? val formattedAmount: String?
get() { get() {
val amount = when (type) { val amount = when (type) {
Type.CALL, Type.CALL_ALLIN -> this.effectiveAmount Type.CALL, Type.CALL_ALLIN -> this.effectiveAmount

@ -82,6 +82,11 @@ open class Card : RealmObject() {
CLOVER(""); CLOVER("");
companion object { companion object {
val displaySuits: List<Suit> by lazy {
listOf(SPADES, HEART, DIAMOND, CLOVER, UNDEFINED)
}
fun format(suit: Suit?) : String { fun format(suit: Suit?) : String {
return suit?.value ?: "" return suit?.value ?: ""
} }

@ -109,7 +109,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab
val totalActions = this.actions.size val totalActions = this.actions.size
for (i in totalActions until this.numberOfPlayers + totalActions - 1) { for (i in totalActions until this.numberOfPlayers + totalActions) {
this.addAction(i, i % this.numberOfPlayers) this.addAction(i, i % this.numberOfPlayers)
} }

@ -1,6 +1,5 @@
package net.pokeranalytics.android.ui.modules.handhistory package net.pokeranalytics.android.ui.modules.handhistory
import android.app.Activity
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.text.InputType import android.text.InputType
import android.view.LayoutInflater import android.view.LayoutInflater
@ -21,7 +20,6 @@ import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter import net.pokeranalytics.android.ui.adapter.RecyclerAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.extensions.hideKeyboard
import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow
import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
@ -114,7 +112,7 @@ class HandHistoryAdapter(
// Action // Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton -> itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
actionButton.setOnClickListener { actionButton.setOnClickListener {
buttonEdited(actionButton, true, HHKeyboard.ACTION.ordinal) buttonClicked(actionButton, true, HHKeyboard.ACTION.ordinal)
} }
} }
@ -141,10 +139,10 @@ class HandHistoryAdapter(
} }
} }
private fun buttonEdited(button: Button, selected: Boolean, tag: Int) { private fun buttonClicked(button: Button, selected: Boolean, tag: Int) {
button.backgroundTintList = ColorStateList.valueOf(color(selected)) button.backgroundTintList = ColorStateList.valueOf(color(selected))
(itemView.context as Activity).hideKeyboard() // (itemView.context as Activity).hideKeyboard()
if (selected) { if (selected) {
val row = dataSource.rowRepresentableForPosition(currentPosition) val row = dataSource.rowRepresentableForPosition(currentPosition)
@ -199,16 +197,16 @@ class HandHistoryAdapter(
amountEditText.isFocusable = selected && computedAction.amountCanBeEdited amountEditText.isFocusable = selected && computedAction.amountCanBeEdited
amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited
Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
amountEditText.setBackgroundColor(color(selected)) amountEditText.setBackgroundColor(color(selected))
amountEditText.setText(computedAction.action.displayedFormattedAmount) amountEditText.setText(computedAction.action.formattedAmount)
if (selected) { if (selected) {
amountEditText.requestFocus() amountEditText.requestFocus()
} else { } else {
amountEditText.clearFocus() amountEditText.clearFocus()
} }
Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
} }
@ -262,7 +260,7 @@ class HandHistoryAdapter(
flopEditText.setText(text) flopEditText.setText(text)
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal) val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) flopEditText.clearFocus() if (selected) flopEditText.requestFocus() else flopEditText.clearFocus()
} }
@ -278,7 +276,7 @@ class HandHistoryAdapter(
} }
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal) val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) turnEditText.clearFocus() if (selected) turnEditText.requestFocus() else turnEditText.clearFocus()
} }
itemView.findViewById<EditText>(R.id.riverEditText)?.let { riverEditText -> itemView.findViewById<EditText>(R.id.riverEditText)?.let { riverEditText ->
@ -293,7 +291,7 @@ class HandHistoryAdapter(
} }
val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal) val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
if (!selected) riverEditText.clearFocus() if (selected) riverEditText.requestFocus() else riverEditText.clearFocus()
} }
} }

@ -84,8 +84,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
this.model.setBuilder(builder) this.model.setBuilder(builder)
// this.rows = this.model.builderLiveData.value?.rowRepresentables() ?: listOf()
} }
private fun initUI() { private fun initUI() {
@ -117,7 +115,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
else -> {} else -> {}
} }
} ?: run { } ?: run {
this.keyboard.setEditText(null, null) this.keyboard.hide()
} }
} }
@ -141,7 +139,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction val holder = recyclerView.findViewHolderForAdapterPosition(position) as? HandHistoryAdapter.RowHandAction
holder?.let { holder?.let {
val amountEditText = it.itemView.findViewById<EditText>(R.id.amountEditText) val amountEditText = it.itemView.findViewById<EditText>(R.id.amountEditText)
this.keyboard.setEditText(amountEditText, computedAction?.action?.amount) this.keyboard.setAmountEditText(amountEditText, computedAction?.action?.amount)
} ?: run { } ?: run {
Timber.d("no holder, or not RowHandAction") Timber.d("no holder, or not RowHandAction")
} }
@ -166,8 +164,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
private fun findNextActionToEdit(index: Int? = null) { private fun findNextActionToEdit(index: Int? = null) {
val startIndex = index ?: this.model.currentSelection.index val startIndex = index ?: this.model.currentSelection.index
this.model.findIndexForEdition(startIndex)?.let { this.model.findIndexForEdition(startIndex)?.let { selection ->
this.keyboard.show(it) this.recyclerView.smoothScrollToPosition(selection.index)
if (selection.keyboard == HHKeyboard.ACTION) {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
}
this.keyboard.show(selection.keyboard)
} ?: run { } ?: run {
this.keyboard.hide() this.keyboard.hide()
} }
@ -191,7 +196,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val keyboard: HHKeyboard = when (row) { val keyboard: HHKeyboard = when (row) {
is ComputedAction -> { is ComputedAction -> {
when (tag) { when (tag) {
HHKeyboard.ACTION.ordinal -> HHKeyboard.ACTION HHKeyboard.ACTION.ordinal -> {
val availableActions = this.model.availableActions()
this.keyboard.setAvailableAction(availableActions)
HHKeyboard.ACTION
}
HHKeyboard.AMOUNT.ordinal -> { HHKeyboard.AMOUNT.ordinal -> {
Timber.d("amount = ${row.action.amount}, toString = ${row.action.amount?.noGroupingFormatted}") Timber.d("amount = ${row.action.amount}, toString = ${row.action.amount?.noGroupingFormatted}")
this.model.currentAmount = row.action.amount?.noGroupingFormatted this.model.currentAmount = row.action.amount?.noGroupingFormatted

@ -4,7 +4,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.HHBuilder import net.pokeranalytics.android.model.handhistory.HHBuilder
import net.pokeranalytics.android.model.handhistory.HHKeyboard
import net.pokeranalytics.android.model.handhistory.HHSelection import net.pokeranalytics.android.model.handhistory.HHSelection
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.Action
@ -17,7 +16,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
private var builderLiveData = MutableLiveData<HHBuilder>() private var builderLiveData = MutableLiveData<HHBuilder>()
val builder: HHBuilder private val builder: HHBuilder
get() { get() {
return this.builderLiveData.value ?: throw PAIllegalStateException("Builder not found") return this.builderLiveData.value ?: throw PAIllegalStateException("Builder not found")
} }
@ -82,10 +81,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
this.builder.deleteLastCardProperty(this.currentSelection) this.builder.deleteLastCardProperty(this.currentSelection)
} }
fun findIndexForEdition(index: Int): HHKeyboard? { fun findIndexForEdition(index: Int): HHSelection? {
val selection = this.builder.findIndexForEdition(index) val selection = this.builder.findIndexForEdition(index)
this.selectionLiveData.value = selection this.selectionLiveData.value = selection
return selection?.keyboard return selection
} }
fun amountChanged(amount: String?) { fun amountChanged(amount: String?) {
@ -100,6 +99,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource {
return this.builder.nextActionIndex(this.actionIndexForSelection, position) return this.builder.nextActionIndex(this.actionIndexForSelection, position)
} }
fun availableActions() : Set<Action.Type> {
return this.builder.availableActions(this.actionIndexForSelection)
}
// Row Representable Datasource // Row Representable Datasource
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {

@ -21,7 +21,7 @@ class CardSuitAdapter(var keyboardListener: KeyboardListener) :
override var dataSource: RowRepresentableDataSource = this override var dataSource: RowRepresentableDataSource = this
override var delegate: RowRepresentableDelegate? = this override var delegate: RowRepresentableDelegate? = this
private val suits = Card.Suit.values().toList() private val suits = Card.Suit.displaySuits
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_cell, parent, false) val layout = LayoutInflater.from(parent.context).inflate(R.layout.row_cell, parent, false)

@ -58,6 +58,10 @@ abstract class CardsRow(cards: List<Card>) : HandHistoryRow {
*/ */
private fun add(card: Card) { private fun add(card: Card) {
if (!canAddMoreCards()) {
return
}
this.cards.lastOrNull()?.let { this.cards.lastOrNull()?.let {
if (it.suit == null) { if (it.suit == null) {
it.suit = Card.Suit.UNDEFINED it.suit = Card.Suit.UNDEFINED
@ -73,6 +77,13 @@ abstract class CardsRow(cards: List<Card>) : HandHistoryRow {
this.cards.add(card) this.cards.add(card)
} }
protected open fun canAddMoreCards(): Boolean {
this.cardLimit()?.let { limit ->
return this.cards.size < limit
}
return true
}
open fun clear() { open fun clear() {
this.cards.clear() this.cards.clear()
} }
@ -115,7 +126,6 @@ class StreetCardsRow(var street: Street, cards: List<Card>) : CardsRow(cards) {
this.cards.removeAll { it.street == this.street } this.cards.removeAll { it.street == this.street }
} }
} }
class PlayerCardsRow(var position: Position, cards: List<Card> = listOf(), var maxCards: Int? = null) : CardsRow(cards) { class PlayerCardsRow(var position: Position, cards: List<Card> = listOf(), var maxCards: Int? = null) : CardsRow(cards) {

@ -24,6 +24,8 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
private var dataAdapter: RowRepresentableAdapter private var dataAdapter: RowRepresentableAdapter
private lateinit var positionAdapter: PositionAdapter private lateinit var positionAdapter: PositionAdapter
private var availableActions: Set<Action.Type> = setOf()
init { init {
LayoutInflater.from(context) LayoutInflater.from(context)
@ -80,6 +82,15 @@ class KeyboardActionView(context: Context) : AbstractKeyboardView(context),
this.keyboardListener?.actionSelected(row as Action.Type) this.keyboardListener?.actionSelected(row as Action.Type)
} }
override fun isEnabled(row: RowRepresentable, tag: Int): Boolean {
return this.availableActions.contains(row as Action.Type)
}
fun setAvailableActions(availableActions: Set<Action.Type>) {
this.availableActions = availableActions
this.dataAdapter.notifyDataSetChanged()
}
// override fun stringForRow(row: RowRepresentable): String { // override fun stringForRow(row: RowRepresentable): String {
// this.context?.let { // this.context?.let {
// return row.localizedTitle(it) // return row.localizedTitle(it)

@ -17,6 +17,7 @@ import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.extensions.noGroupingFormatted import net.pokeranalytics.android.util.extensions.noGroupingFormatted
import timber.log.Timber
import java.text.DecimalFormatSymbols import java.text.DecimalFormatSymbols
class NumericKey : RowRepresentable { class NumericKey : RowRepresentable {
@ -63,7 +64,7 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
private var dataAdapter: RowRepresentableAdapter private var dataAdapter: RowRepresentableAdapter
private var editText: EditText? = null private lateinit var editText: EditText
private var inputConnection: InputConnection? = null private var inputConnection: InputConnection? = null
@ -90,7 +91,7 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
} }
this.clearButton.setOnClickListener { this.clearButton.setOnClickListener {
this.editText?.text = null this.editText.text = null
this.keyboardListener?.clearAmount() this.keyboardListener?.clearAmount()
} }
@ -99,12 +100,12 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
} }
} }
fun setEditText(editText: EditText?, amount: Double?) { fun setEditText(editText: EditText, amount: Double?) {
this.editText = editText this.editText = editText
editText?.setText(amount?.noGroupingFormatted) editText.setText(amount?.noGroupingFormatted)
this.inputConnection = editText?.onCreateInputConnection(EditorInfo()) this.inputConnection = editText.onCreateInputConnection(EditorInfo())
} }
override fun adapterRows(): List<RowRepresentable>? { override fun adapterRows(): List<RowRepresentable>? {
@ -139,7 +140,12 @@ class KeyboardAmountView(context: Context) : AbstractKeyboardView(context),
else -> { it.commitText(key.value, 1) } else -> { it.commitText(key.value, 1) }
} }
this.keyboardListener?.amountChanged(this.editText?.text.toString()) Timber.d(">>> text = ${this.editText.text.toString()}")
// this.editText?.setText(this.editText?.text)
// this.editText?.forceLayout()
this.keyboardListener?.amountChanged(this.editText.text.toString())
} ?: run { } ?: run {
throw PAIllegalStateException("Requires an input connection to handle key selections") throw PAIllegalStateException("Requires an input connection to handle key selections")

@ -96,7 +96,7 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
} }
} }
fun setEditText(editText: EditText?, amount: Double?) { fun setAmountEditText(editText: EditText, amount: Double?) {
val amountKeyboard = this.keyboards[HHKeyboard.AMOUNT] as KeyboardAmountView val amountKeyboard = this.keyboards[HHKeyboard.AMOUNT] as KeyboardAmountView
amountKeyboard.setEditText(editText, amount) amountKeyboard.setEditText(editText, amount)
} }
@ -106,6 +106,11 @@ class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(co
actionKeyboard.setPositions(positions) actionKeyboard.setPositions(positions)
} }
fun setAvailableAction(availableActions: Set<Action.Type>) {
val actionKeyboard = this.keyboards[HHKeyboard.ACTION] as KeyboardActionView
actionKeyboard.setAvailableActions(availableActions)
}
// private fun loadView(layoutId: Int) { // private fun loadView(layoutId: Int) {
// val layoutInflater = LayoutInflater.from(context) // val layoutInflater = LayoutInflater.from(context)
// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout // constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout

@ -107,10 +107,11 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier {
return when (this) { return when (this) {
// Row View Holder // Row View Holder
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG, LOCATION_TITLE, HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG,
INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE, TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_GRID, LOCATION_TITLE, INFO, TITLE, TITLE_ARROW, TITLE_ICON_ARROW, TITLE_VALUE,
TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, CONTENT, TITLE_SUBTITLE, HEADER_SUBTITLE, TITLE_VALUE_ARROW, TITLE_VALUE_ACTION, TITLE_GRID,
DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout) TITLE_SWITCH, TITLE_CHECK, TITLE_VALUE_CHECK, CONTENT, TITLE_SUBTITLE,
HEADER_SUBTITLE, DATA, BOTTOM_SHEET_DATA, LOADER -> RowViewHolder(layout)
// Row Session // Row Session
ROW_SESSION -> RowSessionViewHolder(layout) ROW_SESSION -> RowSessionViewHolder(layout)

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view.holder package net.pokeranalytics.android.ui.view.holder
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
@ -85,9 +86,19 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
} }
} }
else -> { else -> { // Standard row
// Classic row // View background
itemView.findViewById<ViewGroup>(R.id.container)?.let {
val enabled = adapter.dataSource.isEnabled(row, 0)
val color = if (enabled) {
R.color.kaki_light
} else {
R.color.green_darkest
}
it.setBackgroundColor(itemView.context.getColor(color))
it.isEnabled = enabled
}
// Title // Title
itemView.findViewById<AppCompatTextView?>(R.id.title)?.let { itemView.findViewById<AppCompatTextView?>(R.id.title)?.let {
@ -96,6 +107,13 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
} else { } else {
it.text = row.getDisplayName(itemView.context) it.text = row.getDisplayName(itemView.context)
} }
val color = if (adapter.dataSource.isEnabled(row, 0)) {
R.color.white
} else {
R.color.kaki_light
}
it.setTextColor(itemView.context.getColor(color))
} }
// Value // Value
@ -143,7 +161,9 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl
it.isChecked = !it.isChecked it.isChecked = !it.isChecked
} }
} ?: run { } ?: run {
adapter.delegate?.onRowSelected(position, row) if (adapter.dataSource.isEnabled(row, 0)) {
adapter.delegate?.onRowSelected(position, row)
}
} }
} }

Loading…
Cancel
Save