@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Arrangement
66import androidx.compose.foundation.layout.Column
77import androidx.compose.foundation.layout.IntrinsicSize
88import androidx.compose.foundation.layout.Row
9+ import androidx.compose.foundation.layout.Spacer
910import androidx.compose.foundation.layout.fillMaxWidth
1011import androidx.compose.foundation.layout.height
1112import androidx.compose.foundation.layout.padding
@@ -28,8 +29,8 @@ import androidx.compose.ui.text.style.TextOverflow
2829import androidx.compose.ui.tooling.preview.Preview
2930import androidx.compose.ui.unit.dp
3031import com.cornellappdev.score.model.GameData
32+ import com.cornellappdev.score.model.ScoresByPeriod
3133import com.cornellappdev.score.model.TeamScore
32- import com.cornellappdev.score.model.mapToPeriodScores
3334import com.cornellappdev.score.theme.CrimsonPrimary
3435import com.cornellappdev.score.theme.GrayMedium
3536import com.cornellappdev.score.theme.GrayPrimary
@@ -44,23 +45,14 @@ import com.cornellappdev.score.util.mediumGameData
4445import com.cornellappdev.score.util.shortGameData
4546
4647private val HEADER_HEIGHT = 35 .dp
48+ private val SMALL_BOX_SIZE = 4
49+ private val LARGE_BOX_SIZE = 10
4750
4851@Composable
4952fun BoxScore (
5053 gameData : GameData ,
5154 modifier : Modifier = Modifier
5255) {
53- val maxPeriods = maxOf(
54- gameData.teamScores.first.scoresByPeriod.size,
55- gameData.teamScores.second.scoresByPeriod.size
56- )
57-
58- val rowTextStyle = if (maxPeriods > 4 ) {
59- metricSmallNormal
60- } else {
61- metricNormal
62- }
63-
6456 Surface (
6557 modifier = modifier
6658 // set height required for CompleteLazyTableData case
@@ -75,24 +67,21 @@ fun BoxScore(
7567 modifier = Modifier
7668 .fillMaxWidth()
7769 ) {
70+ val rowTextStyle = if (gameData.maxPeriods > SMALL_BOX_SIZE ) {
71+ metricSmallNormal
72+ } else {
73+ metricNormal
74+ }
7875 TeamNameColumn (
7976 gameData.teamScores.first.team.name,
8077 gameData.teamScores.second.team.name,
8178 rowTextStyle,
82- maxPeriods
79+ gameData.maxPeriods
80+ )
81+ CompleteTableData (
82+ gameData = gameData,
83+ rowTextStyle = rowTextStyle
8384 )
84- if (maxPeriods > 10 ) {
85- CompleteLazyTableData (
86- gameData = gameData,
87- rowTextStyle = rowTextStyle
88- )
89- } else {
90- CompleteTableData (
91- gameData = gameData,
92- rowTextStyle = rowTextStyle,
93- maxPeriods = maxPeriods
94- )
95- }
9685 }
9786 }
9887}
@@ -113,13 +102,13 @@ private fun TeamNameColumn(
113102 modifier.widthIn(max = 100 .dp)
114103 }
115104 ) {
116- Row (
105+ Spacer (
117106 modifier = Modifier
118107 .fillMaxWidth()
119108 .background(color = CrimsonPrimary )
120109 .height(HEADER_HEIGHT )
121110 .padding(top = 6 .dp, bottom = 4 .dp),
122- ) {}
111+ )
123112 Row (
124113 modifier = Modifier
125114 .fillMaxWidth()
@@ -221,54 +210,37 @@ private fun TableDataColumn(
221210}
222211
223212@Composable
224- private fun CompleteLazyTableData (
225- gameData : GameData ,
213+ private fun LazyDataRow (
214+ periodScores : List < ScoresByPeriod > ,
226215 rowTextStyle : TextStyle ,
227216 modifier : Modifier = Modifier
228217) {
229- val periodScores = mapToPeriodScores(gameData)
230-
231- if (periodScores.isNotEmpty()) {
232- Row (
233- modifier = modifier
234- ) {
235- LazyRow (
236- modifier = Modifier .weight(1f )
237- ) {
238- items(periodScores) { periodScore ->
239- TableDataColumn (
240- header = periodScore.header,
241- teamOneScore = periodScore.teamOneScore,
242- teamTwoScore = periodScore.teamTwoScore,
243- rowTextStyle = rowTextStyle,
244- modifier = Modifier .width(35 .dp)
245- )
246- }
247- }
248- TotalsColumn (
249- teamOneScores = gameData.teamScores.first,
250- teamTwoScores = gameData.teamScores.second,
251- rowTextStyle = rowTextStyle
218+ LazyRow (
219+ modifier = modifier
220+ ) {
221+ items(periodScores) { periodScore ->
222+ TableDataColumn (
223+ header = periodScore.header,
224+ teamOneScore = periodScore.teamOneScore,
225+ teamTwoScore = periodScore.teamTwoScore,
226+ rowTextStyle = rowTextStyle,
227+ modifier = Modifier .width(35 .dp)
252228 )
253229 }
254230 }
255231}
256232
257233@Composable
258- private fun CompleteTableData (
259- gameData : GameData ,
234+ private fun DataRow (
235+ periodScores : List < ScoresByPeriod > ,
260236 rowTextStyle : TextStyle ,
261- maxPeriods : Int ,
262237 modifier : Modifier = Modifier
263238) {
264- val periodScores = mapToPeriodScores(gameData)
265-
266239 Row (
267- modifier = modifier,
268- horizontalArrangement = Arrangement .SpaceEvenly
240+ modifier = modifier.fillMaxWidth()
269241 ) {
270242 if (periodScores.isNotEmpty()) {
271- mapToPeriodScores(gameData) .map { periodScore ->
243+ periodScores .map { periodScore ->
272244 TableDataColumn (
273245 header = periodScore.header,
274246 teamOneScore = periodScore.teamOneScore,
@@ -288,20 +260,47 @@ private fun CompleteTableData(
288260 )
289261 }
290262 }
263+ }
264+ }
265+
266+ @Composable
267+ private fun CompleteTableData (
268+ gameData : GameData ,
269+ rowTextStyle : TextStyle ,
270+ modifier : Modifier = Modifier
271+ ) {
272+ val periodScores = gameData.mapToPeriodScores()
273+
274+ Row (
275+ modifier = modifier
276+ ) {
277+ if (gameData.maxPeriods > LARGE_BOX_SIZE ) {
278+ LazyDataRow (
279+ periodScores,
280+ rowTextStyle,
281+ Modifier .weight(1f )
282+ )
283+ } else {
284+ DataRow (
285+ periodScores,
286+ rowTextStyle,
287+ Modifier .weight(1f )
288+ )
289+ }
290+
291291 TotalsColumn (
292292 teamOneScores = gameData.teamScores.first,
293293 teamTwoScores = gameData.teamScores.second,
294+ rowTextStyle = rowTextStyle,
294295 // if maxPeriods > 8, "Totals" header will wrap to two lines. In this case, don't weight so that space is allocated to TotalsColumn first
295296 // otherwise, TotalsColumn will fit without wrapping and can be allocated equal width as the data columns
296- modifier = if (maxPeriods < 4 ) {
297+ modifier = if (gameData. maxPeriods < 4 ) {
297298 Modifier .weight(1f , fill = true )
298299 } else {
299300 Modifier
300- },
301- rowTextStyle = rowTextStyle
301+ }
302302 )
303303 }
304-
305304}
306305
307306@Composable
@@ -324,7 +323,8 @@ private fun TotalScoreCell(
324323 style = rowTextStyle,
325324 color = if (showEmpty) Color .Gray else totalTextColor,
326325 fontWeight = if (showEmpty) FontWeight .Normal else FontWeight .Bold ,
327- textAlign = TextAlign .Center
326+ textAlign = TextAlign .Center ,
327+ modifier = Modifier .fillMaxWidth()
328328 )
329329 }
330330}
@@ -351,9 +351,9 @@ private fun TotalsColumn(
351351 ) {
352352 Text (
353353 text = " Total" ,
354- color = Color .White ,
355354 style = rowTextStyle,
356- textAlign = TextAlign .Center
355+ textAlign = TextAlign .Center ,
356+ color = Color .White
357357 )
358358 }
359359
0 commit comments