|
|
|
|
@ -4,9 +4,10 @@ import android.content.Context |
|
|
|
|
import android.util.AttributeSet |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.widget.FrameLayout |
|
|
|
|
import android.widget.ImageView |
|
|
|
|
import android.widget.TextView |
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout |
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
|
import kotlinx.android.synthetic.main.row_session_view.view.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.ComputedStat |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
@ -27,6 +28,19 @@ class SessionRowView : FrameLayout { |
|
|
|
|
|
|
|
|
|
private lateinit var rowSession: ConstraintLayout |
|
|
|
|
|
|
|
|
|
private lateinit var dateDay: TextView |
|
|
|
|
private lateinit var dateNumber: TextView |
|
|
|
|
private lateinit var sessionTitle: TextView |
|
|
|
|
private lateinit var sessionInfoDurationIcon: ImageView |
|
|
|
|
private lateinit var sessionInfoDurationValue: TextView |
|
|
|
|
private lateinit var sessionInfoLocationIcon: ImageView |
|
|
|
|
private lateinit var sessionInfoLocationValue: TextView |
|
|
|
|
private lateinit var sessionInfoTableIcon: ImageView |
|
|
|
|
private lateinit var sessionInfoTableValue: TextView |
|
|
|
|
private lateinit var gameResult: TextView |
|
|
|
|
private lateinit var infoIcon: ImageView |
|
|
|
|
private lateinit var infoTitle: TextView |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructors |
|
|
|
|
*/ |
|
|
|
|
@ -48,8 +62,21 @@ class SessionRowView : FrameLayout { |
|
|
|
|
private fun init() { |
|
|
|
|
val layoutInflater = LayoutInflater.from(context) |
|
|
|
|
rowSession = layoutInflater.inflate(R.layout.row_session_view, this, false) as ConstraintLayout |
|
|
|
|
val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT) |
|
|
|
|
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT) |
|
|
|
|
addView(rowSession, layoutParams) |
|
|
|
|
|
|
|
|
|
this.dateDay = rowSession.findViewById(R.id.dateDay) |
|
|
|
|
this.dateNumber = rowSession.findViewById(R.id.dateNumber) |
|
|
|
|
this.sessionTitle = rowSession.findViewById(R.id.sessionTitle) |
|
|
|
|
this.sessionInfoDurationIcon = rowSession.findViewById(R.id.sessionInfoDurationIcon) |
|
|
|
|
this.sessionInfoDurationValue = rowSession.findViewById(R.id.sessionInfoDurationValue) |
|
|
|
|
this.sessionInfoLocationIcon = rowSession.findViewById(R.id.sessionInfoLocationIcon) |
|
|
|
|
this.sessionInfoLocationValue = rowSession.findViewById(R.id.sessionInfoLocationValue) |
|
|
|
|
this.sessionInfoTableIcon = rowSession.findViewById(R.id.sessionInfoTableIcon) |
|
|
|
|
this.sessionInfoTableValue = sessionInfoTableValue.findViewById(R.id.dateDay) |
|
|
|
|
this.gameResult = rowSession.findViewById(R.id.gameResult) |
|
|
|
|
this.infoIcon = rowSession.findViewById(R.id.infoIcon) |
|
|
|
|
this.infoTitle = rowSession.findViewById(R.id.infoTitle) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -60,69 +87,69 @@ class SessionRowView : FrameLayout { |
|
|
|
|
val date = session.startDate ?: session.creationDate |
|
|
|
|
|
|
|
|
|
// Date |
|
|
|
|
rowSession.dateDay.text = date.getShortDayName() |
|
|
|
|
rowSession.dateNumber.text = date.getDayNumber() |
|
|
|
|
this.dateDay.text = date.getShortDayName() |
|
|
|
|
this.dateNumber.text = date.getDayNumber() |
|
|
|
|
|
|
|
|
|
// Title / Game type |
|
|
|
|
rowSession.sessionTitle.text = session.getFormattedGameType(context) |
|
|
|
|
this.sessionTitle.text = session.getFormattedGameType(context) |
|
|
|
|
|
|
|
|
|
// Duration |
|
|
|
|
rowSession.sessionInfoDurationValue.text = session.getFormattedDuration() |
|
|
|
|
this.sessionInfoDurationValue.text = session.getFormattedDuration() |
|
|
|
|
|
|
|
|
|
// Location |
|
|
|
|
rowSession.sessionInfoLocationIcon.isVisible = session.location != null |
|
|
|
|
rowSession.sessionInfoLocationValue.isVisible = session.location != null |
|
|
|
|
this.sessionInfoLocationIcon.isVisible = session.location != null |
|
|
|
|
this.sessionInfoLocationValue.isVisible = session.location != null |
|
|
|
|
session.location?.let { |
|
|
|
|
rowSession.sessionInfoLocationValue.text = it.name |
|
|
|
|
this.sessionInfoLocationValue.text = it.name |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Table size |
|
|
|
|
rowSession.sessionInfoTableIcon.isVisible = session.tableSize != null |
|
|
|
|
rowSession.sessionInfoTableValue.isVisible = session.tableSize != null |
|
|
|
|
this.sessionInfoTableIcon.isVisible = session.tableSize != null |
|
|
|
|
this.sessionInfoTableValue.isVisible = session.tableSize != null |
|
|
|
|
session.tableSize?.let { |
|
|
|
|
rowSession.sessionInfoTableValue.text = TableSize(it).localizedTitle(context) |
|
|
|
|
this.sessionInfoTableValue.text = TableSize(it).localizedTitle(context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val state = session.getState() |
|
|
|
|
rowSession.sessionInfoDurationIcon.isVisible = state.hasStarted |
|
|
|
|
rowSession.sessionInfoDurationValue.isVisible = state.hasStarted |
|
|
|
|
this.sessionInfoDurationIcon.isVisible = state.hasStarted |
|
|
|
|
this.sessionInfoDurationValue.isVisible = state.hasStarted |
|
|
|
|
|
|
|
|
|
// State |
|
|
|
|
when (state) { |
|
|
|
|
SessionState.STARTED -> { |
|
|
|
|
rowSession.gameResult.isVisible = false |
|
|
|
|
rowSession.infoIcon.isVisible = true |
|
|
|
|
rowSession.infoIcon.setImageResource(R.drawable.ic_play_circle_outline) |
|
|
|
|
rowSession.infoTitle.isVisible = true |
|
|
|
|
rowSession.infoTitle.text = context.getString(R.string.running_session_state) |
|
|
|
|
this.gameResult.isVisible = false |
|
|
|
|
this.infoIcon.isVisible = true |
|
|
|
|
this.infoIcon.setImageResource(R.drawable.ic_play_circle_outline) |
|
|
|
|
this.infoTitle.isVisible = true |
|
|
|
|
this.infoTitle.text = context.getString(R.string.running_session_state) |
|
|
|
|
} |
|
|
|
|
SessionState.PAUSED -> { |
|
|
|
|
rowSession.gameResult.isVisible = false |
|
|
|
|
rowSession.infoIcon.isVisible = true |
|
|
|
|
rowSession.infoIcon.setImageResource(R.drawable.ic_pause_circle_outline) |
|
|
|
|
rowSession.infoTitle.isVisible = true |
|
|
|
|
rowSession.infoTitle.text = context.getString(R.string.paused_session_state) |
|
|
|
|
this.gameResult.isVisible = false |
|
|
|
|
this.infoIcon.isVisible = true |
|
|
|
|
this.infoIcon.setImageResource(R.drawable.ic_pause_circle_outline) |
|
|
|
|
this.infoTitle.isVisible = true |
|
|
|
|
this.infoTitle.text = context.getString(R.string.paused_session_state) |
|
|
|
|
} |
|
|
|
|
SessionState.PLANNED -> { |
|
|
|
|
rowSession.gameResult.isVisible = false |
|
|
|
|
rowSession.infoIcon.isVisible = true |
|
|
|
|
rowSession.infoIcon.setImageResource(R.drawable.ic_planned) |
|
|
|
|
rowSession.infoTitle.isVisible = true |
|
|
|
|
rowSession.infoTitle.text = session.startDate!!.shortTime() |
|
|
|
|
this.gameResult.isVisible = false |
|
|
|
|
this.infoIcon.isVisible = true |
|
|
|
|
this.infoIcon.setImageResource(R.drawable.ic_planned) |
|
|
|
|
this.infoTitle.isVisible = true |
|
|
|
|
this.infoTitle.text = session.startDate!!.shortTime() |
|
|
|
|
} |
|
|
|
|
SessionState.PENDING -> { |
|
|
|
|
rowSession.gameResult.isVisible = false |
|
|
|
|
rowSession.infoIcon.isVisible = false |
|
|
|
|
rowSession.infoTitle.isVisible = false |
|
|
|
|
this.gameResult.isVisible = false |
|
|
|
|
this.infoIcon.isVisible = false |
|
|
|
|
this.infoTitle.isVisible = false |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
rowSession.gameResult.isVisible = true |
|
|
|
|
rowSession.infoIcon.isVisible = false |
|
|
|
|
rowSession.infoTitle.isVisible = false |
|
|
|
|
this.gameResult.isVisible = true |
|
|
|
|
this.infoIcon.isVisible = false |
|
|
|
|
this.infoTitle.isVisible = false |
|
|
|
|
|
|
|
|
|
session.result?.net?.let { netResult -> |
|
|
|
|
val stat = ComputedStat(Stat.NET_RESULT, netResult, currency = session.currency) |
|
|
|
|
rowSession.gameResult.setTextFormat(stat.textFormat, context) |
|
|
|
|
this.gameResult.setTextFormat(stat.textFormat, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// val formattedStat = ComputedStat(Stat.NET_RESULT, result, currency = session.currency).format() |
|
|
|
|
|