Skip to content

Commit 95fcfe3

Browse files
committed
change top color if they are teammate
1 parent 285ff4e commit 95fcfe3

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

lib/builders/PlatformRoute.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,24 @@ class PlatformRoute extends StatefulWidget {
2020

2121
class _PlatformRouteState extends State<PlatformRoute> {
2222
final scaffoldKey = GlobalKey<ScaffoldState>();
23+
Color appBarColor = AppStyle.textInputColor;
24+
25+
@override
26+
void initState() {
27+
super.initState();
28+
_loadColor();
29+
}
30+
31+
void _loadColor() async {
32+
appBarColor = await UIHelper.getAppBarColour();
33+
setState(() {
34+
appBarColor = appBarColor;
35+
});
36+
}
37+
2338
@override
2439
Widget build(BuildContext context) {
40+
2541
return PopScope(
2642
canPop: false,
2743
child: Scaffold(
@@ -31,7 +47,7 @@ class _PlatformRouteState extends State<PlatformRoute> {
3147
appBar: PreferredSize(
3248
preferredSize: const Size.fromHeight(40.0),
3349
child: AppBar(
34-
backgroundColor: AppStyle.textInputColor,
50+
backgroundColor: appBarColor,
3551
title: Text(
3652
widget.title,
3753
textAlign: TextAlign.center,

lib/routes/prematch/fields/PrematchFields.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class _PrematchFieldsState extends State<PrematchFields> {
124124
PrematchValues.teamNumber.text = teamNumber.toString();
125125
});
126126
});
127+
Schedulehelper.getSimbotMatches(); // does nothing with the value because this code computes the list too
127128
}
128129
}
129130
},

lib/utils/helpers/QRCodeHelper.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:scouting_platform/utils/data/values/EndgameValues.dart';
99
import 'package:scouting_platform/utils/data/values/PrematchValues.dart';
1010
import 'package:scouting_platform/utils/data/values/SettingValues.dart';
1111
import 'package:scouting_platform/utils/data/values/TeleoperatedValues.dart';
12-
import 'package:scouting_platform/utils/helpers/AppDataHelper.dart';
1312

1413
class QrcodeHelper {
1514
/// Returns a string that represents the contents of the QR code that will be generated and separates them with a "^" character
@@ -29,7 +28,7 @@ class QrcodeHelper {
2928
// Encode to UTF-8 and then base64 to compress size and reduce issues with characters
3029
List<int> utf8Encoded = utf8.encode(computedValues);
3130

32-
AppDataHelper.saveQRCodeCopy(computedValues);
31+
// AppDataHelper.saveQRCodeCopy(computedValues);
3332

3433
return base64.encode(utf8Encoded);
3534
}

lib/utils/helpers/ScheduleHelper.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import 'dart:io';
44

55
import 'package:permission_handler/permission_handler.dart';
66
import 'package:scouting_platform/utils/data/constants/AppConstants.dart';
7+
import 'package:scouting_platform/utils/data/values/PrematchValues.dart';
78
import 'package:scouting_platform/utils/data/values/SettingValues.dart';
89

910
class Schedulehelper {
1011
static late int argumentReadingIndex;
1112
static late int driverStationIdentifier;
13+
static List<String> simbotMatches = [];
1214

1315
static Future<String> get _scheduleDirecotyPath async {
1416
final directory = Directory('/storage/emulated/0/Documents');
@@ -53,6 +55,56 @@ class Schedulehelper {
5355
return null;
5456
}
5557

58+
static Future<int> getNumberOfLinesInSchedule() async {
59+
final file = File(
60+
"/storage/emulated/0/Documents/match_schedule_${SettingValues.eventID.text}.csv");
61+
62+
if (await file.exists()) {
63+
final lines = await file.readAsLines();
64+
return lines.length - 1;
65+
}
66+
return 0;
67+
}
68+
69+
static Future<List<String>> getSimbotMatches() async {
70+
simbotMatches.clear();
71+
for (var i = 0; i < await getNumberOfLinesInSchedule(); i++) {
72+
String? matchData = await readLineFromSchedule(i);
73+
if (matchData == null) {
74+
break;
75+
}
76+
if (matchData.contains("1114")) {
77+
simbotMatches.add(matchData);
78+
}
79+
}
80+
return simbotMatches;
81+
}
82+
83+
static Future<bool> isTeamInUpcomingMatches(int teamNumber) async {
84+
if (PrematchValues.matchNumber.text.isEmpty) {
85+
return false;
86+
}
87+
88+
List<String> simbotMatches = await getSimbotMatches();
89+
for (String simbotMatch in simbotMatches) {
90+
List<String> simbotMatchData = simbotMatch.split(",");
91+
String matchNumber = simbotMatchData[0];
92+
simbotMatchData.removeAt(0);
93+
int teamIndex = simbotMatchData.indexOf(teamNumber.toString());
94+
int simbotIndex = simbotMatchData.indexOf("1114");
95+
96+
bool teamAlliance = teamIndex < 2 && teamIndex != -1;
97+
bool simbotAlliance = simbotIndex < 2 && simbotIndex != -1;
98+
99+
if (int.parse(matchNumber) >
100+
int.parse(PrematchValues.matchNumber.text) + 1 &&
101+
teamAlliance == simbotAlliance) {
102+
return true;
103+
}
104+
}
105+
return false;
106+
}
107+
56108
static Future<int> getTeamNumberFromSchedule(int matchNumber) async {
57109
switch (SettingValues.selectedDriverStation.text) {
58110
case "Red 1":

lib/utils/helpers/UIHelper.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import 'dart:ui';
33

44
import 'package:scouting_platform/styles/AppStyle.dart';
5+
import 'package:scouting_platform/utils/data/values/PrematchValues.dart';
56
import 'package:scouting_platform/utils/data/values/SettingValues.dart';
7+
import 'package:scouting_platform/utils/helpers/ScheduleHelper.dart';
68
import 'package:screen_brightness/screen_brightness.dart';
79

810
class UIHelper {
@@ -15,6 +17,18 @@ class UIHelper {
1517
}
1618
}
1719

20+
static Future<Color> getAppBarColour() async {
21+
try {
22+
if(await Schedulehelper.isTeamInUpcomingMatches(int.parse(PrematchValues.teamNumber.text))) {
23+
return Color.from(alpha: 1, red: 0, green: 0.5, blue: 0);
24+
} else {
25+
return AppStyle.textInputColor;
26+
}
27+
} catch (FormatException) {
28+
return AppStyle.textInputColor;
29+
}
30+
}
31+
1832
// Sets the brightness of the screen
1933
static Future<void> setBrightness(double brightness) async {
2034
try {

0 commit comments

Comments
 (0)