@@ -50,11 +50,113 @@ class EventDivisionMatchesViewModel: ViewModel() {
50
50
var division by mutableStateOf(Division ())
51
51
}
52
52
53
+ @Composable
54
+ fun MatchesView (matchList : List <Match >) {
55
+ val timeFormat = java.text.SimpleDateFormat (" h:mm a" , java.util.Locale .getDefault())
56
+ Column (
57
+ modifier = Modifier .verticalScroll(rememberScrollState())
58
+ ) {
59
+ Card (
60
+ modifier = Modifier .padding(10 .dp),
61
+ colors = CardColors (
62
+ containerColor = MaterialTheme .colorScheme.surfaceContainer.copy(alpha = 0.5f ),
63
+ disabledContainerColor = Color .Unspecified .copy(alpha = 0.5f ),
64
+ contentColor = MaterialTheme .colorScheme.onSurface,
65
+ disabledContentColor = Color .Unspecified
66
+ )
67
+ ) {
68
+ Column (
69
+ modifier = Modifier .padding(horizontal = 5 .dp, vertical = 0 .dp)
70
+ ) {
71
+ (matchList).forEach { match ->
72
+ Row (
73
+ verticalAlignment = Alignment .CenterVertically
74
+ ) {
75
+ Column (
76
+ modifier = Modifier .width(65 .dp),
77
+ verticalArrangement = Arrangement .spacedBy((- 3 ).dp)
78
+ ) {
79
+ Text (
80
+ text = match.shortName,
81
+ fontSize = 16 .sp,
82
+ fontWeight = FontWeight .Bold ,
83
+ color = MaterialTheme .colorScheme.onSurface
84
+ )
85
+ Text (
86
+ text = match.startedDate?.let { timeFormat.format(it) }
87
+ ? : match.scheduledDate?.let { timeFormat.format(it) }
88
+ ? : " " ,
89
+ fontSize = 12 .sp,
90
+ color = MaterialTheme .colorScheme.onSurface
91
+ )
92
+ }
93
+ Spacer (modifier = Modifier .width(10 .dp))
94
+ Row (
95
+ verticalAlignment = Alignment .CenterVertically
96
+ ) {
97
+ Column (
98
+ horizontalAlignment = Alignment .CenterHorizontally ,
99
+ modifier = Modifier .width(60 .dp),
100
+ verticalArrangement = Arrangement .spacedBy((- 5 ).dp)
101
+ ) {
102
+ match.redAlliance.members.forEach{ member ->
103
+ Text (
104
+ text = member.team.name,
105
+ fontSize = 15 .sp,
106
+ color = allianceRed
107
+ )
108
+ }
109
+ }
110
+ Spacer (modifier = Modifier .width(20 .dp))
111
+ Text (
112
+ match.redScore.toString(),
113
+ fontSize = 18 .sp,
114
+ fontWeight = FontWeight .Bold ,
115
+ color = allianceRed,
116
+ textAlign = TextAlign .Start ,
117
+ modifier = Modifier .width(50 .dp)
118
+ )
119
+ Spacer (modifier = Modifier .weight(1f ))
120
+ Text (
121
+ match.blueScore.toString(),
122
+ fontSize = 18 .sp,
123
+ fontWeight = FontWeight .Bold ,
124
+ color = allianceBlue,
125
+ textAlign = TextAlign .End ,
126
+ modifier = Modifier .width(50 .dp)
127
+ )
128
+ Spacer (modifier = Modifier .width(20 .dp))
129
+ Column (
130
+ horizontalAlignment = Alignment .CenterHorizontally ,
131
+ modifier = Modifier .width(60 .dp),
132
+ verticalArrangement = Arrangement .spacedBy((- 5 ).dp)
133
+ ) {
134
+ match.blueAlliance.members.forEach{ member ->
135
+ Text (
136
+ text = member.team.name,
137
+ fontSize = 15 .sp,
138
+ color = allianceBlue
139
+ )
140
+ }
141
+ }
142
+ }
143
+ }
144
+ if (match != matchList.last()) {
145
+ HorizontalDivider (
146
+ thickness = 0.5 .dp,
147
+ color = MaterialTheme .colorScheme.secondary.copy(alpha = 0.1f ),
148
+ )
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
53
156
@OptIn(ExperimentalMaterial3Api ::class )
54
157
@Destination
55
158
@Composable
56
159
fun EventDivisionMatchesView (event : Event , division : Division , eventDivisionMatchesViewModel : EventDivisionMatchesViewModel = viewModel(), navController : NavController ) {
57
- val timeFormat = java.text.SimpleDateFormat (" h:mm a" , java.util.Locale .getDefault())
58
160
59
161
var loading by remember { mutableStateOf(event.matches[division] == null ) }
60
162
@@ -113,108 +215,11 @@ fun EventDivisionMatchesView(event: Event, division: Division, eventDivisionMatc
113
215
if (loading) {
114
216
LoadingView ()
115
217
}
116
- else if ((event.matches[division] ? : listOf ()).isEmpty()) {
218
+ else if ((event.matches[division] ? : emptyList ()).isEmpty()) {
117
219
NoDataView ()
118
220
}
119
221
else {
120
- Column (
121
- modifier = Modifier .verticalScroll(rememberScrollState())
122
- ) {
123
- Card (
124
- modifier = Modifier .padding(10 .dp),
125
- colors = CardColors (
126
- containerColor = MaterialTheme .colorScheme.surfaceContainer.copy(alpha = 0.5f ),
127
- disabledContainerColor = Color .Unspecified .copy(alpha = 0.5f ),
128
- contentColor = MaterialTheme .colorScheme.onSurface,
129
- disabledContentColor = Color .Unspecified
130
- )
131
- ) {
132
- Column (
133
- modifier = Modifier .padding(horizontal = 5 .dp, vertical = 0 .dp)
134
- ) {
135
- (event.matches[division] ? : emptyList()).forEach { match ->
136
- Row (
137
- verticalAlignment = Alignment .CenterVertically
138
- ) {
139
- Column (
140
- modifier = Modifier .width(65 .dp),
141
- verticalArrangement = Arrangement .spacedBy((- 3 ).dp)
142
- ) {
143
- Text (
144
- text = match.shortName,
145
- fontSize = 16 .sp,
146
- fontWeight = FontWeight .Bold ,
147
- color = MaterialTheme .colorScheme.onSurface
148
- )
149
- Text (
150
- text = match.startedDate?.let { timeFormat.format(it) }
151
- ? : match.scheduledDate?.let { timeFormat.format(it) }
152
- ? : " " ,
153
- fontSize = 12 .sp,
154
- color = MaterialTheme .colorScheme.onSurface
155
- )
156
- }
157
- Spacer (modifier = Modifier .width(10 .dp))
158
- Row (
159
- verticalAlignment = Alignment .CenterVertically
160
- ) {
161
- Column (
162
- horizontalAlignment = Alignment .CenterHorizontally ,
163
- modifier = Modifier .width(60 .dp),
164
- verticalArrangement = Arrangement .spacedBy((- 5 ).dp)
165
- ) {
166
- match.redAlliance.members.forEach{ member ->
167
- Text (
168
- text = member.team.name,
169
- fontSize = 15 .sp,
170
- color = allianceRed
171
- )
172
- }
173
- }
174
- Spacer (modifier = Modifier .width(20 .dp))
175
- Text (
176
- match.redScore.toString(),
177
- fontSize = 18 .sp,
178
- fontWeight = FontWeight .Bold ,
179
- color = allianceRed,
180
- textAlign = TextAlign .Start ,
181
- modifier = Modifier .width(50 .dp)
182
- )
183
- Spacer (modifier = Modifier .weight(1f ))
184
- Text (
185
- match.blueScore.toString(),
186
- fontSize = 18 .sp,
187
- fontWeight = FontWeight .Bold ,
188
- color = allianceBlue,
189
- textAlign = TextAlign .End ,
190
- modifier = Modifier .width(50 .dp)
191
- )
192
- Spacer (modifier = Modifier .width(20 .dp))
193
- Column (
194
- horizontalAlignment = Alignment .CenterHorizontally ,
195
- modifier = Modifier .width(60 .dp),
196
- verticalArrangement = Arrangement .spacedBy((- 5 ).dp)
197
- ) {
198
- match.blueAlliance.members.forEach{ member ->
199
- Text (
200
- text = member.team.name,
201
- fontSize = 15 .sp,
202
- color = allianceBlue
203
- )
204
- }
205
- }
206
- }
207
- }
208
- if (match != event.matches[division]?.last()) {
209
- HorizontalDivider (
210
- thickness = 0.5 .dp,
211
- color = MaterialTheme .colorScheme.secondary.copy(alpha = 0.1f ),
212
- )
213
- }
214
- }
215
- }
216
- }
217
- }
222
+ MatchesView (event.matches[division] ? : emptyList())
218
223
}
219
224
}
220
225
}
0 commit comments