Refactor Stat management for Header Row

feature/top10
Aurelien Hubert 7 years ago
parent 6bba7b510d
commit 71f06f74c0
  1. 15
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 19
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/HeaderRowRepresentable.kt

@ -9,7 +9,9 @@ import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where import io.realm.kotlin.where
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.SessionInterface import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.Limit import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.TableSize import net.pokeranalytics.android.model.TableSize
@ -345,14 +347,15 @@ open class Session : RealmObject(), SessionInterface, Savable,
rows.add( rows.add(
HeaderRowRepresentable( HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG, RowViewType.HEADER_TITLE_AMOUNT_BIG,
title = getDuration(), value = result?.net.toString() title = getDuration(),
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0)
) )
) )
rows.add( rows.add(
HeaderRowRepresentable( HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT, RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.hour_rate_without_pauses, resId = R.string.hour_rate_without_pauses,
value = this.sessionSet?.hourlyRate.toString() computedStat = ComputedStat(Stat.NETRESULT, this.sessionSet?.hourlyRate ?: 0.0)
) )
) )
@ -361,7 +364,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
HeaderRowRepresentable( HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE, RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation, resId = R.string.bankroll_variation,
value = result?.net.toString() computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0)
) )
) )
} }
@ -389,13 +392,15 @@ open class Session : RealmObject(), SessionInterface, Savable,
SessionRow.BUY_IN -> buyin.toCurrency() SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: NULL_TEXT SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: NULL_TEXT
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else NULL_TEXT SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else NULL_TEXT
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: NULL_TEXT else NULL_TEXT SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime()
?: NULL_TEXT else NULL_TEXT
SessionRow.GAME -> getGameTitle() SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT
SessionRow.LOCATION -> location?.name ?: NULL_TEXT SessionRow.LOCATION -> location?.name ?: NULL_TEXT
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: NULL_TEXT else NULL_TEXT SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime()
?: NULL_TEXT else NULL_TEXT
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT

@ -11,12 +11,9 @@ import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_history_session.view.* import kotlinx.android.synthetic.main.row_history_session.view.*
import kotlinx.android.synthetic.main.row_stats_title_value.view.* import kotlinx.android.synthetic.main.row_stats_title_value.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable
import timber.log.Timber
/** /**
* An interface used to factor the configuration of RecyclerView.ViewHolder * An interface used to factor the configuration of RecyclerView.ViewHolder
@ -106,16 +103,13 @@ enum class RowViewType(private var layoutRes: Int) {
// Value // Value
itemView.findViewById<FormattedTextView?>(R.id.value)?.let { itemView.findViewById<FormattedTextView?>(R.id.value)?.let {
val value = try { if (row.computedStat != null) {
row.value?.toDouble() ?: 0.0 val format = row.computedStat!!.format(itemView.context)
} catch (e: Exception) { it.setTextColor(format.getColor(itemView.context))
0.0 it.text = format.text
} else if (row.value != null) {
it.text = row.value
} }
//TODO: Manage multiple stat type
val stat = ComputedStat(Stat.NETRESULT, value)
it.textFormat = stat.format(itemView.context)
//it.text = adapter.dataSource.stringForRow(row, itemView.context)
} }
} }
} }
@ -145,7 +139,6 @@ enum class RowViewType(private var layoutRes: Int) {
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let { itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let {
it.isChecked = adapter.dataSource.boolForRow(row) it.isChecked = adapter.dataSource.boolForRow(row)
it.setOnCheckedChangeListener { _, isChecked -> it.setOnCheckedChangeListener { _, isChecked ->
Timber.d("Manage switch: $isChecked")
adapter.delegate?.onRowValueChanged(isChecked, row) adapter.delegate?.onRowValueChanged(isChecked, row)
} }
} }

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view.rowrepresentable package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context import android.content.Context
import net.pokeranalytics.android.calculus.ComputedStat
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
@ -11,7 +12,8 @@ class HeaderRowRepresentable(
var customViewType: RowViewType? = RowViewType.HEADER_TITLE, var customViewType: RowViewType? = RowViewType.HEADER_TITLE,
override var resId: Int? = null, override var resId: Int? = null,
var title: String? = null, var title: String? = null,
var value: String? = null var value: String? = null,
var computedStat: ComputedStat? = null
) : RowRepresentable { ) : RowRepresentable {
override fun localizedTitle(context: Context): String { override fun localizedTitle(context: Context): String {
@ -26,6 +28,7 @@ class HeaderRowRepresentable(
} }
override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER_TITLE.ordinal override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER_TITLE.ordinal
} }

Loading…
Cancel
Save