11package com.cornellappdev.score.components
22
3+ import androidx.compose.foundation.BorderStroke
34import androidx.compose.foundation.background
5+ import androidx.compose.foundation.border
46import androidx.compose.foundation.layout.Arrangement
57import androidx.compose.foundation.layout.Column
68import androidx.compose.foundation.layout.Row
79import androidx.compose.foundation.layout.fillMaxWidth
810import androidx.compose.foundation.layout.padding
911import androidx.compose.foundation.shape.RoundedCornerShape
10- import androidx.compose.material3.Divider
12+ import androidx.compose.material3.HorizontalDivider
1113import androidx.compose.material3.Text
1214import androidx.compose.runtime.Composable
1315import androidx.compose.ui.Alignment
1416import androidx.compose.ui.Modifier
17+ import androidx.compose.ui.draw.clip
1518import androidx.compose.ui.graphics.Color
19+ import androidx.compose.ui.text.TextStyle
1620import androidx.compose.ui.text.font.FontWeight
1721import androidx.compose.ui.text.style.TextAlign
1822import androidx.compose.ui.text.style.TextOverflow
@@ -21,13 +25,15 @@ import androidx.compose.ui.unit.dp
2125import com.cornellappdev.score.model.GameData
2226import com.cornellappdev.score.model.TeamScore
2327import com.cornellappdev.score.theme.CrimsonPrimary
28+ import com.cornellappdev.score.theme.GrayMedium
2429import com.cornellappdev.score.theme.GrayPrimary
2530import 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
2832import com.cornellappdev.score.theme.saturatedGreen
2933import com.cornellappdev.score.util.emptyGameData
3034import com.cornellappdev.score.util.gameData
35+ import com.cornellappdev.score.util.longGameData
36+ import com.cornellappdev.score.util.mediumGameData
3137
3238@Composable
3339fun 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
144154private 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
150172private 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+ }
0 commit comments