Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import com.cornellappdev.score.util.gameData
fun BoxScore(gameData: GameData) {
val maxPeriods = maxOf(
gameData.teamScores.first.scoresByPeriod.size,
gameData.teamScores.second.scoresByPeriod.size,
4
gameData.teamScores.second.scoresByPeriod.size
)

Column(
Expand Down Expand Up @@ -76,19 +75,21 @@ fun BoxScore(gameData: GameData) {
TeamScoreRow(
teamScore = gameData.teamScores.first,
totalTextColor = saturatedGreen,
maxPeriods = maxPeriods
)

Divider(color = CrimsonPrimary, thickness = 1.dp)

TeamScoreRow(
teamScore = gameData.teamScores.second,
totalTextColor = Color.Black,
maxPeriods = maxPeriods
)
}
}

@Composable
fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color, maxPeriods: Int) {
val showEmpty = teamScore.scoresByPeriod.isEmpty()

Row(
Expand Down Expand Up @@ -118,7 +119,7 @@ fun TeamScoreRow(teamScore: TeamScore, totalTextColor: Color) {
)
}

repeat(4 - teamScore.scoresByPeriod.size) {
repeat(maxPeriods - teamScore.scoresByPeriod.size) {
Text(
text = "-",
modifier = Modifier.weight(1f),
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/cornellappdev/score/model/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.cornellappdev.score.util.parseDateOrNull
import com.cornellappdev.score.util.parseDateTimeOrNull
import com.cornellappdev.score.util.parseResultScore
import com.cornellappdev.score.util.toGameData
import kotlinx.serialization.Serializable
import java.time.LocalDate
import java.time.LocalDateTime

Expand Down Expand Up @@ -151,6 +152,7 @@ data class GameData(
* @property score Current score after the event (e.g., "10 - 7").
* @property description Optional detailed description of the event.
*/
@Serializable
data class ScoreEvent(
val id: Int,
val time: String,
Expand All @@ -169,6 +171,7 @@ data class TeamBoxScore(
val name: String
)

@Serializable
data class TeamGameSummary(
val name: String,
val logo: String
Expand Down Expand Up @@ -273,12 +276,16 @@ fun List<GameDetailsBoxScore>.toScoreEvents(teamLogo: String): List<ScoreEvent>
val teamName = boxScore.team ?: ""
val corScore = boxScore.corScore ?: 0
val oppScore = boxScore.oppScore ?: 0

val teamSummary = if (teamName == "COR") {
TeamGameSummary(teamName, logo = R.drawable.cornell_logo.toString())
} else {
TeamGameSummary(teamName, logo = teamLogo)
}
ScoreEvent(
id = index,
time = boxScore.time ?: "",
quarter = boxScore.period ?: "",
team = TeamGameSummary(teamName, logo = teamLogo),
team = teamSummary,
eventType = "Score", // TODO: Change to what ios has and not figma
score = "$corScore - $oppScore",
description = boxScore.description
Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/com/cornellappdev/score/nav/ScoreNavHost.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.cornellappdev.score.nav

import GameScoreSummaryScreenDetail
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import com.cornellappdev.score.model.ScoreEvent
import com.cornellappdev.score.nav.root.ScoreScreens
import com.cornellappdev.score.nav.root.ScoreScreens.Home
import com.cornellappdev.score.screen.GameDetailsScreen
import com.cornellappdev.score.screen.HomeScreen
import com.cornellappdev.score.screen.PastGamesScreen
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json

@Composable
fun ScoreNavHost(navController: NavHostController) {
Expand Down Expand Up @@ -38,9 +43,27 @@ fun ScoreNavHost(navController: NavHostController) {
}
}
composable<ScoreScreens.GameDetailsPage> {
GameDetailsScreen(onBackArrow = {
GameDetailsScreen(
onBackArrow = {
navController.navigateUp()
},
navigateToGameScoreSummary = { scoreEvents: List<ScoreEvent> ->
val scoreEventsJson =
Json.encodeToString(ListSerializer(ScoreEvent.serializer()), scoreEvents)
navController.navigate(ScoreScreens.GameScoreSummaryPage(scoreEventsJson))
}
)
}

composable<ScoreScreens.GameScoreSummaryPage> { backStackEntry ->
val route = backStackEntry.toRoute<ScoreScreens.GameScoreSummaryPage>()
val scoreEvents: List<ScoreEvent> = Json.decodeFromString(route.scoreEvents)
GameScoreSummaryScreenDetail(scoreEvents = scoreEvents, onBackArrow = {
navController.navigateUp()
})
}


}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import com.cornellappdev.score.R
import com.cornellappdev.score.nav.ScoreNavHost
import com.cornellappdev.score.nav.ScoreNavigationBar
import com.cornellappdev.score.nav.root.ScoreScreens.GameDetailsPage
import com.cornellappdev.score.nav.root.ScoreScreens.Home
import com.cornellappdev.score.nav.root.ScoreScreens.ScoresScreen
import com.cornellappdev.score.theme.LocalInfiniteLoading
import kotlinx.serialization.Serializable

Expand Down Expand Up @@ -84,13 +82,17 @@ sealed class ScoreScreens {

@Serializable
data object ScoresScreen : ScoreScreens()

@Serializable
data class GameScoreSummaryPage(val scoreEvents: String) : ScoreScreens()
}

fun NavBackStackEntry.toScreen(): ScoreScreens? =
when (destination.route?.substringAfterLast(".")?.substringBefore("/")) {
"Home" -> toRoute<Home>()
"GameDetailsPage" -> toRoute<GameDetailsPage>()
"ScoresScreen" -> toRoute<ScoresScreen>()
"Home" -> toRoute<ScoreScreens.Home>()
"GameDetailsPage" -> toRoute<ScoreScreens.GameDetailsPage>()
"ScoresScreen" -> toRoute<ScoreScreens.ScoresScreen>()
"GameScoreSummaryPage" -> toRoute<ScoreScreens.GameScoreSummaryPage>()
else -> throw IllegalArgumentException("Invalid screen")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -29,7 +30,6 @@ import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import com.cornellappdev.score.R
import com.cornellappdev.score.components.BoxScore
import com.cornellappdev.score.components.ButtonPrimary
import com.cornellappdev.score.components.ErrorState
import com.cornellappdev.score.components.GameDetailsLoadingScreen
import com.cornellappdev.score.components.GameScoreHeader
Expand All @@ -51,15 +51,14 @@ import com.cornellappdev.score.theme.Style.heading1
import com.cornellappdev.score.theme.Style.heading2
import com.cornellappdev.score.theme.Style.heading3
import com.cornellappdev.score.theme.White
import com.cornellappdev.score.util.addToCalendar
import com.cornellappdev.score.util.toCalendarEvent
import com.cornellappdev.score.viewmodel.GameDetailsViewModel
import java.time.LocalDate

@Composable
fun GameDetailsScreen(
gameDetailsViewModel: GameDetailsViewModel = hiltViewModel(),
onBackArrow: () -> Unit = {}
onBackArrow: () -> Unit = {},
navigateToGameScoreSummary: (List<ScoreEvent>) -> Unit
) {
val uiState = gameDetailsViewModel.collectUiStateValue()
ScorePullToRefreshBox(
Expand Down Expand Up @@ -92,7 +91,8 @@ fun GameDetailsScreen(

is ApiResponse.Success -> {
GameDetailsContent(
gameCard = state.data
gameCard = state.data,
navigateToGameScoreSummary = navigateToGameScoreSummary
)
}
}
Expand All @@ -101,7 +101,10 @@ fun GameDetailsScreen(
}

@Composable
fun GameDetailsContent(gameCard: DetailsCardData) {
fun GameDetailsContent(
gameCard: DetailsCardData,
navigateToGameScoreSummary: (List<ScoreEvent>) -> Unit
) {
Column(
modifier = Modifier
.background(White)
Expand Down Expand Up @@ -164,10 +167,26 @@ fun GameDetailsContent(gameCard: DetailsCardData) {
Spacer(modifier = Modifier.height(24.dp))
}
if (gameCard.boxScore.isNotEmpty()) {
Text(
"Scoring Summary", fontSize = 18.sp,
style = heading2,
) // TODO: NAVIGATION
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
Text(
"Scoring Summary", fontSize = 18.sp,
style = heading2,
)
Spacer(modifier = Modifier.weight(1f))
IconButton(onClick = { navigateToGameScoreSummary(gameCard.scoreEvent) }) {
Icon(
painter = painterResource(id = R.drawable.ic_right_chevron),
contentDescription = "Back button",
modifier = Modifier
.width(24.dp)
.height(24.dp),
)
Comment on lines +182 to +188
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image the icon appears really off here?

}
}

Spacer(modifier = Modifier.height(16.dp))
ScoringSummary(gameCard.scoreEvent)
} else {
Expand All @@ -190,15 +209,15 @@ fun GameDetailsContent(gameCard: DetailsCardData) {

Spacer(modifier = Modifier.weight(1f))

ButtonPrimary(
"Add to Calendar",
painterResource(R.drawable.ic_calendar),
onClick = {
gameCard.toCalendarEvent()?.let { event ->
addToCalendar(context = context, event)
}
}
)
// ButtonPrimary(
// "Add to Calendar",
// painterResource(R.drawable.ic_calendar),
// onClick = {
// gameCard.toCalendarEvent()?.let { event ->
// addToCalendar(context = context, event)
// }
// }
// )
}

}
Expand Down Expand Up @@ -301,6 +320,6 @@ private fun GameDetailsPreview() {
hoursUntilGame = 144,
homeScore = 78,
oppScore = 75
)
), navigateToGameScoreSummary = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import com.cornellappdev.score.R
import com.cornellappdev.score.components.NavigationHeader
import com.cornellappdev.score.components.ScorePreview
import com.cornellappdev.score.model.ScoreEvent
import com.cornellappdev.score.theme.Style.bodyNormal
import com.cornellappdev.score.theme.Style.spanBodyNormal
import com.cornellappdev.score.theme.White
import com.cornellappdev.score.util.scoreEvents2
import androidx.compose.foundation.layout.fillMaxSize
import coil3.compose.AsyncImage

@Composable
fun GameScoreSummaryScreenDetail(scoreEvents: List<ScoreEvent>) {
fun GameScoreSummaryScreenDetail(scoreEvents: List<ScoreEvent>, onBackArrow: () -> Unit) {
Column(modifier = Modifier.fillMaxSize()) {
// TODO: add navigation
NavigationHeader(title = "Scoring Summary", {})
NavigationHeader(title = "Scoring Summary", onBackArrow)
LazyColumn(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -59,11 +58,21 @@ fun ScoreEventItemDetailed(event: ScoreEvent) {
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween
) {
AsyncImage(
model = event.team.logo,
contentDescription = event.team.name,
modifier = Modifier.size(40.dp)
)
if (event.team.name == "COR") {
Image(
painter = painterResource(R.drawable.cornell_logo),
contentDescription = event.team.name,
modifier = Modifier
.size(40.dp)
.padding(end = 12.dp)
)
} else {
AsyncImage(
model = event.team.logo,
contentDescription = event.team.name,
modifier = Modifier.size(40.dp)
)
}
Spacer(modifier = Modifier.width(8.dp))
Column(
modifier = Modifier
Expand Down Expand Up @@ -113,5 +122,5 @@ fun ScoreEventItemDetailed(event: ScoreEvent) {
@Preview
@Composable
private fun PreviewScoringDetailsScreen() = ScorePreview {
GameScoreSummaryScreenDetail(scoreEvents = scoreEvents2)
GameScoreSummaryScreenDetail(scoreEvents = scoreEvents2, onBackArrow = {})
}