near final

This commit is contained in:
ImBenji
2024-03-02 18:07:05 +00:00
parent 67e1cd3530
commit 429eb4ad5f
29 changed files with 7870 additions and 1345 deletions

View File

@@ -1,11 +1,15 @@
import 'dart:async';
import 'package:bus_infotainment/pages/components/ibus_display.dart';
import 'package:bus_infotainment/singletons/live_information.dart';
import 'package:bus_infotainment/backend/live_information.dart';
import 'package:bus_infotainment/tfl_datasets.dart';
import 'package:bus_infotainment/utils/OrdinanceSurveyUtils.dart';
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
import 'package:bus_infotainment/utils/delegates.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_fonts/google_fonts.dart';
class pages_Home extends StatelessWidget {
@@ -18,226 +22,343 @@ class pages_Home extends StatelessWidget {
child: SingleChildScrollView(
child: Column(
children: [
Container(
height: 2,
color: Colors.white70,
),
Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 2,
spreadRadius: 4
)
]
),
margin: EdgeInsets.all(20),
child: ibus_display(),
),
Container(
height: 2,
color: Colors.white70,
),
Container(
margin: EdgeInsets.all(20),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 2,
spreadRadius: 4
)
]
),
child: ManualAnnouncementPicker(
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
announcements: [
...LiveInformation().manualAnnouncements
],
),
),
),
Container(
height: 2,
color: Colors.white70,
),
Container(
margin: EdgeInsets.all(20),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 2,
spreadRadius: 4
)
]
),
child: DelegateBuilder<BusRouteVariant>(
delegate: LiveInformation().routeVariantDelegate,
builder: (context, routeVariant) {
print("rebuilt stop announcement picker");
return StopAnnouncementPicker(
routeVariant: routeVariant,
child: Column(
children: [
Row(
children: [
Speedometer(),
],
),
Container(
height: 2,
color: Colors.white70,
),
SingleChildScrollView(
child: Column(
children: [
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: AnnouncementPicker(
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
},
defaultBuilder: (context) {
BusRouteVariant? routeVariant = LiveInformation().getRouteVariant();
if (routeVariant == null) {
return Container(
color: Colors.grey.shade900,
child: Center(
child: Text(
"No route selected",
style: GoogleFonts.teko(
fontSize: 25,
color: Colors.white70
),
),
),
);
} else {
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
}
},
announcements: [
for (NamedAnnouncementQueueEntry announcement in LiveInformation().announcementModule.manualAnnouncements)
_AnnouncementEntry(
label: announcement.shortName,
index: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
outlineColor: Colors.white70,
onPressed: (){
LiveInformation liveInformation = LiveInformation();
liveInformation.announcementModule.queueAnnounementByInfoIndex(
infoIndex: liveInformation.announcementModule.manualAnnouncements.indexOf(announcement),
sendToServer: true
);
},
)
],
),
),
),
),
Container(
height: 2,
color: Colors.white70,
),
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: DelegateBuilder<BusRouteVariant>(
delegate: LiveInformation().routeVariantDelegate,
builder: (context, routeVariant) {
print("rebuilt stop announcement picker");
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
},
defaultBuilder: (context) {
BusRouteVariant? routeVariant = LiveInformation().getRouteVariant();
if (routeVariant == null) {
return Container(
color: Colors.grey.shade900,
child: Center(
child: Text(
"No route selected",
style: GoogleFonts.teko(
fontSize: 25,
color: Colors.white70
),
),
),
);
} else {
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
}
},
),
),
),
ElevatedButton(
onPressed: () async {
LiveInformation liveInformation = LiveInformation();
final commandModule = liveInformation.commandModule;
// commandModule.executeCommand(
// "announce dest"
// );
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
routeVariant: liveInformation.getRouteVariant()!
);
},
child: Text("Announce current destination"),
),
// Container(
//
// margin: EdgeInsets.all(20),
//
// height: 300-45,
//
// child: ListView(
//
// scrollDirection: Axis.vertical,
//
// children: [
//
// ElevatedButton(
// onPressed: () async {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: false));
// },
// child: Text("Test announcement"),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.updateServer();
// },
// child: Text("Update server"),
// ),
//
// SizedBox(
//
// width: 100,
//
// child: TextField(
// onChanged: (String value) {
// LiveInformation liveInformation = LiveInformation();
// // liveInformation.documentID = value;
// },
// ),
// ),
//
// SizedBox(
//
// width: 200,
//
// child: TextField(
// onSubmitted: (String value) {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(AnnouncementQueueEntry(
// displayText: value,
// audioSources: []
// ));
// },
// ),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.pullServer();
// },
// child: Text("Pull server"),
// ),
//
// ],
//
// ),
//
// ),
],
),
ElevatedButton(
onPressed: () async {
LiveInformation liveInformation = LiveInformation();
liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: true));
},
child: Text("Announce Destination"),
),
// Container(
//
// margin: EdgeInsets.all(20),
//
// height: 300-45,
//
// child: ListView(
//
// scrollDirection: Axis.vertical,
//
// children: [
//
// ElevatedButton(
// onPressed: () async {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: false));
// },
// child: Text("Test announcement"),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.updateServer();
// },
// child: Text("Update server"),
// ),
//
// SizedBox(
//
// width: 100,
//
// child: TextField(
// onChanged: (String value) {
// LiveInformation liveInformation = LiveInformation();
// // liveInformation.documentID = value;
// },
// ),
// ),
//
// SizedBox(
//
// width: 200,
//
// child: TextField(
// onSubmitted: (String value) {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(AnnouncementQueueEntry(
// displayText: value,
// audioSources: []
// ));
// },
// ),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.pullServer();
// },
// child: Text("Pull server"),
// ),
//
// ],
//
// ),
//
// ),
],
),
),
],
)
);
}
}
class ManualAnnouncementPicker extends StatefulWidget {
class Speedometer extends StatefulWidget {
@override
State<Speedometer> createState() => _SpeedometerState();
}
class _SpeedometerState extends State<Speedometer> {
double speed = 0;
double arrivalTime = 0;
BusRouteStop? nearestStop;
double speed2 = 0;
_SpeedometerState(){
}
@override
void initState() {
// TODO: implement initState
super.initState();
Timer.periodic(Duration(milliseconds: 250), (timer) {
Position? newPosition = LiveInformation().trackerModule.position;
speed = newPosition?.speed ?? 0;
arrivalTime -= 0.25;
arrivalTime = arrivalTime < 0 ? 0 : arrivalTime;
setState(() {
});
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
margin: EdgeInsets.all(8),
height: 74,
child: Row(
children: [
Container(
// width: 60,
height: double.infinity,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: Colors.white70,
width: 2
)
),
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.white70,
width: 2
)
),
width: 30,
height: 30,
alignment: Alignment.center,
child: Text(
"${((speed) * 2.237).toInt()}",
style: GoogleFonts.teko(
fontSize: 20,
color: Colors.white70,
height: 1
),
)
),
const SizedBox(
height: 4,
),
Text(
"MPH",
style: GoogleFonts.teko(
fontSize: 20,
color: Colors.white70,
height: 1
),
),
],
),
),
],
),
);
}
}
class AnnouncementPicker extends StatefulWidget {
final Color backgroundColor;
final Color outlineColor;
final List<NamedAnnouncementQueueEntry> announcements;
final List<Widget> announcements;
const ManualAnnouncementPicker({super.key, required this.backgroundColor, required this.outlineColor, required this.announcements});
const AnnouncementPicker({super.key, required this.backgroundColor, required this.outlineColor, required this.announcements});
@override
State<ManualAnnouncementPicker> createState() => _ManualAnnouncementPickerState();
State<AnnouncementPicker> createState() => _AnnouncementPickerState();
}
class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
class _AnnouncementPickerState extends State<AnnouncementPicker> {
List<Widget> announcementWidgets = [];
@@ -255,13 +376,9 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
}
int i = 0;
for (NamedAnnouncementQueueEntry announcement in widget.announcements!) {
for (Widget announcement in widget.announcements!) {
announcementWidgets.add(
_ManualAnnouncementEntry(
announcement: announcement,
index: i,
outlineColor: Colors.white70
)
announcement
);
i++;
}
@@ -436,7 +553,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length);
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
@@ -489,7 +606,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
Positioned.fill(
child: ElevatedButton(
onPressed: () {
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length);
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length, increment: 4);
setState(() {});
print(_currentIndex);
},
@@ -529,7 +646,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
}
}
class StopAnnouncementPicker extends ManualAnnouncementPicker {
class StopAnnouncementPicker extends AnnouncementPicker {
final BusRouteVariant routeVariant;
StopAnnouncementPicker({
@@ -542,29 +659,52 @@ class StopAnnouncementPicker extends ManualAnnouncementPicker {
backgroundColor: backgroundColor,
outlineColor: outlineColor,
announcements: [
for (BusRouteStops stop in routeVariant.busStops)
ManualAnnouncementEntry(
shortName: stop.formattedStopName,
informationText: stop.formattedStopName,
audioFileNames: [
stop.getAudioFileName()
]
for (BusRouteStop stop in routeVariant.busStops)
_AnnouncementEntry(
label: stop.formattedStopName,
onPressed: () {
LiveInformation liveInformation = LiveInformation();
liveInformation.announcementModule.queueAnnounceByAudioName(
displayText: stop.formattedStopName,
audioNames: [stop.getAudioFileName()],
);
},
index: routeVariant.busStops.indexOf(stop),
outlineColor: outlineColor,
alert: LiveInformation().announcementModule.announcementCache[stop.getAudioFileName()] == null,
)
]
);
}
int wrap(int i, int j, int length) {
return ((i - j) % length + length) % length;
int wrap(int i, int j, int length, {int increment = -1}) {
if (increment == -1) {
return ((i - j) % length + length) % length;
} else {
if (i >= length) {
return 0;
} else if (i < 0) {
double d = length / increment;
int n = d.toInt();
return (n-1) * increment;
} else {
return i;
}
}
}
class _ManualAnnouncementEntry extends StatelessWidget {
class _AnnouncementEntry extends StatelessWidget {
final NamedAnnouncementQueueEntry announcement;
final String label;
final Function onPressed;
final int index;
final Color outlineColor;
_ManualAnnouncementEntry({super.key, required this.announcement, required this.index, required this.outlineColor});
bool alert = false;
_AnnouncementEntry({super.key, required this.label, required this.onPressed, required this.index, required this.outlineColor, this.alert = false});
@override
Widget build(BuildContext context) {
@@ -591,35 +731,60 @@ class _ManualAnnouncementEntry extends StatelessWidget {
width: double.infinity,
child: Transform.translate(
child: Row(
children: [
Row(
children: [
Container(
offset: Offset(0, 4),
child: Row(
children: [
Text(
announcement.shortName,
style: GoogleFonts.teko(
fontSize: 25,
color: outlineColor,
)
),
Expanded(
child: Container(
alignment: Alignment.centerRight,
constraints: const BoxConstraints(
maxWidth: 260
),
child: Text(
(index+1).toString(),
label,
style: GoogleFonts.teko(
fontSize: 25,
color: outlineColor,
)
),
overflow: TextOverflow.ellipsis,
),
),
)
],
),
if (alert)
const SizedBox(
width: 4,
),
if (alert)
Icon(
Icons.error,
color: Colors.red.shade800,
size: 25,
shadows: const [
Shadow(
color: Colors.black,
blurRadius: 2,
)
],
)
],
),
Expanded(
child: Container(
alignment: Alignment.centerRight,
child: Text(
(index+1).toString(),
style: GoogleFonts.teko(
fontSize: 25,
color: outlineColor,
)
),
),
)
],
)
),
@@ -627,8 +792,7 @@ class _ManualAnnouncementEntry extends StatelessWidget {
Positioned.fill(
child: ElevatedButton(
onPressed: () {
LiveInformation liveInformation = LiveInformation();
liveInformation.queueAnnouncement(announcement);
onPressed();
},
style: ElevatedButton.styleFrom(