Skip to content

Commit 61318fd

Browse files
committed
Add match outcome coloring in MatchesView for teams
1 parent 7f24682 commit 61318fd

File tree

1 file changed

+25
-1
lines changed
  • app/src/main/java/com/sunkensplashstudios/VRCRoboScout/helperviews

1 file changed

+25
-1
lines changed

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/helperviews/MatchesView.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,38 @@ import androidx.compose.ui.text.style.TextDecoration
2323
import androidx.compose.ui.text.style.TextOverflow
2424
import androidx.compose.ui.unit.dp
2525
import androidx.compose.ui.unit.sp
26+
import com.sunkensplashstudios.VRCRoboScout.AllianceColor
2627
import com.sunkensplashstudios.VRCRoboScout.Match
2728
import com.sunkensplashstudios.VRCRoboScout.Team
2829
import com.sunkensplashstudios.VRCRoboScout.ui.theme.allianceBlue
2930
import com.sunkensplashstudios.VRCRoboScout.ui.theme.allianceRed
3031

3132
@Composable
3233
fun MatchesView(matchList: List<Match>, team: Team? = null) {
34+
3335
val timeFormat = java.text.SimpleDateFormat("h:mm a", java.util.Locale.getDefault())
36+
37+
fun determineColor(match: Match, team: Team?, defaultColor: Color): Color {
38+
if (match.completed()) {
39+
return if (team != null) {
40+
if (match.winningAlliance() == null) {
41+
Color.Yellow
42+
} else if (match.winningAlliance() == AllianceColor.RED && match.redAlliance.members.find { member -> member.team.id == team.id } != null) {
43+
Color.Green
44+
} else if (match.winningAlliance() == AllianceColor.BLUE && match.blueAlliance.members.find { member -> member.team.id == team.id } != null) {
45+
Color.Green
46+
} else {
47+
Color.Red
48+
}
49+
} else {
50+
defaultColor
51+
}
52+
}
53+
else {
54+
return defaultColor
55+
}
56+
}
57+
3458
Column(
3559
modifier = Modifier.verticalScroll(rememberScrollState())
3660
) {
@@ -58,7 +82,7 @@ fun MatchesView(matchList: List<Match>, team: Team? = null) {
5882
text = match.shortName,
5983
fontSize = 16.sp,
6084
fontWeight = FontWeight.Bold,
61-
color = MaterialTheme.colorScheme.onSurface
85+
color = determineColor(match, team, MaterialTheme.colorScheme.onSurface)
6286
)
6387
Text(
6488
text = match.startedDate?.let { timeFormat.format(it) }

0 commit comments

Comments
 (0)