From 665d8f491d1dd19f274e142b57773a54794c03ae Mon Sep 17 00:00:00 2001 From: Aurelien Hubert Date: Mon, 25 Feb 2019 15:39:53 +0100 Subject: [PATCH 1/3] Improve Session history UI --- .../android/ui/view/SessionRowView.kt | 59 ++++++++- .../pokeranalytics/android/util/Extensions.kt | 4 +- app/src/main/res/layout/row_session_view.xml | 121 ++++++++++++++++-- app/src/main/res/values/styles.xml | 1 + 4 files changed, 167 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt index 30a0b39a..b791200e 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt @@ -6,13 +6,16 @@ import android.view.LayoutInflater import android.widget.FrameLayout import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import kotlinx.android.synthetic.main.row_session_view.view.* import net.pokeranalytics.android.R +import net.pokeranalytics.android.model.TableSize +import net.pokeranalytics.android.model.extensions.SessionState +import net.pokeranalytics.android.model.extensions.getState import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.util.getDayNumber import net.pokeranalytics.android.util.getShortDayName import net.pokeranalytics.android.util.toCurrency -import timber.log.Timber class SessionRowView : FrameLayout { @@ -55,16 +58,58 @@ class SessionRowView : FrameLayout { */ fun setData(session: Session) { + // Date rowHistorySession.dateDay.text = session.creationDate.getShortDayName() rowHistorySession.dateNumber.text = session.creationDate.getDayNumber() - rowHistorySession.gameType.text = session.getGameTitle() - rowHistorySession.gameInfo.text = session.getDuration(context) - rowHistorySession.gameResult.text = session.result?.netResult?.toCurrency() ?: "$0" + // Title / Game type + var title = "" + if (session.cgSmallBlind != null && session.cgBigBlind != null) { + title += session.getBlinds() + } + session.game?.let { + title += session.getGameTitle() + } + title += if (title.isEmpty()) "--" else "" - val result = session.result?.netResult ?: 0.0 - val resultColor = if (result >= 0.0) R.color.green else R.color.red - rowHistorySession.gameResult.setTextColor(ContextCompat.getColor(context, resultColor)) + rowHistorySession.sessionTitle.text = title + + // Duration + rowHistorySession.sessionInfoDurationIcon.isVisible = session.timeFrame != null + rowHistorySession.sessionInfoDurationValue.isVisible = session.timeFrame != null + session.timeFrame?.let { + rowHistorySession.sessionInfoDurationValue.text = session.getDuration(context) + } + + // Location + rowHistorySession.sessionInfoLocationIcon.isVisible = session.location != null + rowHistorySession.sessionInfoLocationValue.isVisible = session.location != null + session.location?.let { + rowHistorySession.sessionInfoLocationValue.text = it.name + } + + // Table size + rowHistorySession.sessionInfoTableIcon.isVisible = session.tableSize != null + rowHistorySession.sessionInfoTableValue.isVisible = session.tableSize != null + session.tableSize?.let { + rowHistorySession.sessionInfoTableValue.text = TableSize.all[it].localizedTitle(context) + } + + // State + if (session.getState() == SessionState.STARTED) { + rowHistorySession.gameResult.isVisible = false + rowHistorySession.playingIcon.isVisible = true + rowHistorySession.playingTitle.isVisible = true + } else { + rowHistorySession.gameResult.isVisible = true + rowHistorySession.playingIcon.isVisible = false + rowHistorySession.playingTitle.isVisible = false + + val result = session.result?.netResult ?: 0.0 + val resultColor = if (result >= 0.0) R.color.green else R.color.red + rowHistorySession.gameResult.text = result.toCurrency() + rowHistorySession.gameResult.setTextColor(ContextCompat.getColor(context, resultColor)) + } } diff --git a/app/src/main/java/net/pokeranalytics/android/util/Extensions.kt b/app/src/main/java/net/pokeranalytics/android/util/Extensions.kt index 9037f16a..b02ee6a0 100644 --- a/app/src/main/java/net/pokeranalytics/android/util/Extensions.kt +++ b/app/src/main/java/net/pokeranalytics/android/util/Extensions.kt @@ -104,13 +104,11 @@ fun Date.getDuration(context: Context, toDate: Date) : String { val numOfDays = (difference / (1000 * 60 * 60 * 24)) val hours = (difference / (1000 * 60 * 60)) val minutes = (difference / (1000 * 60)) % 60 - val seconds = (difference / 1000) % 60 val hoursStr = if (hours < 10) "0$hours" else "$hours" val minutesStr = if (minutes < 10) "0$minutes" else "$minutes" - val secondsStr = if (seconds < 10) "0$seconds" else "$seconds" - return "$hoursStr:$minutesStr:$secondsStr" + return "$hoursStr:$minutesStr" } diff --git a/app/src/main/res/layout/row_session_view.xml b/app/src/main/res/layout/row_session_view.xml index 61515f4b..b8520741 100644 --- a/app/src/main/res/layout/row_session_view.xml +++ b/app/src/main/res/layout/row_session_view.xml @@ -36,14 +36,14 @@ tools:text="21" /> + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toTopOf="@+id/sessionTitle"> + + + + 12sp @font/roboto + 0.02 - + + +