Skip to content

Commit bc8c875

Browse files
authored
Fixed BaseBall Scoring and IsLive (#102)
* git issue fix * advanced fitler first iteration * center icon * google-services.json * fix scrollable * pagination * changes for baseball scores * Delete app/src/google-services.json
1 parent 254d1c7 commit bc8c875

5 files changed

Lines changed: 38 additions & 15 deletions

File tree

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (secretsPropertiesFile.exists()) {
1111
plugins {
1212
alias(libs.plugins.androidApplication)
1313
alias(libs.plugins.jetbrainsKotlinAndroid) version "1.9.10"
14-
alias(libs.plugins.apollo)
14+
id("com.apollographql.apollo") version "4.0.0"
1515
id("kotlin-kapt")
1616
id("com.google.dagger.hilt.android")
1717
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" // this version matches your Kotlin version
@@ -97,7 +97,7 @@ dependencies {
9797
androidTestImplementation(libs.androidx.junit)
9898
androidTestImplementation(libs.androidx.espresso.core)
9999
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
100-
implementation(libs.apollo.runtime)
100+
implementation("com.apollographql.apollo:apollo-runtime:4.0.0")
101101
implementation("io.coil-kt.coil3:coil-compose:3.1.0")
102102
implementation("io.coil-kt.coil3:coil-network-okhttp:3.1.0")
103103
lintChecks(libs.compose.lint.checks)

app/src/main/graphql/Games.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ query Games{
22
games{
33
id
44
date
5+
time
56
city
67
sport
78
team{

app/src/main/java/com/cornellappdev/score/model/Game.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ data class Game(
2020
val id: String,
2121
val teamName: String,
2222
val teamLogo: String,
23+
val time: String?,
2324
val teamColor: Color,
2425
val gender: String,
2526
val sport: String,
@@ -146,7 +147,7 @@ data class TeamScore(
146147
// Aggregated game data showing scores for both teams
147148
data class GameData(
148149
val teamScores: Pair<TeamScore, TeamScore>
149-
){
150+
) {
150151
val maxPeriods: Int
151152
get() =
152153
maxOf(
@@ -250,7 +251,11 @@ fun Game.toGameCardData(): GameCardData {
250251
date = parseDateOrNull(date),
251252
dateString = parseDateOrNull(date)?.format(outputFormatter)
252253
?: date,
253-
isLive = (LocalDate.now() == parseDateOrNull(date)),
254+
isLive = parseDateTimeOrNull(date, time ?: "")?.let { startTime ->
255+
val now = LocalDateTime.now()
256+
val endTime = startTime.plusHours(2)
257+
now.isAfter(startTime) && now.isBefore(endTime)
258+
} ?: false,
254259
isPast = isPast,
255260
location = city,
256261
gender = gender,
@@ -290,14 +295,15 @@ fun GameDetailsGame.toGameCardData(): DetailsCardData {
290295
scoreBreakdown = scoreBreakdown,
291296
team1 = TeamBoxScore("Cornell"),
292297
team2 = TeamBoxScore(team?.name ?: ""),
293-
sport = sport
298+
sport = sport,
299+
result = result ?: ""
294300
),
295301
scoreEvent = boxScore?.toScoreEvents(team?.image ?: "") ?: emptyList(),
296302
daysUntilGame = daysUntil,
297303
hoursUntilGame = hoursUntil,
298-
homeScore = convertScores(scoreBreakdown?.getOrNull(0), sport).second
304+
homeScore = convertScores(scoreBreakdown?.getOrNull(0), sport, result ?: "").second
299305
?: parsedScores?.first ?: 0,
300-
oppScore = convertScores(scoreBreakdown?.getOrNull(1), sport).second
306+
oppScore = convertScores(scoreBreakdown?.getOrNull(1), sport, result ?: "").second
301307
?: parsedScores?.second ?: 0
302308
)
303309
}

app/src/main/java/com/cornellappdev/score/model/ScoreRepository.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.util.Log
44
import com.apollographql.apollo.ApolloClient
55
import com.cornellappdev.score.util.isValidSport
66
import com.cornellappdev.score.util.parseColor
7+
import com.cornellappdev.score.util.parseResultScore
78
import com.example.score.GameByIdQuery
89
import com.example.score.GamesQuery
910
import com.example.score.PagedGamesQuery
@@ -75,6 +76,7 @@ class ScoreRepository @Inject constructor(
7576
id = game.id ?: "", // Should never be null
7677
teamLogo = it,
7778
teamName = game.team.name,
79+
time = game.time,
7880
teamColor = parseColor(game.team.color).copy(alpha = 0.4f * 255),
7981
gender = if (game.gender == "Mens") "Men's" else "Women's",
8082
sport = game.sport,
@@ -133,11 +135,15 @@ class ScoreRepository @Inject constructor(
133135
.mapNotNull { graphqlGame ->
134136
val scores = graphqlGame.result?.split(",")?.getOrNull(1)?.split("-")
135137
val cornellScore = scores?.getOrNull(0)?.toNumberOrNull()
136-
val otherScore = scores?.getOrNull(1)?.toNumberOrNull()
138+
?: parseResultScore(graphqlGame.result)?.first
139+
val otherScore = scores?.getOrNull(1)?.toNumberOrNull() ?: parseResultScore(
140+
graphqlGame.result
141+
)?.second
137142
graphqlGame.team?.image?.let { imageUrl ->
138143
Game(
139144
id = graphqlGame.id ?: "",
140145
teamLogo = imageUrl,
146+
time = graphqlGame.time,
141147
teamName = graphqlGame.team.name,
142148
teamColor = parseColor(graphqlGame.team.color).copy(alpha = 0.4f * 255),
143149
gender = if (graphqlGame.gender == "Mens") "Men's" else "Women's",
@@ -171,6 +177,7 @@ class ScoreRepository @Inject constructor(
171177
* `currentGamesFlow` to be observed.
172178
*/
173179
fun getGameById(id: String) = appScope.launch {
180+
Log.d("ScoreRepository", "Fetching game with id: $id")
174181
_currentGameFlow.value = ApiResponse.Loading
175182
try {
176183
val result =
@@ -181,6 +188,7 @@ class ScoreRepository @Inject constructor(
181188

182189
result.getOrNull()?.game?.let {
183190
_currentGameFlow.value = ApiResponse.Success(it.toGameDetails())
191+
184192
} ?: _currentGameFlow.update { ApiResponse.Error }
185193
} catch (e: Exception) {
186194
Log.e("ScoreRepository", "Error fetching game with id: ${id}: ", e)

app/src/main/java/com/cornellappdev/score/util/GameDataUtil.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cornellappdev.score.util
22

3+
import android.util.Log
34
import com.cornellappdev.score.model.GameData
45
import com.cornellappdev.score.model.TeamBoxScore
56
import com.cornellappdev.score.model.TeamScore
@@ -17,7 +18,7 @@ import com.cornellappdev.score.model.TeamScore
1718
* @return a pair where the first value is a list of parsed period scores and the second is the total score (or null if invalid)
1819
*/
1920
// TODO: ASK ABOUT OT. Other sports might be added.
20-
fun convertScores(scoreList: List<String?>?, sport: String): Pair<List<Int>, Int?> {
21+
fun convertScores(scoreList: List<String?>?, sport: String, result: String): Pair<List<Int>, Int?> {
2122
if (scoreList == null || scoreList.size < 2) return Pair(emptyList(), null)
2223

2324
var scoresByPeriod = scoreList
@@ -31,7 +32,12 @@ fun convertScores(scoreList: List<String?>?, sport: String): Pair<List<Int>, Int
3132
}
3233

3334
if (sport.lowercase() == "baseball") {
34-
scoresByPeriod = scoresByPeriod.take(9)
35+
val scoreParsed = result.split("(")
36+
scoresByPeriod = if (scoreParsed.size > 1) {
37+
scoresByPeriod.take(6)
38+
} else {
39+
scoresByPeriod.take(9)
40+
}
3541
val totalScore = scoresByPeriod.sum()
3642
return Pair(scoresByPeriod, totalScore)
3743
}
@@ -56,14 +62,15 @@ fun toGameData(
5662
scoreBreakdown: List<List<String?>?>?,
5763
team1: TeamBoxScore,
5864
team2: TeamBoxScore,
59-
sport: String
65+
sport: String,
66+
result: String,
6067
): GameData {
6168
val (team1Scores, team1Total) = scoreBreakdown?.getOrNull(0)?.let {
62-
convertScores(it, sport)
69+
convertScores(it, sport, result)
6370
} ?: (emptyList<Int>() to null)
6471

6572
val (team2Scores, team2Total) = scoreBreakdown?.getOrNull(1)?.let {
66-
convertScores(it, sport)
73+
convertScores(it, sport, result)
6774
} ?: (emptyList<Int>() to null)
6875

6976
val team1Score =
@@ -90,11 +97,12 @@ fun parseResultScore(result: String?): Pair<Int, Int>? {
9097
if (parts.size != 2) return null
9198

9299
val scorePart = parts[1].split("-")
100+
val secondScorePartEdge = scorePart[1].split("(")
93101
if (scorePart.size != 2) return null
94102

95103
val homeScore = scorePart[0].toIntOrNull()
96-
val oppScore = scorePart[1].toIntOrNull()
97-
104+
val oppScore = secondScorePartEdge[0].toIntOrNull()
105+
Log.d("HIHI", oppScore.toString())
98106
if (homeScore != null && oppScore != null) {
99107
return Pair(homeScore, oppScore)
100108
} else {

0 commit comments

Comments
 (0)