Skip to content

Commit deb9ff6

Browse files
amjiaozachseidner1
andauthored
Fix ScoreBox UI (#48)
* Fix ScoreBox UI * add new preview * more score preview * Font size change based on score length --------- Co-authored-by: zachseidner1 <zachary.seidner@gmail.com>
1 parent a5efd81 commit deb9ff6

3 files changed

Lines changed: 78 additions & 24 deletions

File tree

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package com.cornellappdev.score.components
22

3+
import androidx.compose.foundation.BorderStroke
34
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.border
46
import androidx.compose.foundation.layout.Arrangement
57
import androidx.compose.foundation.layout.Column
68
import androidx.compose.foundation.layout.Row
79
import androidx.compose.foundation.layout.fillMaxWidth
810
import androidx.compose.foundation.layout.padding
911
import androidx.compose.foundation.shape.RoundedCornerShape
10-
import androidx.compose.material3.Divider
12+
import androidx.compose.material3.HorizontalDivider
1113
import androidx.compose.material3.Text
1214
import androidx.compose.runtime.Composable
1315
import androidx.compose.ui.Alignment
1416
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.draw.clip
1518
import androidx.compose.ui.graphics.Color
19+
import androidx.compose.ui.text.TextStyle
1620
import androidx.compose.ui.text.font.FontWeight
1721
import androidx.compose.ui.text.style.TextAlign
1822
import androidx.compose.ui.text.style.TextOverflow
@@ -21,13 +25,15 @@ import androidx.compose.ui.unit.dp
2125
import com.cornellappdev.score.model.GameData
2226
import com.cornellappdev.score.model.TeamScore
2327
import com.cornellappdev.score.theme.CrimsonPrimary
28+
import com.cornellappdev.score.theme.GrayMedium
2429
import com.cornellappdev.score.theme.GrayPrimary
2530
import com.cornellappdev.score.theme.Style.bodyNormal
26-
import com.cornellappdev.score.theme.Style.metricNormal
27-
import com.cornellappdev.score.theme.Style.metricSemibold
31+
import com.cornellappdev.score.theme.Style.labelsNormal
2832
import com.cornellappdev.score.theme.saturatedGreen
2933
import com.cornellappdev.score.util.emptyGameData
3034
import com.cornellappdev.score.util.gameData
35+
import com.cornellappdev.score.util.longGameData
36+
import com.cornellappdev.score.util.mediumGameData
3137

3238
@Composable
3339
fun BoxScore(gameData: GameData) {
@@ -36,17 +42,19 @@ fun BoxScore(gameData: GameData) {
3642
gameData.teamScores.second.scoresByPeriod.size,
3743
4
3844
)
39-
45+
val rowTextStyle = if (maxPeriods > 4) labelsNormal else bodyNormal
4046
Column(
4147
modifier = Modifier
4248
.fillMaxWidth()
43-
.background(Color.White, shape = RoundedCornerShape(8.dp))
49+
.clip(shape = RoundedCornerShape(8.dp))
50+
.background(color = Color.White, shape = RoundedCornerShape(8.dp))
51+
.border(BorderStroke(width = 1.dp, color = CrimsonPrimary))
4452
) {
4553
Row(
4654
modifier = Modifier
4755
.fillMaxWidth()
48-
.background(CrimsonPrimary)
49-
.padding(vertical = 8.dp),
56+
.background(color = CrimsonPrimary)
57+
.padding(top = 6.dp, bottom = 4.dp, end = 8.dp),
5058
verticalAlignment = Alignment.CenterVertically
5159
) {
5260
Text(
@@ -60,47 +68,48 @@ fun BoxScore(gameData: GameData) {
6068
text = "${period + 1}",
6169
modifier = Modifier.weight(1f),
6270
color = Color.White,
63-
style = bodyNormal,
71+
style = rowTextStyle,
6472
textAlign = TextAlign.Center
6573
)
6674
}
6775
Text(
6876
text = "Total",
6977
modifier = Modifier.weight(1f),
70-
style = bodyNormal,
78+
style = rowTextStyle,
7179
color = Color.White,
7280
textAlign = TextAlign.Center
7381
)
7482
}
75-
7683
TeamScoreRow(
7784
teamScore = gameData.teamScores.first,
7885
totalTextColor = saturatedGreen,
86+
rowTextStyle
7987
)
80-
81-
Divider(color = CrimsonPrimary, thickness = 1.dp)
88+
HorizontalDivider(thickness = 1.dp, color = CrimsonPrimary)
8289

8390
TeamScoreRow(
8491
teamScore = gameData.teamScores.second,
85-
totalTextColor = Color.Black,
92+
totalTextColor = GrayMedium,
93+
rowTextStyle
8694
)
95+
8796
}
8897
}
8998

9099
@Composable
91-
fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
100+
fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color, rowTextStyle: TextStyle) {
92101
val showEmpty = teamScore.scoresByPeriod.isEmpty()
93102

94103
Row(
95104
modifier = Modifier
96105
.fillMaxWidth()
97-
.padding(vertical = 8.dp),
106+
.padding(vertical = 8.dp, horizontal = 10.dp),
98107
horizontalArrangement = Arrangement.SpaceBetween,
99108
verticalAlignment = Alignment.CenterVertically
100109
) {
101110
Text(
102111
text = teamScore.team.name,
103-
style = bodyNormal,
112+
style = rowTextStyle,
104113
color = GrayPrimary,
105114
modifier = Modifier.weight(1f),
106115
textAlign = TextAlign.Center,
@@ -112,7 +121,7 @@ fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
112121
Text(
113122
text = if (showEmpty) "-" else score.toString(),
114123
modifier = Modifier.weight(1f),
115-
style = metricNormal,
124+
style = rowTextStyle,
116125
color = GrayPrimary,
117126
textAlign = TextAlign.Center
118127
)
@@ -122,7 +131,7 @@ fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
122131
Text(
123132
text = "-",
124133
modifier = Modifier.weight(1f),
125-
style = metricNormal,
134+
style = rowTextStyle,
126135
color = GrayPrimary,
127136
textAlign = TextAlign.Center
128137
)
@@ -131,22 +140,42 @@ fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
131140
Text(
132141
text = if (showEmpty) "-" else teamScore.totalScore.toString(),
133142
modifier = Modifier.weight(1f),
134-
style = metricSemibold,
143+
style = rowTextStyle,
135144
color = if (showEmpty) Color.Gray else totalTextColor,
136145
fontWeight = if (showEmpty) FontWeight.Normal else FontWeight.Bold,
137146
textAlign = TextAlign.Center
138147
)
139148
}
140149
}
141150

151+
142152
@Preview
143153
@Composable
144154
private fun PreviewBoxScore() = ScorePreview {
145155
BoxScore(gameData = gameData)
146156
}
147157

158+
@Preview
159+
@Composable
160+
private fun PreviewBoxScoreForLongGame() = ScorePreview {
161+
BoxScore(longGameData)
162+
}
163+
164+
@Preview
165+
@Composable
166+
private fun PreviewBoxScoreForMedGame() = ScorePreview {
167+
BoxScore(mediumGameData)
168+
}
169+
148170
@Preview
149171
@Composable
150172
private fun PreviewBoxScoreEmpty() = ScorePreview {
151173
BoxScore(gameData = emptyGameData())
152174
}
175+
176+
177+
@Preview
178+
@Composable
179+
private fun PreviewTeamScoreRow() = ScorePreview {
180+
TeamScoreRow(gameData.teamScores.first, GrayMedium, bodyNormal)
181+
}

app/src/main/java/com/cornellappdev/score/screen/GameDetailsScreen.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ fun GameDetailsContent(gameCard: DetailsCardData) {
158158
// render the below if the game is in the future
159159
// TODO: MESSY, is it every the case when there is a boxscore but no scoring summary
160160
if (gameCard.isPastStartTime) {
161-
if (gameCard.scoreBreakdown?.isNotEmpty() == true) {
162-
Spacer(modifier = Modifier.height(24.dp))
163-
BoxScore(gameCard.gameData)
164-
Spacer(modifier = Modifier.height(24.dp))
165-
}
161+
//if (gameCard.scoreBreakdown?.isNotEmpty() == true) {
162+
Spacer(modifier = Modifier.height(24.dp))
163+
BoxScore(gameCard.gameData)
164+
Spacer(modifier = Modifier.height(24.dp))
165+
// }
166166
if (gameCard.boxScore.isNotEmpty()) {
167167
Text(
168168
"Scoring Summary", fontSize = 18.sp,

app/src/main/java/com/cornellappdev/score/util/TestingConstants.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,33 @@ val teamScore2 = TeamScore(
6868
totalScore = 23
6969
)
7070

71+
val mediumGameTeamScore1 = TeamScore(
72+
team = team1,
73+
scoresByPeriod = listOf(13, 14, 6, 14, 13, 2),
74+
totalScore = 62
75+
)
76+
val mediumGameTeamScore2 = TeamScore(
77+
team = team1,
78+
scoresByPeriod = listOf(7, 7, 9, 0, 7, 7),
79+
totalScore = 37
80+
)
81+
82+
val longGameTeamScore1 = TeamScore(
83+
team = team1,
84+
scoresByPeriod = listOf(13, 14, 6, 14, 13, 2, 4, 6, 2, 2),
85+
totalScore = 47
86+
)
87+
val longGameTeamScore2 = TeamScore(
88+
team = team1,
89+
scoresByPeriod = listOf(7, 7, 9, 0, 7, 7, 9, 0, 7, 2),
90+
totalScore = 47
91+
)
7192
val gameData = GameData(teamScores = Pair(teamScore1, teamScore2))
7293

94+
val mediumGameData = GameData(teamScores = mediumGameTeamScore1 to mediumGameTeamScore2)
95+
96+
val longGameData = GameData(teamScores = longGameTeamScore1 to longGameTeamScore2)
97+
7398
val team3 = TeamGameSummary(
7499
name = "Cornell",
75100
"https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max"

0 commit comments

Comments
 (0)