Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
32 changes: 32 additions & 0 deletions app/src/main/graphql/GameById.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
query GameById($id: String!) {
game(id: $id){
id
city
date
gender
location
opponentId
result
sport
state
time
scoreBreakdown
team {
id
color
image
name
}
boxScore {
team
period
time
description
scorer
assist
scoreBy
corScore
oppScore
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
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.theme.Style.scoreHeaderText
import com.cornellappdev.score.theme.Style.vsText

@Composable
fun GameScoreHeader(
leftTeamLogo: Painter,
rightTeamLogo: Painter,
rightTeamLogo: String,
gradientColor1: Color,
gradientColor2: Color,
leftScore: Int,
rightScore: Int,
modifier: Modifier = Modifier
) {
Box(
Expand All @@ -64,7 +67,7 @@ fun GameScoreHeader(

Row {
Text(
text = "0",
text = leftScore.toString(),
style = scoreHeaderText,
modifier = Modifier.width(52.dp),
textAlign = TextAlign.Center
Expand All @@ -76,15 +79,15 @@ fun GameScoreHeader(
)

Text(
text = "0",
text = rightScore.toString(),
style = scoreHeaderText,
modifier = Modifier.width(52.dp),
textAlign = TextAlign.Center
)
}

Image(
painter = rightTeamLogo,
AsyncImage(
model = rightTeamLogo,
contentDescription = "Right Team Logo",
modifier = Modifier.height(70.dp)
)
Expand All @@ -97,9 +100,11 @@ fun GameScoreHeader(
private fun GameScoreHeaderPreview() {
GameScoreHeader(
leftTeamLogo = painterResource(R.drawable.cornell_logo),
rightTeamLogo = painterResource(R.drawable.penn_logo),
rightTeamLogo = "https://images.sidearmdev.com/fit?url=https%3a%2f%2fdxbhsrqyrr690.cloudfront.net%2fsidearm.nextgen.sites%2fcornellbigred.com%2fimages%2flogos%2fpenn_200x200.png&height=80&width=80&type=webp",
gradientColor1 = Color(0xFFE1A69F),
gradientColor2 = Color(0xFF011F5B),
leftScore = 0,
rightScore = 0,
modifier = Modifier.height(185.dp)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
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.model.ScoreEvent
import com.cornellappdev.score.theme.GrayPrimary
import com.cornellappdev.score.theme.Style.bodyMedium
Expand Down Expand Up @@ -47,13 +49,25 @@ fun ScoreEventItem(event: ScoreEvent) {
.padding(vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = painterResource(event.team.logo),
contentDescription = event.team.name,
modifier = Modifier
.size(40.dp)
.padding(end = 12.dp)
)
if (event.team.name == "COR"){ // TODO: Check if its "COR" for all queries. It is for baseball
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, // Turn this into a if statement if i know the link for cornell logo
modifier = Modifier
.size(40.dp)
.padding(end = 12.dp)
)
}


Row(
modifier = Modifier.weight(2f),
Expand Down Expand Up @@ -91,7 +105,7 @@ fun ScoreEventItem(event: ScoreEvent) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = homeScore.toString(),
style = if (event.team.name == "Cornell") metricSemibold else metricNormal,
style = if (event.team.name == "Cornell") metricSemibold else metricNormal, // TODO: Check name
color = GrayPrimary,
textAlign = TextAlign.Center
)
Expand Down
122 changes: 116 additions & 6 deletions app/src/main/java/com/cornellappdev/score/model/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package com.cornellappdev.score.model

import androidx.compose.ui.graphics.Color
import com.cornellappdev.score.R
import com.cornellappdev.score.util.formatDateTimeDisplay
import com.cornellappdev.score.util.outputFormatter
import com.cornellappdev.score.util.parseColor
import com.cornellappdev.score.util.parseDateOrNull
import com.cornellappdev.score.util.parseDateTimeOrNull
import com.cornellappdev.score.util.toGameData
import java.time.LocalDate
import java.time.LocalDateTime

// TODO Refactor to make easier to filter... actual gender, etc.

Expand All @@ -18,7 +23,44 @@ data class Game(
val city: String
)

//Data for HomeScreen game displays
data class GameDetailsTeam(
val id: String?,
val color: Color,
val image: String?,
val name: String
)

data class GameDetailsBoxScore(
val team: String?,
val period: String?,
val time: String?,
val description: String?,
val scorer: String?,
val assist: String?,
val scoreBy: String?,
val corScore: Int?,
val oppScore: Int?
)

data class GameDetailsGame(
val id: String?,
val city: String,
val date: String,
val gender: String,
val location: String?,
val opponentId: String,
val result: String?,
val sport: String,
val state: String,
val time: String?,
val scoreBreakdown: List<List<String?>?>?,
val team: GameDetailsTeam?,
val boxScore: List<GameDetailsBoxScore>?
)



// Data for HomeScreen game displays
data class GameCardData(
val teamLogo: String,
val team: String,
Expand All @@ -33,9 +75,31 @@ data class GameCardData(
val sportIcon: Int
)

// Data for GameDetailsScreen
data class DetailsCardData(
val title: String,
val opponentLogo: String,
val opponent: String,
val opponentColor: Color,
val date: LocalDate?,
val time: String,
val dateString: String,
val isPastStartTime: Boolean,
val location: String,
val locationString: String,
val gender: String,
val genderIcon: Int,
val sport: String,
val sportIcon: Int,
val boxScore: List<GameDetailsBoxScore?>,
val scoreBreakdown: List<List<String?>?>?,
val gameData: GameData,
val scoreEvent:List<ScoreEvent>
)

// Scoring information for a specific team, used in the box score
data class TeamScore(
val team: Team,
val team: TeamBoxScore,
val scoresByPeriod: List<Int>,
val totalScore: Int
)
Expand All @@ -60,7 +124,7 @@ data class ScoreEvent(
val id: Int,
val time: String,
val quarter: String,
val team: Team,
val team: TeamGameSummary,
val eventType: String,
val score: String,
val description: String? = null
Expand All @@ -70,11 +134,13 @@ data class ScoreEvent(
val awayScore get() = scoreTuple[1]
}

data class Team(
data class TeamBoxScore(
val name: String
)
data class TeamGameSummary(
val name: String,
val logo: Int
val logo: String
)

data class GameSummary(
val gameData: GameData,
val scoreEvents: List<ScoreEvent>
Expand Down Expand Up @@ -119,4 +185,48 @@ fun Game.toGameCardData(): GameCardData{
sportIcon = Sport.fromDisplayName(sport)?.emptyIcon
?: R.drawable.ic_empty_placeholder
)
}

fun GameDetailsGame.toGameCardData(): DetailsCardData{
return DetailsCardData(
title = "Cornell Vs. ${team?.name ?: ""}",
opponentLogo = team?.image ?: "",
opponent = team?.name ?: "",
opponentColor = team?.color ?: Color.White,
date = parseDateOrNull(date),
time = time ?: "",
dateString = formatDateTimeDisplay(date, time ?: ""),
isPastStartTime = parseDateTimeOrNull(date, time ?: "")?.let {
!LocalDateTime.now().isBefore(it)
} ?: false,
location = city,
locationString = "${city}, ${state}",
gender = gender,
genderIcon = if (gender == "Mens") R.drawable.ic_gender_men else R.drawable.ic_gender_women,
sport = sport,
sportIcon = Sport.fromDisplayName(sport)?.emptyIcon
?: R.drawable.ic_empty_placeholder,
boxScore = boxScore ?: emptyList(),
scoreBreakdown = scoreBreakdown ?: emptyList(),
gameData = toGameData(scoreBreakdown = scoreBreakdown, team1 = TeamBoxScore("Cornell", ), team2 = TeamBoxScore(team?.name ?: "")),
scoreEvent = boxScore?.toScoreEvents(team?.image ?: "") ?: emptyList()
)
}

fun List<GameDetailsBoxScore>.toScoreEvents(teamLogo: String): List<ScoreEvent> {
return this.mapIndexed { index, boxScore ->
val teamName = boxScore.team ?: ""
val corScore = boxScore.corScore ?: 0
val oppScore = boxScore.oppScore ?: 0

ScoreEvent(
id = index,
time = boxScore.time ?: "",
quarter = boxScore.period ?: "",
team = TeamGameSummary(teamName, logo = teamLogo),
eventType = "Score", // TODO: Change to what ios has and not figma
score = "$corScore - $oppScore",
description = boxScore.description
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.cornellappdev.score.model

import com.cornellappdev.score.util.parseColor
import com.example.score.GameByIdQuery

fun GameByIdQuery.Game.toGameDetails(): GameDetailsGame {
return GameDetailsGame(
id = this.id ?: "",
city = this.city,
date = this.date,
gender = this.gender,
location = this.location,
opponentId = this.opponentId,
result = this.result,
sport = this.sport,
state = this.state,
time = this.time,
scoreBreakdown = this.scoreBreakdown,
team = this.team?.toGameDetailsTeam(),
boxScore = this.boxScore?.mapNotNull { it?.toGameDetailsBoxScore() }
)
}
fun GameByIdQuery.Team.toGameDetailsTeam(): GameDetailsTeam {
return GameDetailsTeam(
id = this.id,
color = parseColor(this.color).copy(alpha = 0.4f*255),
image = this.image,
name = this.name
)
}

fun GameByIdQuery.BoxScore.toGameDetailsBoxScore(): GameDetailsBoxScore {
return GameDetailsBoxScore(
team = this.team,
period = this.period,
time = this.time,
description = this.description,
scorer = this.scorer,
assist = this.assist,
scoreBy = this.scoreBy,
corScore = this.corScore,
oppScore = this.oppScore
)
}

Loading