Refactor Stat management for Header Row

feature/top10
Aurelien Hubert 7 years ago
parent 6bba7b510d
commit 71f06f74c0
  1. 17
      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. 13
      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.kotlin.where
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.TableSize
@ -345,14 +347,15 @@ open class Session : RealmObject(), SessionInterface, Savable,
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG,
title = getDuration(), value = result?.net.toString()
title = getDuration(),
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0)
)
)
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
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(
RowViewType.HEADER_TITLE_VALUE,
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.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: 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.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT
SessionRow.LOCATION -> location?.name ?: NULL_TEXT
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.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.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT
@ -578,7 +583,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
if (value == null) {
localResult.cashout = null
} else {
localResult.cashout = (value as String).toDouble()
localResult.cashout = (value as String).toDouble()
val timeFrameToUpdate =
if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
timeFrameToUpdate.setEnd(Date())

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

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
@ -8,11 +9,12 @@ import net.pokeranalytics.android.ui.view.RowViewType
* A class to display headers as row representable
*/
class HeaderRowRepresentable(
var customViewType: RowViewType? = RowViewType.HEADER_TITLE,
override var resId: Int? = null,
var title: String? = null,
var value: String? = null
) : RowRepresentable {
var customViewType: RowViewType? = RowViewType.HEADER_TITLE,
override var resId: Int? = null,
var title: String? = null,
var value: String? = null,
var computedStat: ComputedStat? = null
) : RowRepresentable {
override fun localizedTitle(context: Context): String {
@ -26,6 +28,7 @@ class HeaderRowRepresentable(
}
override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER_TITLE.ordinal
}

Loading…
Cancel
Save