Laurent 5 years ago
commit 20d42eea19
  1. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/CustomFieldDataFragment.kt
  2. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/feed/FeedSessionRowRepresentableAdapter.kt
  3. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/feed/FeedTransactionRowRepresentableAdapter.kt
  4. 173
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorAdapter.kt

@ -210,6 +210,11 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
* Init UI
*/
private fun initUI() {
val addItem = binding.addItem
val sortChoices = binding.sortChoices
val sortDescending = binding.sortDescending
val recyclerView = binding.recyclerView
customField.updateRowRepresentation()
binding.bottomBar.translationY = 72f.px
binding.bottomBar.visibility = View.VISIBLE

@ -11,13 +11,14 @@ import io.realm.RealmQuery
import io.realm.RealmResults
import io.realm.Sort
import io.realm.kotlin.where
import kotlinx.android.synthetic.main.row_feed_session.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.Filter
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.SessionRowView
import net.pokeranalytics.android.util.extensions.getMonthAndYear
import timber.log.Timber
import java.util.*
@ -74,16 +75,17 @@ class FeedSessionRowRepresentableAdapter(
*/
inner class RowSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
BindableHolder {
private var sessionRow: SessionRowView = itemView.findViewById(R.id.sessionRow)
fun bind(position: Int, row: Session?, adapter: FeedSessionRowRepresentableAdapter) {
itemView.sessionRow.setData(row as Session)
this.sessionRow.setData(row as Session)
val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, row)
}
itemView.sessionRow.setOnClickListener(listener)
this.sessionRow.setOnClickListener(listener)
itemView.sessionRow.setOnLongClickListener {
this.sessionRow.setOnLongClickListener {
adapter.delegate?.onRowLongClick(itemView, row, adapterPosition)
return@setOnLongClickListener true
}

@ -6,12 +6,12 @@ import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.RecyclerView
import io.realm.RealmResults
import kotlinx.android.synthetic.main.row_transaction.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Transaction
import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.TransactionRowView
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.getMonthAndYear
import java.util.*
@ -42,14 +42,15 @@ class FeedTransactionRowRepresentableAdapter(
*/
inner class RowTransactionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
BindableHolder {
private var transactionRow: TransactionRowView = itemView.findViewById(R.id.transactionRow)
fun bind(position: Int, row: Transaction?, adapter: FeedTransactionRowRepresentableAdapter) {
itemView.transactionRow.setData(row as Transaction)
this.transactionRow.setData(row as Transaction)
val listener = View.OnClickListener {
adapter.delegate?.onRowSelected(position, row)
}
itemView.transactionRow.setOnClickListener(listener)
this.transactionRow.setOnClickListener(listener)
}
}

@ -3,24 +3,13 @@ package net.pokeranalytics.android.ui.modules.handhistory.editor
import android.content.res.ColorStateList
import android.text.InputType
import android.view.*
import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.*
import androidx.appcompat.widget.AppCompatButton
import androidx.core.view.isEmpty
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip
import kotlinx.android.synthetic.main.row_hand_action.view.*
import kotlinx.android.synthetic.main.row_hand_action_read.view.*
import kotlinx.android.synthetic.main.row_hand_cards.view.*
import kotlinx.android.synthetic.main.row_hand_player_summary.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.position_button
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.ps_hand_layout
import kotlinx.android.synthetic.main.row_hhsettings_player_setup_read.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
import kotlinx.android.synthetic.main.row_recycler.view.*
import com.google.android.material.internal.FlowLayout
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position
@ -104,7 +93,8 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable {
class EditorAdapter(
override var dataSource: RowRepresentableDataSource,
override var delegate: RowRepresentableDelegate? = null) :
override var delegate: RowRepresentableDelegate? = null
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(),
RecyclerAdapter {
@ -180,15 +170,27 @@ class EditorAdapter(
this.currentPosition = position
}
protected fun configureEditTexts(index: Int, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
protected fun configureEditTexts(
index: Int,
position: Int,
row: RowRepresentable,
adapter: RecyclerAdapter
) {
this.configureEditTexts(index..index, position, row, adapter)
}
private fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
private 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")
val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException(
"Edit Text not found for tag: $tag, class: $this"
)
// hides soft input view
editText.setTextIsSelectable(true)
@ -229,7 +231,9 @@ class EditorAdapter(
}
protected fun configureTextView(tag: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
val textView = itemView.findViewWithTag<TextView>(tag) ?: throw PAIllegalStateException("TextView not found for tag: $tag, class: $this")
val textView = itemView.findViewWithTag<TextView>(tag) ?: throw PAIllegalStateException(
"TextView not found for tag: $tag, class: $this"
)
textView.text = adapter.dataSource.charSequenceForRow(row, itemView.context, tag)
}
@ -287,7 +291,11 @@ class EditorAdapter(
return itemView.findViewWithTag(tag)
}
protected fun configurePlayerImage(playerImageView: PlayerImageView, position: Int, row: RowRepresentable) {
protected fun configurePlayerImage(
playerImageView: PlayerImageView,
position: Int,
row: RowRepresentable
) {
// Player
val listener = View.OnClickListener {
@ -359,6 +367,8 @@ class EditorAdapter(
}
inner class RowStraddleHolder(itemView: View) : RowHandHolder(itemView) {
private var container: ViewGroup = itemView.findViewById(R.id.container)
private var positionsChipGroup: FlowLayout = itemView.findViewById(R.id.positionsChipGroup)
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
@ -366,10 +376,14 @@ class EditorAdapter(
val straddleRow = row as StraddleRowRepresentable
adapter.dataSource.backgroundColor(position, row)?.let { color ->
itemView.findViewById<ViewGroup>(R.id.container)?.setBackgroundColor(itemView.context.getColor(color))
this.container.setBackgroundColor(
itemView.context.getColor(
color
)
)
}
itemView.positionsChipGroup.removeAllViews()
this.positionsChipGroup.removeAllViews()
straddleRow.positions.forEach { pos ->
val chip = Chip(itemView.context)
@ -388,20 +402,21 @@ class EditorAdapter(
}
adapter.delegate?.onRowValueChanged(straddleRow.selectedPositions, row)
}
itemView.positionsChipGroup.addView(chip)
this.positionsChipGroup.addView(chip)
}
}
}
inner class RowPositionHolder(itemView: View) : RowHandHolder(itemView) {
private var recycler: RecyclerView = itemView.findViewById(R.id.recycler)
private var positionAdapter: PositionAdapter = PositionAdapter()
private var positionViewManager: LinearLayoutManager =
LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false)
init {
itemView.recycler.apply {
this.recycler.apply {
setHasFixedSize(true)
layoutManager = positionViewManager
adapter = positionAdapter
@ -411,7 +426,11 @@ class EditorAdapter(
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
this.positionAdapter.positions = adapter.dataSource.contentForRow(row, itemView.context, Position::class)
this.positionAdapter.positions = adapter.dataSource.contentForRow(
row,
itemView.context,
Position::class
)
this.positionAdapter.setOnClickListener { pos ->
adapter.delegate?.onRowValueChanged(pos, row)
this.positionAdapter.notifyDataSetChanged()
@ -427,26 +446,33 @@ class EditorAdapter(
inner class RowActionReadHolder(itemView: View) : RowHandHolder(itemView) {
private var playerImage: PlayerImageView = itemView.findViewById(R.id.player_image_rhar)
private var stackText: TextView = itemView.findViewById(R.id.stackText)
private var playersText: TextView = itemView.findViewById(R.id.playersText)
private var actionText: TextView = itemView.findViewById(R.id.actionText)
private var actionContainer: View = itemView.findViewById(R.id.action_container)
private var amountText: TextView = itemView.findViewById(R.id.amountText)
init {
itemView.player_image_rhar.tag = ActionReadRow.Tag.PLAYER.ordinal
itemView.stackText.tag = ActionReadRow.Tag.STACK.ordinal
playerImage.tag = ActionReadRow.Tag.PLAYER.ordinal
stackText.tag = ActionReadRow.Tag.STACK.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
configurePlayerImage(itemView.player_image_rhar, position, row)
configurePlayerImage(this.playerImage, position, row)
val actionReadRow = row as ActionReadRow
itemView.playersText.text = actionReadRow.positions.joinToString(", ") { it.value }
this.playersText.text = actionReadRow.positions.joinToString(", ") { it.value }
actionReadRow.action?.let { type ->
itemView.actionText.text = type.localizedTitle(itemView.context)
this.actionText.text = type.localizedTitle(itemView.context)
val background = itemView.context.getDrawable(type.background)
itemView.action_container.background = background
this.actionContainer.background = background
}
itemView.amountText.text = actionReadRow.amount?.formatted
itemView.stackText.text = actionReadRow.stack?.formatted
this.amountText.text = actionReadRow.amount?.formatted
this.stackText.text = actionReadRow.stack?.formatted
}
}
@ -456,16 +482,22 @@ class EditorAdapter(
*/
inner class RowActionHolder(itemView: View) : RowHandHolder(itemView) {
private var playerImage: PlayerImageView = itemView.findViewById(R.id.player_image_rha)
private var actionButton: AppCompatButton = itemView.findViewById(R.id.actionButton)
private var amountEditText: EditText = itemView.findViewById(R.id.amountEditText)
private var positionButton: AppCompatButton = itemView.findViewById(R.id.positionButton)
init {
itemView.player_image_rha.tag = ComputedAction.Tag.PLAYER.ordinal
itemView.actionButton.tag = ComputedAction.Tag.ACTION.ordinal
itemView.amountEditText.tag = ComputedAction.Tag.AMOUNT.ordinal
this.playerImage.tag = ComputedAction.Tag.PLAYER.ordinal
this.actionButton.tag = ComputedAction.Tag.ACTION.ordinal
this.amountEditText.tag = ComputedAction.Tag.AMOUNT.ordinal
// Action
setOnClickListener(itemView.actionButton)
setOnClickListener(this.actionButton)
// Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
this.amountEditText.let { amountEditText ->
amountEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
amountEditText.isFocusableInTouchMode = true
@ -498,17 +530,17 @@ class EditorAdapter(
val computedAction = row as ComputedAction
configurePlayerImage(itemView.player_image_rha, position, row)
configurePlayerImage(this.playerImage, position, row)
// Position
itemView.findViewById<Button>(R.id.positionButton)?.let { button ->
this.positionButton.let { button ->
button.text = computedAction.position.value
// button.setBackgroundColor(color(computedAction.isHero))
button.backgroundTintList = ColorStateList.valueOf(positionColor(computedAction.isHero))
}
// Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
this.actionButton.let { actionButton ->
actionButton.isEnabled = adapter.dataSource.isEnabled(row, actionButton.tag as Int)
val selected = adapter.dataSource.isSelected(position, row, actionButton.tag as Int)
@ -523,7 +555,7 @@ class EditorAdapter(
}
// Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
this.amountEditText.let { amountEditText ->
val tag = amountEditText.tag as Int
configureEditTexts(tag, position, row, adapter)
}
@ -536,14 +568,15 @@ class EditorAdapter(
* Display a hand street
*/
inner class RowStreetHolder(itemView: View) : RowHandHolder(itemView) {
private var cardsLayout: LinearLayout = itemView.findViewById(R.id.cardsLayout)
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter)
val streetCardsRow = row as StreetCardsRow
itemView.cardsLayout.tag = streetCardsRow.street.ordinal
this.cardsLayout.tag = streetCardsRow.street.ordinal
configureCardsLayout(itemView.cardsLayout, true)
configureCardsLayout(this.cardsLayout, true)
}
@ -553,10 +586,12 @@ class EditorAdapter(
* Display a hand action
*/
inner class RowPlayerSummaryHolder(itemView: View) : RowHandHolder(itemView) {
private var hpsPlayerImage: PlayerImageView = itemView.findViewById(R.id.hps_player_image)
private var handLayout: LinearLayout = itemView.findViewById(R.id.handLayout)
init {
itemView.hps_player_image.tag = PlayerCardsRow.Tag.PLAYER.ordinal
itemView.handLayout.tag = PlayerCardsRow.Tag.CARDS.ordinal
this.hpsPlayerImage.tag = PlayerCardsRow.Tag.PLAYER.ordinal
this.handLayout.tag = PlayerCardsRow.Tag.CARDS.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -571,18 +606,20 @@ class EditorAdapter(
positionButton.setBackgroundColor(color(playerCardView.isHero))
}
configurePlayerImage(itemView.hps_player_image, position, row)
configurePlayerImage(this.hpsPlayerImage, position, row)
configureCardsLayout(itemView.handLayout as LinearLayout, false)
configureCardsLayout(this.handLayout, false)
}
}
abstract inner class AbstractRowPlayerSetup(itemView: View) : RowHandHolder(itemView) {
private var psHandLayout: LinearLayout = itemView.findViewById(R.id.ps_hand_layout)
private var positionButton: AppCompatButton = itemView.findViewById(R.id.position_button)
protected var delegate: RowRepresentableDelegate? = null
init {
itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal
this.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -591,22 +628,28 @@ class EditorAdapter(
this.delegate = adapter.delegate
// Position Button
itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
this.positionButton.text = adapter.dataSource.charSequenceForRow(
row,
itemView.context,
PlayerSetupRow.Tag.POSITION.ordinal
)
val positionalRow = row as PositionalRow
itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionalRow.isHero))
this.positionButton.backgroundTintList = ColorStateList.valueOf(color(positionalRow.isHero))
configureCardsLayout(itemView.ps_hand_layout as LinearLayout, false)
configureCardsLayout(this.psHandLayout, false)
}
}
inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowPlayerSetup(itemView) {
private var psPlayerImage: PlayerImageView = itemView.findViewById(R.id.ps_player_image)
private var stackTextView: TextView = itemView.findViewById(R.id.stack_text_view)
init {
itemView.ps_player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal
itemView.stack_text_view.tag = PlayerSetupRow.Tag.STACK.ordinal
this.psPlayerImage.tag = PlayerSetupRow.Tag.PLAYER.ordinal
this.stackTextView.tag = PlayerSetupRow.Tag.STACK.ordinal
}
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -615,23 +658,27 @@ class EditorAdapter(
configureTextView(PlayerSetupRow.Tag.STACK.ordinal, row, adapter)
// Player
configurePlayerImage(itemView.ps_player_image, position, row as PlayerSetupRow)
configurePlayerImage(this.psPlayerImage, position, row as PlayerSetupRow)
}
}
inner class RowPlayerSetupHolder(itemView: View) : AbstractRowPlayerSetup(itemView) {
private var playerImage: PlayerImageView = itemView.findViewById(R.id.player_image)
private var positionButton: AppCompatButton = itemView.findViewById(R.id.position_button)
private var psHandLayout: LinearLayout = itemView.findViewById(R.id.ps_hand_layout)
private var stackEditText: EditText = itemView.findViewById(R.id.stack_edit_text)
init {
itemView.player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal
itemView.position_button.tag = PlayerSetupRow.Tag.POSITION.ordinal
itemView.ps_hand_layout.tag = PlayerSetupRow.Tag.HAND.ordinal
itemView.stack_edit_text.tag = PlayerSetupRow.Tag.STACK.ordinal
this.playerImage.tag = PlayerSetupRow.Tag.PLAYER.ordinal
this.positionButton.tag = PlayerSetupRow.Tag.POSITION.ordinal
this.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal
this.stackEditText.tag = PlayerSetupRow.Tag.STACK.ordinal
itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(itemView.stack_edit_text)
setOnItemClickListener(itemView.position_button, false)
this.stackEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(this.stackEditText)
setOnItemClickListener(this.positionButton, false)
}
@ -639,7 +686,7 @@ class EditorAdapter(
super.onBind(position, row, adapter)
// Player
configurePlayerImage(itemView.player_image, position, row)
configurePlayerImage(this.playerImage, position, row)
configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
}

Loading…
Cancel
Save