Skip to content

Commit 356fd00

Browse files
committed
Fix missing team ID bug
1 parent 09c16f2 commit 356fd00

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/EventView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ fun EventView(eventViewModel: EventViewModel = viewModel(), navController: NavCo
251251
horizontalArrangement = Arrangement.SpaceBetween,
252252
verticalAlignment = Alignment.CenterVertically,
253253
modifier = Modifier.clickable {
254+
println("Team ID: ${team.id}, Number: ${team.number}")
254255
navController.navigate(
255256
EventTeamMatchesViewDestination(eventViewModel.event, team)
256257
)

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/RoboScoutAPI.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class RoboScoutAPI {
165165
var regionsMap: MutableMap<String, Int> = mutableMapOf<String, Int>()
166166
var importedWS: Boolean = false
167167
var importedVDA: Boolean = false
168-
var seasonIdMap: List<MutableList<Season>> = listOf()
168+
var seasonsCache: List<MutableList<Season>> = listOf()
169169
var selectedSeasonId: Int = BuildConfig.DEFAULT_V5_SEASON_ID
170170
var gradeLevel: String = "High School"
171171

@@ -300,7 +300,7 @@ class RoboScoutAPI {
300300
6 -> params["level_class_id"] = 13
301301
}
302302

303-
val competition = if (API.seasonIdMap[0].find { it.id == params["seasonId"]} != null) "vex-robotics-competition" else "college-competition"
303+
val competition = if (API.seasonsCache[0].find { it.id == params["seasonId"]} != null) "vex-robotics-competition" else "college-competition"
304304

305305
val requestUrl = "https://www.robotevents.com/robot-competitions/$competition"
306306

@@ -340,20 +340,20 @@ class RoboScoutAPI {
340340
}
341341
}
342342

343-
suspend fun generateSeasonIdMap() {
344-
this.seasonIdMap = listOf(mutableListOf(), mutableListOf())
343+
suspend fun generateseasonsCache() {
344+
this.seasonsCache = listOf(mutableListOf(), mutableListOf())
345345
val data = roboteventsRequest("/seasons/")
346346

347347
for (seasonData in data) {
348348
val season = jsonWorker.decodeFromJsonElement<Season>(seasonData)
349349
val gradeLevelIndex = if (season.program.id == 1) 0 else if (season.program.id == 4) 1 else -1
350350
if (gradeLevelIndex != -1) {
351-
this.seasonIdMap[gradeLevelIndex].add(season)
351+
this.seasonsCache[gradeLevelIndex].add(season)
352352
}
353353
}
354354

355355
println("Season ID map generated")
356-
/*for (gradeLevel in this.seasonIdMap) {
356+
/*for (gradeLevel in this.seasonsCache) {
357357
for (season in gradeLevel) {
358358
println("ID: ${season.id}, Name: ${season.name}")
359359
}
@@ -369,18 +369,18 @@ class RoboScoutAPI {
369369
}
370370

371371
fun activeSeasonId(): Int {
372-
return if (this.seasonIdMap.isNotEmpty()) {
372+
return if (this.seasonsCache.isNotEmpty()) {
373373
if (this.gradeLevel != "College") {
374374
try {
375-
this.seasonIdMap[0].first().id
375+
this.seasonsCache[0].first().id
376376
}
377377
catch (e: NoSuchElementException) {
378378
BuildConfig.DEFAULT_V5_SEASON_ID
379379
}
380380
}
381381
else {
382382
try {
383-
this.seasonIdMap[1].first().id
383+
this.seasonsCache[1].first().id
384384
}
385385
catch (e: NoSuchElementException) {
386386
BuildConfig.DEFAULT_VU_SEASON_ID
@@ -477,8 +477,8 @@ class RoboScoutAPI {
477477
var totalAP = 0
478478
var totalWP = 0
479479

480-
val seasonIndex = API.seasonIdMap[if (API.selectedProgramId() == 4) 1 else 0].indexOfFirst { it.id == API.selectedSeasonId() }
481-
val season = API.seasonIdMap[if (team.grade == "College") 1 else 0][seasonIndex]
480+
val seasonIndex = API.seasonsCache[if (API.selectedProgramId() == 4) 1 else 0].indexOfFirst { it.id == API.selectedSeasonId() }
481+
val season = API.seasonsCache[if (team.grade == "College") 1 else 0][seasonIndex]
482482

483483
val reRankingsData = roboteventsRequest("/teams/${team.id}/rankings", mapOf("season" to season.id))
484484
val reRankings = reRankingsData.map { jsonWorker.decodeFromJsonElement<TeamRanking>(it) }
@@ -1122,8 +1122,8 @@ class Team : MutableState<Team> {
11221122
suspend fun fetchEvents(season: Int? = null) {
11231123
val data: List<JsonObject>
11241124
if (season == null) {
1125-
val seasonIndex = API.seasonIdMap[if (API.selectedProgramId() == 4) 1 else 0].indexOfFirst { it.id == API.selectedSeasonId() }
1126-
data = RoboScoutAPI.roboteventsRequest("/events", mapOf("team" to id, "season" to (API.seasonIdMap[if (this.grade == "College") 1 else 0][seasonIndex].id)))
1125+
val seasonIndex = API.seasonsCache[if (API.selectedProgramId() == 4) 1 else 0].indexOfFirst { it.id == API.selectedSeasonId() }
1126+
data = RoboScoutAPI.roboteventsRequest("/events", mapOf("team" to id, "season" to (API.seasonsCache[if (this.grade == "College") 1 else 0][seasonIndex].id)))
11271127
}
11281128
else {
11291129
data = RoboScoutAPI.roboteventsRequest("/events", mapOf("team" to id, "season" to season))

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/RootActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ class RootActivity : ComponentActivity() {
349349
) {
350350

351351
LaunchedEffect(Unit) {
352-
if (API.seasonIdMap.isEmpty()) {
352+
if (API.seasonsCache.isEmpty()) {
353353
CoroutineScope(Dispatchers.Default).launch {
354-
API.generateSeasonIdMap()
354+
API.generateseasonsCache()
355355
}
356356
}
357357
if (!API.importedWS) {

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/SettingsView.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,25 @@ fun SettingsView(navController: NavController) {
181181
userSettings.setGradeLevel(gradeLevelMap.entries.first { entry -> entry.value == it }.key)
182182
selectedGradeLevel = userSettings.getGradeLevel()
183183
val seasonIndex =
184-
API.seasonIdMap[if (prevGradeLevel == "College") 1 else 0].indexOfFirst { it.id == userSettings.getSelectedSeasonId() }
184+
API.seasonsCache[if (prevGradeLevel == "College") 1 else 0].indexOfFirst { it.id == userSettings.getSelectedSeasonId() }
185185
if (seasonIndex == -1) {
186186
userSettings.setSelectedSeasonId(if (selectedGradeLevel == "College") BuildConfig.DEFAULT_VU_SEASON_ID else BuildConfig.DEFAULT_V5_SEASON_ID)
187187
} else {
188-
userSettings.setSelectedSeasonId(API.seasonIdMap[if (selectedGradeLevel == "College") 1 else 0][seasonIndex].id)
188+
userSettings.setSelectedSeasonId(API.seasonsCache[if (selectedGradeLevel == "College") 1 else 0][seasonIndex].id)
189189
}
190190
API.importedWS = false
191191
CoroutineScope(Dispatchers.Default).launch {
192192
API.updateWorldSkillsCache()
193193
}
194194
},
195-
modifier = Modifier.padding(10.dp)
195+
modifier = Modifier.padding(7.dp)
196196
) {
197197
SegmentText(
198198
text = it
199199
)
200200
}
201201
}
202-
if (API.seasonIdMap[0].isNotEmpty()) {
202+
if (API.seasonsCache[0].isNotEmpty()) {
203203
HorizontalDivider(
204204
thickness = 0.5.dp,
205205
color = MaterialTheme.colorScheme.secondary.copy(alpha = 0.1f),
@@ -215,7 +215,7 @@ fun SettingsView(navController: NavController) {
215215
expanded = expanded,
216216
onDismissRequest = { expanded = false }
217217
) {
218-
API.seasonIdMap[if (userSettings.getGradeLevel() != "College") 0 else 1].forEach { entry ->
218+
API.seasonsCache[if (userSettings.getGradeLevel() != "College") 0 else 1].forEach { entry ->
219219
DropdownMenuItem(
220220
text = {
221221
Text(
@@ -234,7 +234,7 @@ fun SettingsView(navController: NavController) {
234234
}
235235
}
236236
Text(
237-
(API.seasonIdMap[0] + API.seasonIdMap[1]).first { it.id == API.selectedSeasonId() }.shortName,
237+
(API.seasonsCache[0] + API.seasonsCache[1]).first { it.id == API.selectedSeasonId() }.shortName,
238238
color = MaterialTheme.colorScheme.button,
239239
modifier = Modifier.clickable {
240240
expanded = !expanded

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/TeamEventsView.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import kotlinx.coroutines.withContext
4343

4444
class TeamEventsViewModel: ViewModel() {
4545
var events by mutableStateOf(listOf<Event>())
46+
var team by mutableStateOf(Team())
4647
var loading by mutableStateOf(true)
4748
}
4849

@@ -63,6 +64,7 @@ fun TeamEventsView(teamEventsViewModel: TeamEventsViewModel = viewModel(), navCo
6364
withContext(Dispatchers.Main) {
6465
teamEventsViewModel.loading = false
6566
teamEventsViewModel.events = team.events
67+
teamEventsViewModel.team = team
6668
}
6769
}
6870
}
@@ -75,7 +77,7 @@ fun TeamEventsView(teamEventsViewModel: TeamEventsViewModel = viewModel(), navCo
7577
titleContentColor = MaterialTheme.colorScheme.onTopContainer,
7678
),
7779
title = {
78-
Text("${team.number} Events", fontWeight = FontWeight.Bold)
80+
Text("${teamEventsViewModel.team.number} Events", fontWeight = FontWeight.Bold)
7981
},
8082
navigationIcon = {
8183
Icon(
@@ -121,7 +123,7 @@ fun TeamEventsView(teamEventsViewModel: TeamEventsViewModel = viewModel(), navCo
121123
Row(
122124
verticalAlignment = Alignment.CenterVertically
123125
) {
124-
EventRow(navController, event, team)
126+
EventRow(navController, event, teamEventsViewModel.team)
125127
}
126128
if (teamEventsViewModel.events.indexOf(event) != 0) {
127129
HorizontalDivider(

0 commit comments

Comments
 (0)