Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/src/main/graphql/GameById.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ query GameById($id: String!) {
corScore
oppScore
}
ticketLink
}
}
11 changes: 7 additions & 4 deletions app/src/main/java/com/cornellappdev/score/model/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ data class GameDetailsGame(
val time: String?,
val scoreBreakdown: List<List<String?>?>?,
val team: GameDetailsTeam?,
val boxScore: List<GameDetailsBoxScore>?
val boxScore: List<GameDetailsBoxScore>?,
val ticketUrl: String?
)


Expand Down Expand Up @@ -126,7 +127,8 @@ data class DetailsCardData(
val daysUntilGame: Int?,
val hoursUntilGame: Int?,
val homeScore: Int,
val oppScore: Int
val oppScore: Int,
val ticketUrl: String?
)

// Scoring information by round of a game, used in the box score
Expand All @@ -146,7 +148,7 @@ data class TeamScore(
// Aggregated game data showing scores for both teams
data class GameData(
val teamScores: Pair<TeamScore, TeamScore>
){
) {
val maxPeriods: Int
get() =
maxOf(
Expand Down Expand Up @@ -298,7 +300,8 @@ fun GameDetailsGame.toGameCardData(): DetailsCardData {
homeScore = convertScores(scoreBreakdown?.getOrNull(0), sport).second
?: parsedScores?.first ?: 0,
oppScore = convertScores(scoreBreakdown?.getOrNull(1), sport).second
?: parsedScores?.second ?: 0
?: parsedScores?.second ?: 0,
ticketUrl = ticketUrl ?: ""
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ fun GameByIdQuery.Game.toGameDetails(): GameDetailsGame {
time = this.time,
scoreBreakdown = this.scoreBreakdown,
team = this.team?.toGameDetailsTeam(),
boxScore = this.boxScore?.mapNotNull { it?.toGameDetailsBoxScore() }
boxScore = this.boxScore?.mapNotNull { it?.toGameDetailsBoxScore() },
ticketUrl = ticketLink
)
}

fun GameByIdQuery.Team.toGameDetailsTeam(): GameDetailsTeam {
return GameDetailsTeam(
id = this.id,
color = parseColor(this.color).copy(alpha = 0.4f*255),
color = parseColor(this.color).copy(alpha = 0.4f * 255),
image = this.image,
name = this.name
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.cornellappdev.score.screen

import ScoringSummary
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.CalendarContract
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
Expand Down Expand Up @@ -31,6 +36,7 @@ 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.EmptyStateBox
import com.cornellappdev.score.components.ErrorState
import com.cornellappdev.score.components.GameDetailsLoadingScreen
Expand All @@ -55,6 +61,10 @@ import com.cornellappdev.score.theme.Style.heading3
import com.cornellappdev.score.theme.White
import com.cornellappdev.score.viewmodel.GameDetailsViewModel
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Locale

@Composable
fun GameDetailsScreen(
Expand Down Expand Up @@ -220,16 +230,26 @@ fun GameDetailsContent(
}

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

// ButtonPrimary(
// "Add to Calendar",
// painterResource(R.drawable.ic_calendar),
// onClick = {
// gameCard.toCalendarEvent()?.let { event ->
// addToCalendar(context = context, event)
// }
// }
// )
Row() {
ButtonPrimary(
"Buy Tickets",
painterResource(R.drawable.ticket),
onClick = {
gameCard.ticketUrl?.let { url ->
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
}
}
)
Spacer(Modifier.size(16.dp))
ButtonPrimary(
"Add to Calendar",
painterResource(R.drawable.ic_calendar),
onClick = {
addGameToCalendar(context, gameCard)
}
)
}
}

}
Expand Down Expand Up @@ -331,7 +351,8 @@ private fun GameDetailsPreview() {
daysUntilGame = 6,
hoursUntilGame = 144,
homeScore = 78,
oppScore = 75
oppScore = 75,
ticketUrl = ""
), navigateToGameScoreSummary = {}
)
}
Expand Down Expand Up @@ -382,7 +403,37 @@ private fun EmptyGameDetailsPreview() {
daysUntilGame = 0,
hoursUntilGame = 0,
homeScore = 0,
oppScore = 0
), navigateToGameScoreSummary = {}
oppScore = 0,
ticketUrl = ""
),
navigateToGameScoreSummary = {},
)
}

// helper
fun addGameToCalendar(context: Context, gameCard: DetailsCardData) {
val date = gameCard.date ?: return
val time = gameCard.time

val startDateTime = try {
val formatter = DateTimeFormatter.ofPattern("h:mm a", Locale.ENGLISH)
val localTime = LocalTime.parse(time.trim().uppercase().replace(".", ""), formatter)
date.atTime(localTime)
} catch (e: Exception) {
Log.e("Calendar", "Failed to parse time: '$time'", e)
date.atStartOfDay()
}

val zoneId = ZoneId.systemDefault()
val startMillis = startDateTime.atZone(zoneId).toInstant().toEpochMilli()
val endMillis = startDateTime.plusHours(2).atZone(zoneId).toInstant().toEpochMilli()

val intent = Intent(Intent.ACTION_INSERT, CalendarContract.Events.CONTENT_URI).apply {
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startMillis)
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endMillis)
putExtra(CalendarContract.Events.TITLE, gameCard.title)
putExtra(CalendarContract.Events.EVENT_LOCATION, gameCard.locationString)
putExtra(CalendarContract.Events.DESCRIPTION, "${gameCard.sport} - ${gameCard.gender}")
}
context.startActivity(intent)
}
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/ticket.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M14.551,0.866L0.862,14.677L3.307,17.122C6.362,16.266 7.218,17.977 6.362,20.299L9.051,22.866L22.74,9.055L20.296,6.611C17.167,7.491 16.792,4.777 16.996,3.311L14.551,0.866Z"
android:strokeWidth="1.22222"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
<path
android:pathData="M10.151,5.266L11.129,6.244M12.229,7.344L13.696,8.811M14.918,10.033L16.262,11.377M17.485,12.599L18.34,13.455"
android:strokeWidth="1.22222"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
</vector>
Loading