near final
This commit is contained in:
@@ -33,4 +33,7 @@
|
|||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
5164
assets/datasets/bus-blinds.csv
Normal file
5164
assets/datasets/bus-blinds.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -13,8 +13,15 @@ class AudioCache {
|
|||||||
return _audioCache.keys.toList();
|
return _audioCache.keys.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8List operator [](String key) {
|
Uint8List? operator [](String key) {
|
||||||
return _audioCache[key]!;
|
// ignore case
|
||||||
|
key = key.toLowerCase();
|
||||||
|
for (var k in _audioCache.keys) {
|
||||||
|
if (k.toLowerCase() == key) {
|
||||||
|
return _audioCache[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +29,21 @@ class AnnouncementCache extends AudioCache {
|
|||||||
|
|
||||||
String _assetLocation = "assets/ibus_recordings.zip";
|
String _assetLocation = "assets/ibus_recordings.zip";
|
||||||
|
|
||||||
Future<void> loadAnnouncements(List<String> Announcements) async {
|
Future<void> loadAnnouncements(List<String> announcements) async {
|
||||||
|
|
||||||
|
List<String> _announements = [];
|
||||||
|
|
||||||
|
|
||||||
|
// remove any announcements that are already loaded
|
||||||
|
for (var announcement in announcements) {
|
||||||
|
if (!_audioCache.containsKey(announcement.toLowerCase())) {
|
||||||
|
_announements.add(announcement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_announements.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final bytes = await rootBundle.load(_assetLocation);
|
final bytes = await rootBundle.load(_assetLocation);
|
||||||
final archive = ZipDecoder().decodeBytes(bytes.buffer.asUint8List());
|
final archive = ZipDecoder().decodeBytes(bytes.buffer.asUint8List());
|
||||||
@@ -34,9 +55,9 @@ class AnnouncementCache extends AudioCache {
|
|||||||
filename = filename.split("/").last;
|
filename = filename.split("/").last;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Announcements.contains(filename)) {
|
if (_announements.contains(filename)) {
|
||||||
_audioCache[filename] = file.content;
|
_audioCache[filename.toLowerCase()] = file.content;
|
||||||
print("Loaded announcement: ${filename}");
|
print("Loaded announcement: $filename");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +83,7 @@ class AnnouncementCache extends AudioCache {
|
|||||||
filename = filename.split("/").last;
|
filename = filename.split("/").last;
|
||||||
}
|
}
|
||||||
|
|
||||||
_audioCache[filename] = file.content;
|
_audioCache[filename.toLowerCase()] = file.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Done loading all announcements.");
|
print("Done loading all announcements.");
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class ApiConstants {
|
|||||||
static const String MANUAL_Q_COLLECTION_ID = "65de9f2f925562a2eda8";
|
static const String MANUAL_Q_COLLECTION_ID = "65de9f2f925562a2eda8";
|
||||||
static const String INFORMATION_Q_COLLECTION_ID = "65de9f1b6282fd209bdb";
|
static const String INFORMATION_Q_COLLECTION_ID = "65de9f1b6282fd209bdb";
|
||||||
static const String DEST_Q_COLLECTION_ID = "65de9ef464bfa5a0693d";
|
static const String DEST_Q_COLLECTION_ID = "65de9ef464bfa5a0693d";
|
||||||
|
static const String COMMANDS_COLLECTION_ID = "65e035c82dbae432bafe";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
179
lib/backend/live_information.dart
Normal file
179
lib/backend/live_information.dart
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
|
||||||
|
// Singleton
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:appwrite/appwrite.dart' as appwrite;
|
||||||
|
import 'package:appwrite/models.dart' as models;
|
||||||
|
import 'package:bus_infotainment/audio_cache.dart';
|
||||||
|
import 'package:bus_infotainment/auth/api_constants.dart';
|
||||||
|
import 'package:bus_infotainment/auth/auth_api.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/announcement.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/commands.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/synced_time.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/tracker.dart';
|
||||||
|
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||||
|
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
||||||
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:ntp/ntp.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
|
class LiveInformation {
|
||||||
|
|
||||||
|
static final LiveInformation _singleton = LiveInformation._internal();
|
||||||
|
|
||||||
|
factory LiveInformation() {
|
||||||
|
return _singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveInformation._internal();
|
||||||
|
|
||||||
|
Future<void> initialize() async {
|
||||||
|
|
||||||
|
{
|
||||||
|
// By default, load the bus sequences from the assets
|
||||||
|
print("Loading bus sequences from assets");
|
||||||
|
busSequences = BusSequences.fromCSV(
|
||||||
|
await rootBundle.loadString("assets/datasets/bus-blinds.csv"),
|
||||||
|
await rootBundle.loadString("assets/datasets/bus-sequences.csv")
|
||||||
|
);
|
||||||
|
print("Loaded bus sequences from assets");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
http.Response response = await http.get(Uri.parse('https://tfl.gov.uk/bus-sequences.csv'));
|
||||||
|
|
||||||
|
busSequences = BusSequences.fromCSV(
|
||||||
|
await rootBundle.loadString("assets/datasets/bus-blinds.csv"),
|
||||||
|
response.body
|
||||||
|
);
|
||||||
|
|
||||||
|
print("Loaded bus sequences from TFL");
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
print("Failed to load bus sequences from TFL. Using local copy.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String sessionID = "test";
|
||||||
|
|
||||||
|
commandModule = CommandModule(sessionID);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise modules
|
||||||
|
syncedTimeModule = SyncedTimeModule();
|
||||||
|
announcementModule = AnnouncementModule();
|
||||||
|
|
||||||
|
// Tracker module is not supported on desktop
|
||||||
|
if (defaultTargetPlatform != TargetPlatform.windows || defaultTargetPlatform != TargetPlatform.linux || defaultTargetPlatform != TargetPlatform.macOS) {
|
||||||
|
// Tracker module is not supported on web
|
||||||
|
await Permission.location.request();
|
||||||
|
trackerModule = TrackerModule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth
|
||||||
|
AuthAPI auth = AuthAPI();
|
||||||
|
|
||||||
|
// Modules
|
||||||
|
late CommandModule commandModule;
|
||||||
|
late BusSequences busSequences;
|
||||||
|
late AnnouncementModule announcementModule;
|
||||||
|
late SyncedTimeModule syncedTimeModule;
|
||||||
|
late TrackerModule trackerModule;
|
||||||
|
|
||||||
|
// Important variables
|
||||||
|
BusRouteVariant? _currentRouteVariant;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
EventDelegate<BusRouteVariant> routeVariantDelegate = EventDelegate();
|
||||||
|
|
||||||
|
// Internal methods
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Future<void> setRouteVariant_Internal(BusRouteVariant routeVariant) async {
|
||||||
|
|
||||||
|
// Set the current route variant
|
||||||
|
_currentRouteVariant = routeVariant;
|
||||||
|
|
||||||
|
// Let everyone know that the route variant has been set/changed
|
||||||
|
routeVariantDelegate.trigger(routeVariant);
|
||||||
|
|
||||||
|
// Get all of the files that need to be cached
|
||||||
|
List<String> audioFiles = [];
|
||||||
|
|
||||||
|
for (BusRouteStop stop in routeVariant.busStops) {
|
||||||
|
audioFiles.add(stop.getAudioFileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache/Load the audio files
|
||||||
|
await announcementModule
|
||||||
|
.announcementCache
|
||||||
|
.loadAnnouncements(audioFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Public methods
|
||||||
|
|
||||||
|
BusRouteVariant? getRouteVariant() {
|
||||||
|
return _currentRouteVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setRouteVariant(BusRouteVariant routeVariant) async {
|
||||||
|
await commandModule.executeCommand(
|
||||||
|
"setroute ${routeVariant.busRoute.routeNumber} ${routeVariant.busRoute.routeVariants.values.toList().indexOf(routeVariant)}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Everything under this will be considered legacy code
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnnouncementQueueEntry {
|
||||||
|
final String displayText;
|
||||||
|
final List<AudioWrapperSource> audioSources;
|
||||||
|
bool sendToServer = true;
|
||||||
|
DateTime? scheduledTime;
|
||||||
|
DateTime? timestamp;
|
||||||
|
|
||||||
|
AnnouncementQueueEntry({required this.displayText, required this.audioSources, this.sendToServer = true, this.scheduledTime, this.timestamp});
|
||||||
|
}
|
||||||
|
|
||||||
|
class NamedAnnouncementQueueEntry extends AnnouncementQueueEntry {
|
||||||
|
final String shortName;
|
||||||
|
|
||||||
|
NamedAnnouncementQueueEntry({
|
||||||
|
required this.shortName,
|
||||||
|
required String displayText,
|
||||||
|
required List<AudioWrapperSource> audioSources,
|
||||||
|
DateTime? scheduledTime,
|
||||||
|
DateTime? timestamp,
|
||||||
|
bool sendToServer = true,
|
||||||
|
}) : super(
|
||||||
|
displayText: displayText,
|
||||||
|
audioSources: audioSources,
|
||||||
|
sendToServer: sendToServer,
|
||||||
|
scheduledTime: scheduledTime,
|
||||||
|
timestamp: timestamp,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var abs = (int value) => value < 0 ? -value : value;
|
||||||
330
lib/backend/modules/announcement.dart
Normal file
330
lib/backend/modules/announcement.dart
Normal file
@@ -0,0 +1,330 @@
|
|||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:bus_infotainment/audio_cache.dart';
|
||||||
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||||
|
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
||||||
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
|
|
||||||
|
import 'info_module.dart';
|
||||||
|
|
||||||
|
class AnnouncementModule extends InfoModule {
|
||||||
|
|
||||||
|
AnnouncementCache announcementCache = AnnouncementCache();
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
AnnouncementModule() {
|
||||||
|
refreshTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue
|
||||||
|
List<AnnouncementQueueEntry> queue = [];
|
||||||
|
AnnouncementQueueEntry? currentAnnouncement;
|
||||||
|
DateTime? currentAnnouncementTimeStamp;
|
||||||
|
String defaultText = "*** NO MESSAGE ***";
|
||||||
|
bool isPlaying = false;
|
||||||
|
|
||||||
|
// Audio
|
||||||
|
AudioWrapper audioPlayer = AudioWrapper();
|
||||||
|
|
||||||
|
// Events
|
||||||
|
final EventDelegate<AnnouncementQueueEntry> onAnnouncement = EventDelegate();
|
||||||
|
|
||||||
|
// Timer
|
||||||
|
Timer refreshTimer() => Timer.periodic(const Duration(milliseconds: 200), (timer) async {
|
||||||
|
|
||||||
|
if (!isPlaying) {
|
||||||
|
|
||||||
|
if (queue.isNotEmpty) {
|
||||||
|
isPlaying = true;
|
||||||
|
AnnouncementQueueEntry nextAnnouncement = queue.first;
|
||||||
|
|
||||||
|
bool proceeding = await _internalAccountForInconsistentTime(
|
||||||
|
announcement: nextAnnouncement,
|
||||||
|
timerInterval: const Duration(milliseconds: 200),
|
||||||
|
callback: () {
|
||||||
|
queue.removeAt(0);
|
||||||
|
print("Announcement proceeding");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!proceeding) {
|
||||||
|
isPlaying = false;
|
||||||
|
print("Announcement not proceeding");
|
||||||
|
print("Queue: ${queue.length}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentAnnouncement = nextAnnouncement;
|
||||||
|
currentAnnouncementTimeStamp = liveInformation.syncedTimeModule.Now();
|
||||||
|
|
||||||
|
onAnnouncement.trigger(currentAnnouncement!);
|
||||||
|
|
||||||
|
if (currentAnnouncement!.audioSources.isNotEmpty) {
|
||||||
|
try {
|
||||||
|
for (AudioWrapperSource source in currentAnnouncement!.audioSources) {
|
||||||
|
|
||||||
|
await audioPlayer.loadSource(source);
|
||||||
|
|
||||||
|
Duration? duration = await audioPlayer.play();
|
||||||
|
await Future.delayed(duration!);
|
||||||
|
if (currentAnnouncement?.audioSources.last != source) {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
audioPlayer.stop();
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
// Do nothing
|
||||||
|
print("Error playing announcement: $e");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (queue.isNotEmpty) {
|
||||||
|
await Future.delayed(const Duration(seconds: 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isPlaying = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Will call the callback function if the announcement will be proceeding
|
||||||
|
Future<bool> _internalAccountForInconsistentTime({
|
||||||
|
required AnnouncementQueueEntry announcement,
|
||||||
|
required Duration timerInterval,
|
||||||
|
required Function() callback
|
||||||
|
}) async {
|
||||||
|
DateTime now = liveInformation.syncedTimeModule.Now();
|
||||||
|
if (announcement.scheduledTime != null) {
|
||||||
|
|
||||||
|
if (now.isAfter(announcement.scheduledTime!)) {
|
||||||
|
callback();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int milisecondDifference = abs(now.millisecondsSinceEpoch - announcement.scheduledTime!.millisecondsSinceEpoch);
|
||||||
|
if (milisecondDifference <= timerInterval.inMilliseconds) {
|
||||||
|
// Account for the time lost by the periodic timer
|
||||||
|
callback();
|
||||||
|
await Future.delayed(Duration(milliseconds: timerInterval.inMilliseconds - milisecondDifference));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
int get defaultAnnouncementDelay => liveInformation.auth.isAuthenticated() ? 2 : 0;
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Future<void> queueAnnounceByAudioName({
|
||||||
|
required String displayText,
|
||||||
|
List<String> audioNames = const [],
|
||||||
|
DateTime? scheduledTime = null,
|
||||||
|
bool sendToServer = true
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
if (sendToServer) {
|
||||||
|
|
||||||
|
scheduledTime ??= liveInformation.syncedTimeModule.Now().add(Duration(seconds: defaultAnnouncementDelay));
|
||||||
|
|
||||||
|
String audioNamesString = "";
|
||||||
|
|
||||||
|
for (var audioName in audioNames) {
|
||||||
|
audioNamesString += "\"$audioName\" ";
|
||||||
|
}
|
||||||
|
|
||||||
|
liveInformation.commandModule.executeCommand(
|
||||||
|
"announce manual \"$displayText\" ${audioNamesString} ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache the announcements
|
||||||
|
await announcementCache.loadAnnouncements(audioNames);
|
||||||
|
|
||||||
|
List<AudioWrapperSource> sources = [];
|
||||||
|
|
||||||
|
print("Audio names: $audioNames");
|
||||||
|
|
||||||
|
for (var audioName in audioNames) {
|
||||||
|
Uint8List? audioData = announcementCache[audioName];
|
||||||
|
|
||||||
|
if (audioData == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sources.add(AudioWrapperByteSource(audioData));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.add(
|
||||||
|
AnnouncementQueueEntry(
|
||||||
|
displayText: displayText,
|
||||||
|
audioSources: sources,
|
||||||
|
scheduledTime: scheduledTime
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void queueAnnounementByInfoIndex({
|
||||||
|
int infoIndex = -1,
|
||||||
|
DateTime? scheduledTime = null,
|
||||||
|
bool sendToServer = true
|
||||||
|
}) {
|
||||||
|
|
||||||
|
if (sendToServer) {
|
||||||
|
|
||||||
|
scheduledTime ??= liveInformation.syncedTimeModule.Now().add(Duration(seconds: defaultAnnouncementDelay));
|
||||||
|
|
||||||
|
liveInformation.commandModule.executeCommand(
|
||||||
|
"announce info $infoIndex ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NamedAnnouncementQueueEntry clone = NamedAnnouncementQueueEntry(
|
||||||
|
shortName: manualAnnouncements[infoIndex].shortName,
|
||||||
|
displayText: manualAnnouncements[infoIndex].displayText,
|
||||||
|
audioSources: manualAnnouncements[infoIndex].audioSources,
|
||||||
|
scheduledTime: scheduledTime
|
||||||
|
);
|
||||||
|
|
||||||
|
queue.add(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> queueAnnouncementByRouteVariant({
|
||||||
|
required BusRouteVariant routeVariant,
|
||||||
|
DateTime? scheduledTime = null,
|
||||||
|
bool sendToServer = true
|
||||||
|
}) async {
|
||||||
|
|
||||||
|
if (sendToServer) {
|
||||||
|
|
||||||
|
scheduledTime ??= liveInformation.syncedTimeModule.Now().add(Duration(seconds: defaultAnnouncementDelay));
|
||||||
|
|
||||||
|
liveInformation.commandModule.executeCommand(
|
||||||
|
"announce dest \"${routeVariant.busRoute.routeNumber}\" ${routeVariant.busRoute.routeVariants.values.toList().indexOf(routeVariant)} ${scheduledTime?.millisecondsSinceEpoch ?? ""}"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String routeNumber = routeVariant.busRoute.routeNumber;
|
||||||
|
String destination = routeVariant.destination!.destination;
|
||||||
|
|
||||||
|
String audioRoute = "R_${routeVariant.busRoute.routeNumber}_001.mp3";
|
||||||
|
|
||||||
|
await announcementCache.loadAnnouncements([audioRoute]);
|
||||||
|
|
||||||
|
AudioWrapperSource sourceRoute = AudioWrapperByteSource(announcementCache[audioRoute]!);
|
||||||
|
AudioWrapperSource sourceDestination = AudioWrapperByteSource(await routeVariant.destination!.getAudioBytes());
|
||||||
|
|
||||||
|
AnnouncementQueueEntry announcement = AnnouncementQueueEntry(
|
||||||
|
displayText: "$routeNumber to $destination",
|
||||||
|
audioSources: [sourceRoute, AudioWrapperAssetSource("audio/to_destination.wav"), sourceDestination],
|
||||||
|
scheduledTime: scheduledTime
|
||||||
|
);
|
||||||
|
|
||||||
|
queue.add(announcement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
|
||||||
|
final List<NamedAnnouncementQueueEntry> manualAnnouncements = [
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Driver Change",
|
||||||
|
displayText: "Driver Change",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/driverchange.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "No Standing Upr Deck",
|
||||||
|
displayText: "No standing on the upper deck",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/nostanding.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Face Covering",
|
||||||
|
displayText: "Please wear a face covering!",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/facecovering.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Seats Upstairs",
|
||||||
|
displayText: "Seats are available upstairs",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/seatsupstairs.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Bus Terminates Here",
|
||||||
|
displayText: "Bus terminates here. Please take your belongings with you",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/busterminateshere.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Bus On Diversion",
|
||||||
|
displayText: "Bus on diversion. Please listen for further announcements",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/busondiversion.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Destination Change",
|
||||||
|
displayText: "Destination Changed - please listen for further instructions",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/destinationchange.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Wheelchair Space",
|
||||||
|
displayText: "Wheelchair space requested",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/wheelchairspace1.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Move Down The Bus",
|
||||||
|
displayText: "Please move down the bus",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/movedownthebus.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Next Stop Closed",
|
||||||
|
displayText: "The next bus stop is closed",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/nextstopclosed.wav")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "CCTV In Operation",
|
||||||
|
displayText: "CCTV is in operation on this bus",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/cctvoperation.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Safe Door Opening",
|
||||||
|
displayText: "Driver will open the doors when it is safe to do so",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/safedooropening.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Buggy Safety",
|
||||||
|
displayText: "For your child's safety, please remain with your buggy",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/buggysafety.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Wheelchair Space 2",
|
||||||
|
displayText: "Wheelchair priority space required",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/wheelchairspace2.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Service Regulation",
|
||||||
|
displayText: "Regulating service - please listen for further information",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/serviceregulation.mp3")],
|
||||||
|
),
|
||||||
|
NamedAnnouncementQueueEntry(
|
||||||
|
shortName: "Bus Ready To Depart",
|
||||||
|
displayText: "This bus is ready to depart",
|
||||||
|
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/readytodepart.mp3")],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
224
lib/backend/modules/commands.dart
Normal file
224
lib/backend/modules/commands.dart
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:bus_infotainment/auth/api_constants.dart';
|
||||||
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||||
|
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
||||||
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
|
import 'package:appwrite/appwrite.dart' as appwrite;
|
||||||
|
import 'package:appwrite/models.dart' as models;
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import '../../auth/auth_api.dart';
|
||||||
|
import 'info_module.dart';
|
||||||
|
|
||||||
|
class CommandModule extends InfoModule {
|
||||||
|
|
||||||
|
final String sessionID;
|
||||||
|
late final String clientID;
|
||||||
|
|
||||||
|
List<CommandInfo> _commandHistory = [];
|
||||||
|
get commandHistory => _commandHistory;
|
||||||
|
EventDelegate<CommandInfo> onCommandReceived = EventDelegate();
|
||||||
|
|
||||||
|
CommandModule(this.sessionID){
|
||||||
|
// generate a random client ID
|
||||||
|
var uuid = Uuid();
|
||||||
|
|
||||||
|
clientID = uuid.v4();
|
||||||
|
|
||||||
|
if (liveInformation.auth.isAuthenticated()){
|
||||||
|
print("Auth is authenticated");
|
||||||
|
_setupListener();
|
||||||
|
} else {
|
||||||
|
print("Auth is not authenticated");
|
||||||
|
liveInformation.auth.onLogin.addListener((value) {
|
||||||
|
_setupListener();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Will execute the command an event which is triggered when a response is received
|
||||||
|
Future<EventDelegate> executeCommand(String command) async {
|
||||||
|
EventDelegate<String> delegate = EventDelegate();
|
||||||
|
|
||||||
|
final client = liveInformation.auth.client;
|
||||||
|
|
||||||
|
final databases = appwrite.Databases(client);
|
||||||
|
|
||||||
|
if (liveInformation.auth.status == AuthStatus.AUTHENTICATED) {
|
||||||
|
final document = await databases.createDocument(
|
||||||
|
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
||||||
|
collectionId: ApiConstants.COMMANDS_COLLECTION_ID,
|
||||||
|
documentId: appwrite.ID.unique(),
|
||||||
|
data: {
|
||||||
|
"session_id": sessionID,
|
||||||
|
"command": command,
|
||||||
|
"client_id": clientID,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onCommandReceived(CommandInfo(command, clientID));
|
||||||
|
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onCommandReceived(CommandInfo commandInfo) async {
|
||||||
|
|
||||||
|
commandHistory.add(commandInfo);
|
||||||
|
onCommandReceived.trigger(commandInfo);
|
||||||
|
|
||||||
|
print("Received command: ${commandInfo.command}");
|
||||||
|
|
||||||
|
List<String> commandParts = splitCommand(commandInfo.command);
|
||||||
|
String command = commandParts[0];
|
||||||
|
List<String> args = commandParts.sublist(1);
|
||||||
|
|
||||||
|
if (command == "Response:") {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (command == "announce") {
|
||||||
|
|
||||||
|
final displayText = args[1];
|
||||||
|
|
||||||
|
if (args[0] == "manual") {
|
||||||
|
// announce manual <DisplayText> <AudioFileName>... <ScheduledTime>
|
||||||
|
|
||||||
|
|
||||||
|
List<String> audioFileNames = args.sublist(2);
|
||||||
|
try {
|
||||||
|
if (int.parse(audioFileNames.last) != null) {
|
||||||
|
audioFileNames.removeLast();
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
DateTime scheduledTime = LiveInformation().syncedTimeModule.Now().add(Duration(seconds: 1));
|
||||||
|
try {
|
||||||
|
if (int.parse(args.last) != null) {
|
||||||
|
scheduledTime = DateTime.fromMillisecondsSinceEpoch(int.parse(args.last));
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
liveInformation.announcementModule.queueAnnounceByAudioName(
|
||||||
|
displayText: displayText,
|
||||||
|
audioNames: audioFileNames,
|
||||||
|
scheduledTime: scheduledTime,
|
||||||
|
sendToServer: false
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (args[0] == "info") {
|
||||||
|
|
||||||
|
int InfoIndex = int.parse(args[1]);
|
||||||
|
|
||||||
|
DateTime scheduledTime = LiveInformation().syncedTimeModule.Now();
|
||||||
|
try {
|
||||||
|
if (int.parse(args.last) != null) {
|
||||||
|
scheduledTime = DateTime.fromMillisecondsSinceEpoch(int.parse(args.last));
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
liveInformation.announcementModule.queueAnnounementByInfoIndex(
|
||||||
|
infoIndex: InfoIndex,
|
||||||
|
scheduledTime: scheduledTime,
|
||||||
|
sendToServer: false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (args[0].startsWith("dest")) {
|
||||||
|
// announce destination <RouteNumber> <RouteVariantIndex> <ScheduledTime>
|
||||||
|
|
||||||
|
String routeNumber = args[1];
|
||||||
|
int routeVariantIndex = int.parse(args[2]);
|
||||||
|
|
||||||
|
DateTime scheduledTime = LiveInformation().syncedTimeModule.Now();
|
||||||
|
try {
|
||||||
|
if (int.parse(args.last) != null) {
|
||||||
|
scheduledTime = DateTime.fromMillisecondsSinceEpoch(int.parse(args.last));
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
BusRoute route = LiveInformation().busSequences.routes[routeNumber]!;
|
||||||
|
BusRouteVariant routeVariant = route.routeVariants.values.toList()[routeVariantIndex];
|
||||||
|
|
||||||
|
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
|
||||||
|
routeVariant: routeVariant,
|
||||||
|
scheduledTime: scheduledTime,
|
||||||
|
sendToServer: false
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (command == "setroute") {
|
||||||
|
// setroute <RouteNumber> <RouteVariantIndex>
|
||||||
|
|
||||||
|
LiveInformation liveInformation = LiveInformation();
|
||||||
|
|
||||||
|
String routeNumber = args[0];
|
||||||
|
int routeVariantIndex = int.parse(args[1]);
|
||||||
|
|
||||||
|
BusRoute route = liveInformation.busSequences.routes[routeNumber]!;
|
||||||
|
BusRouteVariant routeVariant = route.routeVariants.values.toList()[routeVariantIndex];
|
||||||
|
|
||||||
|
liveInformation.setRouteVariant_Internal(
|
||||||
|
routeVariant
|
||||||
|
);
|
||||||
|
executeCommand("Response: v \"Client $clientID set its route to ($routeNumber to ${routeVariant.busStops.last.formattedStopName})\"");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
appwrite.RealtimeSubscription? _subscription;
|
||||||
|
Future<void> _setupListener() async {
|
||||||
|
if (_subscription != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final realtime = appwrite.Realtime(LiveInformation().auth.client);
|
||||||
|
|
||||||
|
_subscription = realtime.subscribe(
|
||||||
|
['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.COMMANDS_COLLECTION_ID}.documents']
|
||||||
|
);
|
||||||
|
_subscription!.stream.listen((event) {
|
||||||
|
print(jsonEncode(event.payload));
|
||||||
|
|
||||||
|
// Only do something if the document was created or updated
|
||||||
|
if (!(event.events.first.contains("create") || event.events.first.contains("update"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final commandInfo = CommandInfo(event.payload['command'], event.payload['client_id']);
|
||||||
|
|
||||||
|
if (commandInfo.clientID != clientID) {
|
||||||
|
_onCommandReceived(commandInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
print("Listening for commands");
|
||||||
|
|
||||||
|
await Future.delayed(Duration(seconds: 90));
|
||||||
|
|
||||||
|
await _subscription!.close();
|
||||||
|
_subscription = null;
|
||||||
|
_setupListener();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommandInfo {
|
||||||
|
final String command;
|
||||||
|
final String clientID;
|
||||||
|
|
||||||
|
CommandInfo(this.command, this.clientID);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> splitCommand(String command) {
|
||||||
|
var regex = RegExp(r'([^\s"]+)|"([^"]*)"');
|
||||||
|
var matches = regex.allMatches(command);
|
||||||
|
return matches.map((match) => match.group(0)!.replaceAll('"', '')).toList();
|
||||||
|
}
|
||||||
8
lib/backend/modules/info_module.dart
Normal file
8
lib/backend/modules/info_module.dart
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
|
||||||
|
abstract class InfoModule {
|
||||||
|
|
||||||
|
LiveInformation get liveInformation => LiveInformation();
|
||||||
|
|
||||||
|
}
|
||||||
36
lib/backend/modules/synced_time.dart
Normal file
36
lib/backend/modules/synced_time.dart
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
import 'info_module.dart';
|
||||||
|
|
||||||
|
class SyncedTimeModule extends InfoModule {
|
||||||
|
|
||||||
|
int timeOffset = -1;
|
||||||
|
DateTime lastUpdate = DateTime.now().add(const Duration(seconds: -15));
|
||||||
|
|
||||||
|
SyncedTimeModule() {
|
||||||
|
refreshTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer refreshTimer() => Timer.periodic(const Duration(seconds: 10), (timer) async {
|
||||||
|
var res = await http.get(Uri.parse('http://worldtimeapi.org/api/timezone/Europe/London'));
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
var json = jsonDecode(res.body);
|
||||||
|
DateTime time = DateTime.parse(json['datetime']);
|
||||||
|
timeOffset = time.millisecondsSinceEpoch - DateTime.now().millisecondsSinceEpoch;
|
||||||
|
lastUpdate = DateTime.now();
|
||||||
|
print("Time offset: $timeOffset");
|
||||||
|
} else {
|
||||||
|
print("Failed to get time from worldtimeapi.org");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DateTime Now() {
|
||||||
|
if (timeOffset == -1) {
|
||||||
|
return DateTime.now();
|
||||||
|
}
|
||||||
|
return DateTime.now().add(Duration(milliseconds: timeOffset));
|
||||||
|
}
|
||||||
|
}
|
||||||
199
lib/backend/modules/tracker.dart
Normal file
199
lib/backend/modules/tracker.dart
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:math';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/info_module.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:geolocator/geolocator.dart';
|
||||||
|
import 'package:vector_math/vector_math.dart';
|
||||||
|
|
||||||
|
class TrackerModule extends InfoModule {
|
||||||
|
|
||||||
|
|
||||||
|
TrackerModule() {
|
||||||
|
locationStream();
|
||||||
|
Geolocator.getLastKnownPosition().then((Position? position) {
|
||||||
|
this._position = position;
|
||||||
|
updateNearestStop();
|
||||||
|
});
|
||||||
|
liveInformation.routeVariantDelegate.addListener((routeVariant) {
|
||||||
|
print("Route variant changed");
|
||||||
|
updateNearestStop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Position? _position;
|
||||||
|
Position? get position => _position;
|
||||||
|
|
||||||
|
StreamSubscription<Position> locationStream() => Geolocator.getPositionStream(
|
||||||
|
locationSettings: const LocationSettings(
|
||||||
|
accuracy: LocationAccuracy.high,
|
||||||
|
distanceFilter: 1,
|
||||||
|
)
|
||||||
|
).listen((Position position) {
|
||||||
|
|
||||||
|
if (position == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._position = position;
|
||||||
|
updateNearestStop();
|
||||||
|
});
|
||||||
|
|
||||||
|
Timer refreshTimer() => Timer.periodic(Duration(seconds: 1), (timer) async {
|
||||||
|
_position = await Geolocator.getCurrentPosition();
|
||||||
|
});
|
||||||
|
|
||||||
|
BusRouteStop? nearestStop;
|
||||||
|
bool hasArrived = false;
|
||||||
|
|
||||||
|
Future<void> updateNearestStop() async {
|
||||||
|
if (liveInformation.getRouteVariant() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the closest stop
|
||||||
|
BusRouteStop closestStop = liveInformation.getRouteVariant()!.busStops.first;
|
||||||
|
double closestDistance = OSGrid
|
||||||
|
.toNorthingEasting(_position!.latitude, _position!.longitude)
|
||||||
|
.distanceTo(Vector2(closestStop.easting.toDouble(), closestStop.northing.toDouble()));
|
||||||
|
|
||||||
|
for (BusRouteStop stop in liveInformation.getRouteVariant()!.busStops) {
|
||||||
|
double distance = OSGrid
|
||||||
|
.toNorthingEasting(_position!.latitude, _position!.longitude)
|
||||||
|
.distanceTo(Vector2(stop.easting.toDouble(), stop.northing.toDouble()));
|
||||||
|
|
||||||
|
if (distance < closestDistance) {
|
||||||
|
closestStop = stop;
|
||||||
|
closestDistance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double relativeDistance = _calculateRelativeDistance(closestStop, _position!.latitude, _position!.longitude);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (relativeDistance < -10) {
|
||||||
|
print("Closest stop is behind us: ${closestStop.formattedStopName}");
|
||||||
|
print("Relative distance: $relativeDistance");
|
||||||
|
|
||||||
|
int stopIndex = liveInformation.getRouteVariant()!.busStops.indexOf(closestStop);
|
||||||
|
|
||||||
|
closestStop = liveInformation.getRouteVariant()!.busStops[stopIndex + 1];
|
||||||
|
|
||||||
|
print("Closest stop is now: ${closestStop.formattedStopName}");
|
||||||
|
} else {
|
||||||
|
print("Closest stop is in front of us: ${closestStop.formattedStopName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool preExisting = true;
|
||||||
|
|
||||||
|
if (nearestStop != closestStop) {
|
||||||
|
nearestStop = closestStop;
|
||||||
|
hasArrived = false;
|
||||||
|
preExisting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Closest stop is the same as before");
|
||||||
|
|
||||||
|
double distance = OSGrid
|
||||||
|
.toNorthingEasting(_position!.latitude, _position!.longitude)
|
||||||
|
.distanceTo(Vector2(nearestStop!.easting.toDouble(), nearestStop!.northing.toDouble()));
|
||||||
|
|
||||||
|
// get the speed in mph
|
||||||
|
double speed = _position!.speed * 2.23694;
|
||||||
|
print("Speed: $speed");
|
||||||
|
|
||||||
|
Duration? duration;
|
||||||
|
{
|
||||||
|
// Testing some audio stuff
|
||||||
|
Uint8List? audioBytes = liveInformation.announcementModule.announcementCache[nearestStop!.getAudioFileName()];
|
||||||
|
AudioWrapperByteSource audioSource = AudioWrapperByteSource(audioBytes!);
|
||||||
|
|
||||||
|
AudioWrapper audio = AudioWrapper();
|
||||||
|
|
||||||
|
await audio.loadSource(audioSource);
|
||||||
|
|
||||||
|
duration = await audio.getDuration();
|
||||||
|
|
||||||
|
print("Duration of audio: $duration");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the estimated distance travelled in 5 seconds, in meters
|
||||||
|
double distanceTravelled = speed * (3 + duration!.inSeconds);
|
||||||
|
|
||||||
|
// adjust for the it takes to send the announcement to other devices
|
||||||
|
distance -= distanceTravelled;
|
||||||
|
|
||||||
|
// get the time to the stop in seconds
|
||||||
|
double timeToStop = distance / speed;
|
||||||
|
|
||||||
|
print("Distance to stop: $distance");
|
||||||
|
print("Time to stop: $timeToStop");
|
||||||
|
|
||||||
|
int secondsBefore = 7;
|
||||||
|
|
||||||
|
print("Seconds before: $secondsBefore");
|
||||||
|
|
||||||
|
if ((timeToStop < secondsBefore ) && !hasArrived && relativeDistance > 0) {
|
||||||
|
print("We are at the stop");
|
||||||
|
hasArrived = true;
|
||||||
|
liveInformation.announcementModule.queueAnnounceByAudioName(
|
||||||
|
displayText: "${nearestStop!.formattedStopName}",
|
||||||
|
audioNames: [
|
||||||
|
// "A_NEXT_STOP_001.mp3",
|
||||||
|
nearestStop!.getAudioFileName()
|
||||||
|
],
|
||||||
|
sendToServer: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!hasArrived && !preExisting) {
|
||||||
|
liveInformation.announcementModule.queueAnnounceByAudioName(
|
||||||
|
displayText: "${closestStop.formattedStopName}",
|
||||||
|
audioNames: [],
|
||||||
|
sendToServer: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("Closest stop: ${closestStop.formattedStopName} in ${closestDistance.round()} meters");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double _calculateRelativeDistance(BusRouteStop stop, double latitude, double longitude) {
|
||||||
|
|
||||||
|
List<double> toLatLong = OSGrid.toLatLong(stop.northing.toDouble(), stop.easting.toDouble());
|
||||||
|
|
||||||
|
Vector2 stopPoint = OSGrid.toNorthingEasting(toLatLong[0], toLatLong[1]);
|
||||||
|
Vector2 currentPoint = OSGrid.toNorthingEasting(latitude, longitude);
|
||||||
|
|
||||||
|
// calculate the heading from the current point to the stop point
|
||||||
|
// 0 degrees is north, 90 degrees is east, 180 degrees is south, 270 degrees is west
|
||||||
|
double toHeading = degrees(atan2(stopPoint.x - currentPoint.x, stopPoint.y - currentPoint.y));
|
||||||
|
toHeading = (toHeading + 360) % 360;
|
||||||
|
|
||||||
|
// get the dot product of the heading and the stop heading
|
||||||
|
double dotProduct = cos(radians(toHeading)) * cos(radians(stop.heading.toDouble())) + sin(radians(toHeading)) * sin(radians(stop.heading.toDouble()));
|
||||||
|
|
||||||
|
return (dotProduct.sign) * _calculateDistance(latitude, longitude, toLatLong[0], toLatLong[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double _calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||||
|
|
||||||
|
// Convert to eastings and northings
|
||||||
|
Vector2 point1 = OSGrid.toNorthingEasting(lat1, lon1);
|
||||||
|
Vector2 point2 = OSGrid.toNorthingEasting(lat2, lon2);
|
||||||
|
|
||||||
|
return point1.distanceTo(point2);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,15 +2,32 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:bus_infotainment/pages/audio_cache_test.dart';
|
import 'package:bus_infotainment/pages/audio_cache_test.dart';
|
||||||
import 'package:bus_infotainment/pages/tfl_dataset_test.dart';
|
import 'package:bus_infotainment/pages/tfl_dataset_test.dart';
|
||||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
if (defaultTargetPlatform == TargetPlatform.windows && !kIsWeb) {
|
||||||
|
await windowManager.ensureInitialized();
|
||||||
|
|
||||||
|
WindowOptions options = WindowOptions(
|
||||||
|
size: Size(411.4, 850.3),
|
||||||
|
);
|
||||||
|
|
||||||
|
windowManager.setAspectRatio(411.4 / 850.3);
|
||||||
|
|
||||||
|
await windowManager.waitUntilReadyToShow(options, () async {
|
||||||
|
await windowManager.show();
|
||||||
|
await windowManager.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
LiveInformation liveInformation = LiveInformation();
|
LiveInformation liveInformation = LiveInformation();
|
||||||
await liveInformation.Initialize();
|
await liveInformation.initialize();
|
||||||
|
|
||||||
// Disalow screen to turn off on android
|
// Disalow screen to turn off on android
|
||||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
@@ -30,6 +47,10 @@ class MyApp extends StatelessWidget {
|
|||||||
// This widget is the root of your application.
|
// This widget is the root of your application.
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
// Permission.location.onGrantedCallback(() => null).request();
|
||||||
|
|
||||||
|
print("Window size: ${MediaQuery.of(context).size}");
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
import 'package:bus_infotainment/utils/delegates.dart';
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:text_scroll/text_scroll.dart';
|
import 'package:text_scroll/text_scroll.dart';
|
||||||
|
|
||||||
class ibus_display extends StatefulWidget {
|
class ibus_display extends StatefulWidget {
|
||||||
@@ -21,13 +22,14 @@ class ibus_display extends StatefulWidget {
|
|||||||
class _ibus_displayState extends State<ibus_display> {
|
class _ibus_displayState extends State<ibus_display> {
|
||||||
|
|
||||||
String topLine = "*** NO MESSAGE ***";
|
String topLine = "*** NO MESSAGE ***";
|
||||||
|
String bottomLine = "";
|
||||||
|
|
||||||
late final ListenerReceipt<AnnouncementQueueEntry> _receipt;
|
late final ListenerReceipt<AnnouncementQueueEntry> _receipt;
|
||||||
|
|
||||||
_ibus_displayState(){
|
_ibus_displayState(){
|
||||||
|
|
||||||
LiveInformation liveInformation = LiveInformation();
|
LiveInformation liveInformation = LiveInformation();
|
||||||
_receipt = liveInformation.announcementDelegate.addListener((value) {
|
_receipt = liveInformation.announcementModule.onAnnouncement.addListener((value) {
|
||||||
|
|
||||||
if (topLine == value.displayText){
|
if (topLine == value.displayText){
|
||||||
return;
|
return;
|
||||||
@@ -38,7 +40,7 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
topLine = liveInformation.currentAnnouncement;
|
topLine = liveInformation.announcementModule.currentAnnouncement?.displayText ?? liveInformation.announcementModule.defaultText;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +57,8 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
prefix += " ";
|
prefix += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input = input.replaceAll("©", "(c)");
|
||||||
|
|
||||||
return prefix + input + suffix;
|
return prefix + input + suffix;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -62,7 +66,7 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
|
||||||
LiveInformation().announcementDelegate.removeListener(_receipt);
|
LiveInformation().announcementModule.onAnnouncement.removeListener(_receipt);
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
@@ -75,19 +79,45 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
return Container(
|
return Container(
|
||||||
|
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
color: Colors.black,
|
||||||
|
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
|
Positioned.fill(
|
||||||
|
child: Container(
|
||||||
|
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
|
||||||
|
margin: EdgeInsets.all(1),
|
||||||
|
|
||||||
|
child: Text(
|
||||||
|
"© ImBenji.net - all rights reserved | © Transport for London - all rights reserved",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
fontSize: 10,
|
||||||
|
color: Colors.white.withOpacity(0.01),
|
||||||
|
height: 1,
|
||||||
|
shadows: [
|
||||||
|
Shadow(
|
||||||
|
color: Colors.black,
|
||||||
|
blurRadius: 5,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
|
|
||||||
// width: double.infinity,
|
// width: double.infinity,
|
||||||
// height: 100,
|
// height: 100,
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black,
|
|
||||||
border: widget.hasBorder ? Border.all(color: Colors.grey.shade900, width: 2) : null,
|
border: widget.hasBorder ? Border.all(color: Colors.grey.shade900, width: 2) : null,
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -127,17 +157,27 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
),
|
),
|
||||||
|
|
||||||
Transform.translate(
|
Transform.translate(
|
||||||
offset: Offset(0, -7),
|
offset: Offset(0, -6),
|
||||||
child: Text(
|
child: Container(
|
||||||
"",
|
alignment: Alignment.center,
|
||||||
|
width: 32*4*3,
|
||||||
|
child: TextScroll(
|
||||||
|
_padString(bottomLine),
|
||||||
|
velocity: Velocity(pixelsPerSecond: Offset(120, 0)),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: Colors.orange,
|
color: Colors.orange,
|
||||||
fontFamily: "ibus",
|
fontFamily: "ibus",
|
||||||
height: 1.5
|
shadows: [
|
||||||
|
Shadow(
|
||||||
|
color: Colors.orange,
|
||||||
|
blurRadius: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -145,6 +185,8 @@ class _ibus_displayState extends State<ibus_display> {
|
|||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:bus_infotainment/pages/components/ibus_display.dart';
|
|||||||
import 'package:bus_infotainment/pages/tfl_dataset_test.dart';
|
import 'package:bus_infotainment/pages/tfl_dataset_test.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
class pages_Display extends StatefulWidget {
|
class pages_Display extends StatefulWidget {
|
||||||
|
|
||||||
@@ -30,23 +31,29 @@ class _pages_DisplayState extends State<pages_Display> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
if (MediaQuery.of(context).size.width < 600)
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: RotatedBox(
|
child: RotatedBox(
|
||||||
quarterTurns: 1,
|
quarterTurns: 1,
|
||||||
child: ibus_display(
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
ibus_display(
|
||||||
hasBorder: false,
|
hasBorder: false,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
if (widget._tfL_Dataset_TestState.hideUI)
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.bottomLeft,
|
||||||
|
height: double.infinity,
|
||||||
|
width: double.infinity,
|
||||||
|
|
||||||
|
margin: EdgeInsets.all(5),
|
||||||
|
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
|
||||||
Expanded(
|
|
||||||
child: ibus_display(
|
|
||||||
hasBorder: false,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:bus_infotainment/pages/components/ibus_display.dart';
|
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/tfl_datasets.dart';
|
||||||
|
import 'package:bus_infotainment/utils/OrdinanceSurveyUtils.dart';
|
||||||
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
||||||
import 'package:bus_infotainment/utils/delegates.dart';
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
class pages_Home extends StatelessWidget {
|
class pages_Home extends StatelessWidget {
|
||||||
@@ -18,61 +22,55 @@ class pages_Home extends StatelessWidget {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
child: SingleChildScrollView(
|
child: Column(
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Row(
|
||||||
|
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Speedometer(),
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
height: 2,
|
|
||||||
color: Colors.white70,
|
|
||||||
),
|
|
||||||
|
|
||||||
Container(
|
margin: EdgeInsets.all(10),
|
||||||
|
|
||||||
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(
|
child: Container(
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey.shade900,
|
color: Colors.grey.shade900,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.3),
|
|
||||||
blurRadius: 2,
|
|
||||||
spreadRadius: 4
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
|
|
||||||
child: ManualAnnouncementPicker(
|
child: AnnouncementPicker(
|
||||||
backgroundColor: Colors.grey.shade900,
|
backgroundColor: Colors.grey.shade900,
|
||||||
outlineColor: Colors.white70,
|
outlineColor: Colors.white70,
|
||||||
announcements: [
|
announcements: [
|
||||||
...LiveInformation().manualAnnouncements
|
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
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -86,19 +84,11 @@ class pages_Home extends StatelessWidget {
|
|||||||
|
|
||||||
Container(
|
Container(
|
||||||
|
|
||||||
margin: EdgeInsets.all(20),
|
margin: EdgeInsets.all(10),
|
||||||
|
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey.shade900,
|
color: Colors.grey.shade900,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.3),
|
|
||||||
blurRadius: 2,
|
|
||||||
spreadRadius: 4
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
|
|
||||||
child: DelegateBuilder<BusRouteVariant>(
|
child: DelegateBuilder<BusRouteVariant>(
|
||||||
@@ -142,9 +132,18 @@ class pages_Home extends StatelessWidget {
|
|||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
LiveInformation liveInformation = LiveInformation();
|
LiveInformation liveInformation = LiveInformation();
|
||||||
liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: true));
|
final commandModule = liveInformation.commandModule;
|
||||||
|
|
||||||
|
// commandModule.executeCommand(
|
||||||
|
// "announce dest"
|
||||||
|
// );
|
||||||
|
|
||||||
|
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
|
||||||
|
routeVariant: liveInformation.getRouteVariant()!
|
||||||
|
);
|
||||||
|
|
||||||
},
|
},
|
||||||
child: Text("Announce Destination"),
|
child: Text("Announce current destination"),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
@@ -219,25 +218,147 @@ class pages_Home extends StatelessWidget {
|
|||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 backgroundColor;
|
||||||
final Color outlineColor;
|
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
|
@override
|
||||||
State<ManualAnnouncementPicker> createState() => _ManualAnnouncementPickerState();
|
State<AnnouncementPicker> createState() => _AnnouncementPickerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
class _AnnouncementPickerState extends State<AnnouncementPicker> {
|
||||||
|
|
||||||
List<Widget> announcementWidgets = [];
|
List<Widget> announcementWidgets = [];
|
||||||
|
|
||||||
@@ -255,13 +376,9 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (NamedAnnouncementQueueEntry announcement in widget.announcements!) {
|
for (Widget announcement in widget.announcements!) {
|
||||||
announcementWidgets.add(
|
announcementWidgets.add(
|
||||||
_ManualAnnouncementEntry(
|
announcement
|
||||||
announcement: announcement,
|
|
||||||
index: i,
|
|
||||||
outlineColor: Colors.white70
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -436,7 +553,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
|||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length);
|
_currentIndex = wrap(_currentIndex - 4, 0, announcementWidgets.length, increment: 4);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
print(_currentIndex);
|
print(_currentIndex);
|
||||||
},
|
},
|
||||||
@@ -489,7 +606,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
|||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length);
|
_currentIndex = wrap(_currentIndex + 4, 0, announcementWidgets.length, increment: 4);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
print(_currentIndex);
|
print(_currentIndex);
|
||||||
},
|
},
|
||||||
@@ -529,7 +646,7 @@ class _ManualAnnouncementPickerState extends State<ManualAnnouncementPicker> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StopAnnouncementPicker extends ManualAnnouncementPicker {
|
class StopAnnouncementPicker extends AnnouncementPicker {
|
||||||
final BusRouteVariant routeVariant;
|
final BusRouteVariant routeVariant;
|
||||||
|
|
||||||
StopAnnouncementPicker({
|
StopAnnouncementPicker({
|
||||||
@@ -542,29 +659,52 @@ class StopAnnouncementPicker extends ManualAnnouncementPicker {
|
|||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
outlineColor: outlineColor,
|
outlineColor: outlineColor,
|
||||||
announcements: [
|
announcements: [
|
||||||
for (BusRouteStops stop in routeVariant.busStops)
|
for (BusRouteStop stop in routeVariant.busStops)
|
||||||
ManualAnnouncementEntry(
|
_AnnouncementEntry(
|
||||||
shortName: stop.formattedStopName,
|
label: stop.formattedStopName,
|
||||||
informationText: stop.formattedStopName,
|
onPressed: () {
|
||||||
audioFileNames: [
|
LiveInformation liveInformation = LiveInformation();
|
||||||
stop.getAudioFileName()
|
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) {
|
int wrap(int i, int j, int length, {int increment = -1}) {
|
||||||
|
if (increment == -1) {
|
||||||
return ((i - j) % length + length) % length;
|
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 int index;
|
||||||
final Color outlineColor;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -591,18 +731,44 @@ class _ManualAnnouncementEntry extends StatelessWidget {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
|
||||||
|
|
||||||
child: Transform.translate(
|
|
||||||
|
|
||||||
offset: Offset(0, 4),
|
|
||||||
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
announcement.shortName,
|
children: [
|
||||||
|
Container(
|
||||||
|
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxWidth: 260
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
style: GoogleFonts.teko(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 25,
|
fontSize: 25,
|
||||||
color: outlineColor,
|
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(
|
Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -619,7 +785,6 @@ class _ManualAnnouncementEntry extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
),
|
),
|
||||||
@@ -627,8 +792,7 @@ class _ManualAnnouncementEntry extends StatelessWidget {
|
|||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
LiveInformation liveInformation = LiveInformation();
|
onPressed();
|
||||||
liveInformation.queueAnnouncement(announcement);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/pages/components/ibus_display.dart';
|
||||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
@@ -20,7 +21,19 @@ class _pages_RoutesState extends State<pages_Routes> {
|
|||||||
LiveInformation liveInformation = LiveInformation();
|
LiveInformation liveInformation = LiveInformation();
|
||||||
|
|
||||||
List<Widget> routes = [];
|
List<Widget> routes = [];
|
||||||
routes.add(SizedBox(height: 10));
|
// routes.add(Container(
|
||||||
|
// width: double.infinity,
|
||||||
|
// height: 16,
|
||||||
|
// decoration: BoxDecoration(
|
||||||
|
// color: Colors.grey.shade900,
|
||||||
|
// border: const Border.symmetric(
|
||||||
|
// horizontal: BorderSide(
|
||||||
|
// color: Colors.white70,
|
||||||
|
// width: 2,
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
// ),
|
||||||
|
// ));
|
||||||
for (BusRoute route in liveInformation.busSequences!.routes.values) {
|
for (BusRoute route in liveInformation.busSequences!.routes.values) {
|
||||||
|
|
||||||
if (!route.routeNumber.toLowerCase().contains(_controller.text.toLowerCase())) {
|
if (!route.routeNumber.toLowerCase().contains(_controller.text.toLowerCase())) {
|
||||||
@@ -28,49 +41,77 @@ class _pages_RoutesState extends State<pages_Routes> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
routes.add(_Route(route, this));
|
routes.add(_Route(route, this));
|
||||||
routes.add(SizedBox(height: 10));
|
routes.add(Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 16,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade900,
|
||||||
|
border: const Border.symmetric(
|
||||||
|
horizontal: BorderSide(
|
||||||
|
color: Colors.white70,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if(!routes.isEmpty){
|
||||||
|
routes.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
color: Theme.of(context).colorScheme.background,
|
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade900,
|
||||||
|
),
|
||||||
|
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
// padding: const EdgeInsets.symmetric(horizontal: 10),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
|
|
||||||
padding: const EdgeInsets.all(10),
|
margin: const EdgeInsets.all(10),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.background,
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.5),
|
|
||||||
spreadRadius: 2,
|
|
||||||
blurRadius: 4,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: ">",
|
||||||
|
),
|
||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
if (routes.isNotEmpty)
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: routes,
|
children: routes,
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
"No routes found",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
fontSize: 50,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white70,
|
||||||
|
height: 1
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -93,28 +134,23 @@ class _Route extends StatelessWidget {
|
|||||||
List<Widget> Variants = [];
|
List<Widget> Variants = [];
|
||||||
|
|
||||||
for (BusRouteVariant variant in route.routeVariants.values) {
|
for (BusRouteVariant variant in route.routeVariants.values) {
|
||||||
Variants.add(const SizedBox(height: 10));
|
|
||||||
Variants.add(_Variant(route, variant, tfL_Dataset_TestState));
|
Variants.add(_Variant(route, variant, tfL_Dataset_TestState));
|
||||||
|
|
||||||
|
if (route.routeVariants.values.last != variant) {
|
||||||
|
Variants.add(Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.5),
|
|
||||||
spreadRadius: 2,
|
|
||||||
blurRadius: 4,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
color: Colors.grey.shade900,
|
color: Colors.grey.shade900,
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 10),
|
|
||||||
padding: const EdgeInsets.all(10),
|
|
||||||
|
|
||||||
width: 100,
|
width: 100,
|
||||||
|
|
||||||
@@ -125,21 +161,27 @@ class _Route extends StatelessWidget {
|
|||||||
|
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Container(
|
Container(
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey.shade800,
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(5),
|
border: Border.all(
|
||||||
|
color: Colors.white70,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
|
margin: const EdgeInsets.all(4),
|
||||||
|
|
||||||
child: Text(
|
child: Text(
|
||||||
"Route: ${route.routeNumber}",
|
"Route: ${route.routeNumber}",
|
||||||
style: GoogleFonts.montserrat(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 20,
|
fontSize: 25,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
height: 1
|
height: 1
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -147,11 +189,34 @@ class _Route extends StatelessWidget {
|
|||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
ListView(
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.transparent,
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.white70,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
margin: const EdgeInsets.all(4),
|
||||||
|
|
||||||
|
child: ListView(
|
||||||
children: Variants,
|
children: Variants,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -181,7 +246,7 @@ class _Variant extends StatelessWidget {
|
|||||||
Container(
|
Container(
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.grey.shade800,
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -198,10 +263,10 @@ class _Variant extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Start:",
|
"Start:",
|
||||||
style: GoogleFonts.montserrat(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 15,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
height: 1,
|
height: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -210,14 +275,14 @@ class _Variant extends StatelessWidget {
|
|||||||
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextScroll(
|
child: TextScroll(
|
||||||
"${variant.busStops.first.formattedStopName}",
|
variant.busStops.first.formattedStopName,
|
||||||
mode: TextScrollMode.bouncing,
|
mode: TextScrollMode.bouncing,
|
||||||
pauseBetween: const Duration(seconds: 2),
|
pauseBetween: const Duration(seconds: 2),
|
||||||
pauseOnBounce: const Duration(seconds: 2),
|
pauseOnBounce: const Duration(seconds: 2),
|
||||||
style: GoogleFonts.montserrat(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 15,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
height: 1,
|
height: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -232,10 +297,11 @@ class _Variant extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"End:",
|
"End:",
|
||||||
style: GoogleFonts.montserrat(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 15,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
|
height: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -247,10 +313,10 @@ class _Variant extends StatelessWidget {
|
|||||||
mode: TextScrollMode.bouncing,
|
mode: TextScrollMode.bouncing,
|
||||||
pauseBetween: const Duration(seconds: 2),
|
pauseBetween: const Duration(seconds: 2),
|
||||||
pauseOnBounce: const Duration(seconds: 2),
|
pauseOnBounce: const Duration(seconds: 2),
|
||||||
style: GoogleFonts.montserrat(
|
style: GoogleFonts.teko(
|
||||||
fontSize: 15,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
height: 1,
|
height: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -338,13 +404,12 @@ class _Variant extends StatelessWidget {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
LiveInformation liveInformation = LiveInformation();
|
LiveInformation liveInformation = LiveInformation();
|
||||||
liveInformation.setRouteVariant(variant);
|
await liveInformation.setRouteVariant(variant);
|
||||||
|
|
||||||
liveInformation.queueAnnouncement(
|
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
|
||||||
await liveInformation.getDestinationAnnouncement(
|
routeVariant: variant,
|
||||||
variant,
|
scheduledTime: liveInformation.syncedTimeModule.Now(),
|
||||||
sendToServer: true,
|
sendToServer: false
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
tfL_Dataset_TestState.setState(() {});
|
tfL_Dataset_TestState.setState(() {});
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
|
|
||||||
|
|
||||||
import 'package:bus_infotainment/singletons/live_information.dart';
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/commands.dart';
|
||||||
|
import 'package:bus_infotainment/utils/delegates.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:text_scroll/text_scroll.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
class pages_Settings extends StatefulWidget {
|
class pages_Settings extends StatefulWidget {
|
||||||
@@ -14,22 +17,87 @@ class pages_Settings extends StatefulWidget {
|
|||||||
|
|
||||||
class _pages_SettingsState extends State<pages_Settings> {
|
class _pages_SettingsState extends State<pages_Settings> {
|
||||||
|
|
||||||
|
late final Widget _loginPage;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
if (!LiveInformation().auth.isAuthenticated()){
|
||||||
|
_loginPage = _LoginPage(
|
||||||
|
onLogin: () {
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_loginPage = Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: (){
|
||||||
|
setState(() {});
|
||||||
|
LiveInformation().auth.deleteSession();
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
// make the corner radius 4, background color match the theme, and text colour white, fill to width of parent
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(4)
|
||||||
|
),
|
||||||
|
minimumSize: Size(double.infinity, 48)
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Text(
|
||||||
|
"Sign out",
|
||||||
|
style: GoogleFonts.interTight(
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.white,
|
||||||
|
letterSpacing: 0.5
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
if (LiveInformation().auth.isAuthenticated()){
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.all(8),
|
||||||
|
child: Console()
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
height: 2,
|
||||||
|
width: double.infinity,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
|
||||||
|
child: _loginPage,
|
||||||
|
)
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return _LoginPage(
|
|
||||||
onLogin: () {
|
|
||||||
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,3 +695,117 @@ class PW_TextField extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Console widget
|
||||||
|
class Console extends StatefulWidget {
|
||||||
|
|
||||||
|
Console({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Console> createState() => _ConsoleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ConsoleState extends State<Console> {
|
||||||
|
|
||||||
|
ListenerReceipt? _listenerReceipt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_listenerReceipt = LiveInformation().commandModule.onCommandReceived.addListener((p0) {
|
||||||
|
print("Command received, updating console");
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
// TODO: implement dispose
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
List<Widget> commands = [];
|
||||||
|
|
||||||
|
TextEditingController commandController = TextEditingController();
|
||||||
|
|
||||||
|
commands.add(
|
||||||
|
Text("Command History:")
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < LiveInformation().commandModule.commandHistory.length; i++){
|
||||||
|
CommandInfo command = LiveInformation().commandModule.commandHistory[i];
|
||||||
|
|
||||||
|
commands.add(
|
||||||
|
TextScroll(
|
||||||
|
command.command,
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
letterSpacing: 0.1,
|
||||||
|
),
|
||||||
|
mode: TextScrollMode.bouncing,
|
||||||
|
pauseBetween: const Duration(seconds: 2),
|
||||||
|
pauseOnBounce: const Duration(seconds: 1),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: Colors.white70, width: 2),
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Column(
|
||||||
|
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
|
||||||
|
height: 300,
|
||||||
|
|
||||||
|
child: ListView(
|
||||||
|
children: commands,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
height: 2,
|
||||||
|
width: double.infinity,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
height: 50,
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: TextField(
|
||||||
|
controller: commandController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: ">",
|
||||||
|
),
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
commandController.clear();
|
||||||
|
LiveInformation().commandModule.executeCommand(value);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,15 @@ import 'package:bus_infotainment/pages/display.dart';
|
|||||||
import 'package:bus_infotainment/pages/home.dart';
|
import 'package:bus_infotainment/pages/home.dart';
|
||||||
import 'package:bus_infotainment/pages/routes.dart';
|
import 'package:bus_infotainment/pages/routes.dart';
|
||||||
import 'package:bus_infotainment/pages/settings.dart';
|
import 'package:bus_infotainment/pages/settings.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/tfl_datasets.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:text_scroll/text_scroll.dart';
|
import 'package:text_scroll/text_scroll.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
import 'components/ibus_display.dart';
|
||||||
|
|
||||||
class TfL_Dataset_Test extends StatefulWidget {
|
class TfL_Dataset_Test extends StatefulWidget {
|
||||||
|
|
||||||
@@ -19,9 +23,11 @@ class TfL_Dataset_Test extends StatefulWidget {
|
|||||||
|
|
||||||
class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
|
class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
|
||||||
|
|
||||||
int _selectedIndex = 0;
|
int _selectedIndex = 1;
|
||||||
|
|
||||||
bool hideUI = false;
|
bool hideUI = false;
|
||||||
|
bool shouldCurve = false;
|
||||||
|
bool rotated = false;
|
||||||
|
|
||||||
late final List<Widget> Pages;
|
late final List<Widget> Pages;
|
||||||
|
|
||||||
@@ -42,111 +48,434 @@ class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
|
|||||||
_selectedIndex = min(_selectedIndex, Pages.length - 1);
|
_selectedIndex = min(_selectedIndex, Pages.length - 1);
|
||||||
_selectedIndex = max(_selectedIndex, 0);
|
_selectedIndex = max(_selectedIndex, 0);
|
||||||
|
|
||||||
|
hideUI = _selectedIndex == 2 ? hideUI : false;
|
||||||
|
|
||||||
|
// print the window size
|
||||||
|
|
||||||
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||||
|
shouldCurve = true;
|
||||||
|
} else {
|
||||||
|
rotated = _selectedIndex == 2;
|
||||||
|
|
||||||
|
print("Window size: ${MediaQuery.of(context).size}");
|
||||||
|
|
||||||
|
windowManager.getSize().then((value) {
|
||||||
|
double aspectRatio = value.width / value.height;
|
||||||
|
double targetAspectRatio = rotated ? 850.3 / 411.4 : 411.4 / 850.3;
|
||||||
|
|
||||||
|
if ((aspectRatio - targetAspectRatio).abs() > 0.01) { // Add a tolerance value
|
||||||
|
if (aspectRatio != targetAspectRatio) {
|
||||||
|
windowManager.setSize(Size(value.height * targetAspectRatio, value.height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
||||||
appBar: !hideUI ? AppBar(
|
// appBar: !hideUI ? AppBar(
|
||||||
|
//
|
||||||
|
// surfaceTintColor: Colors.transparent,
|
||||||
|
//
|
||||||
|
// title: Container(
|
||||||
|
//
|
||||||
|
// child: Column(
|
||||||
|
//
|
||||||
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
//
|
||||||
|
// children: [
|
||||||
|
//
|
||||||
|
// Text(
|
||||||
|
// "Bus Infotainment",
|
||||||
|
// style: GoogleFonts.teko(
|
||||||
|
// fontSize: 25,
|
||||||
|
// fontWeight: FontWeight.bold,
|
||||||
|
// color: Colors.white,
|
||||||
|
// height: 1,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// Row(
|
||||||
|
//
|
||||||
|
// children: [
|
||||||
|
//
|
||||||
|
// Text(
|
||||||
|
// "Selected: ",
|
||||||
|
// style: GoogleFonts.teko(
|
||||||
|
// fontSize: 20,
|
||||||
|
// fontWeight: FontWeight.w600,
|
||||||
|
// color: Colors.white,
|
||||||
|
// height: 1,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// if (liveInformation.getRouteVariant() != null)
|
||||||
|
// Container(
|
||||||
|
//
|
||||||
|
// decoration: BoxDecoration(
|
||||||
|
// color: Colors.black,
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
||||||
|
//
|
||||||
|
// child: Text(
|
||||||
|
// "${liveInformation.getRouteVariant()!.busRoute.routeNumber} to ${liveInformation.getRouteVariant()!.busStops.last.formattedStopName}",
|
||||||
|
// style: GoogleFonts.montserrat(
|
||||||
|
// fontSize: 20,
|
||||||
|
// fontWeight: FontWeight.w500,
|
||||||
|
// color: Colors.orange.shade900,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
//
|
||||||
|
// )
|
||||||
|
// else
|
||||||
|
// Text(
|
||||||
|
// "None",
|
||||||
|
// style: GoogleFonts.teko(
|
||||||
|
// fontSize: 20,
|
||||||
|
// fontWeight: FontWeight.w500,
|
||||||
|
// color: Colors.white,
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
//
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// ],
|
||||||
|
//
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ) : null,
|
||||||
|
body: Container(
|
||||||
|
|
||||||
surfaceTintColor: Colors.transparent,
|
width: double.infinity,
|
||||||
|
height: double.infinity,
|
||||||
|
|
||||||
|
child: RotatedBox(
|
||||||
|
quarterTurns: rotated ? 3 : 0,
|
||||||
|
child: FittedBox(
|
||||||
|
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
fit: BoxFit.fitWidth,
|
||||||
|
|
||||||
|
child: Container(
|
||||||
|
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxWidth: 411.4,
|
||||||
|
maxHeight: 850.3,
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Container(
|
||||||
|
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: shouldCurve ? const BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(15),
|
||||||
|
bottomRight: Radius.circular(15),
|
||||||
|
) : null,
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.white70,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
color: Colors.grey.shade900,
|
||||||
|
),
|
||||||
|
|
||||||
|
margin: const EdgeInsets.all(6),
|
||||||
|
|
||||||
title: Container(
|
|
||||||
|
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
|
|
||||||
children: [
|
children: [
|
||||||
|
|
||||||
Text(
|
if (!hideUI)
|
||||||
"Bus Infotainment",
|
|
||||||
style: GoogleFonts.teko(
|
|
||||||
fontSize: 25,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.white,
|
|
||||||
height: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
Row(
|
|
||||||
|
|
||||||
children: [
|
|
||||||
|
|
||||||
Text(
|
|
||||||
"Selected: ",
|
|
||||||
style: GoogleFonts.teko(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white,
|
|
||||||
height: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
if (liveInformation.getRouteVariant() != null)
|
|
||||||
Container(
|
Container(
|
||||||
|
|
||||||
|
margin: const EdgeInsets.all(6),
|
||||||
|
|
||||||
|
child: ibus_display(),
|
||||||
|
),
|
||||||
|
|
||||||
|
if (!hideUI)
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
|
||||||
|
margin: const EdgeInsets.all(8),
|
||||||
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.black,
|
border: Border.all(
|
||||||
),
|
color: Colors.white70,
|
||||||
|
width: 2,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
|
||||||
|
|
||||||
child: Text(
|
|
||||||
"${liveInformation.getRouteVariant()!.busRoute.routeNumber} to ${liveInformation.getRouteVariant()!.busStops.last.formattedStopName}",
|
|
||||||
style: GoogleFonts.montserrat(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.orange.shade900,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Text(
|
|
||||||
"None",
|
|
||||||
style: GoogleFonts.teko(
|
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
],
|
|
||||||
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
color: Colors.grey.shade900,
|
||||||
|
borderRadius: hideUI && shouldCurve ? const BorderRadius.only(
|
||||||
|
bottomLeft: Radius.circular(7),
|
||||||
|
bottomRight: Radius.circular(7),
|
||||||
) : null,
|
) : null,
|
||||||
body: Pages[_selectedIndex],
|
),
|
||||||
|
|
||||||
|
child: ClipRRect(
|
||||||
|
|
||||||
bottomNavigationBar: !hideUI ? NavigationBar(
|
// curved corners
|
||||||
selectedIndex: _selectedIndex,
|
borderRadius: BorderRadius.only(
|
||||||
destinations: const [
|
bottomLeft: Radius.circular(7),
|
||||||
NavigationDestination(
|
bottomRight: Radius.circular(7),
|
||||||
icon: Icon(Icons.home),
|
|
||||||
label: "Home",
|
|
||||||
),
|
),
|
||||||
NavigationDestination(
|
|
||||||
icon: Icon(Icons.bus_alert),
|
child: Pages[_selectedIndex],
|
||||||
label: "Routes",
|
)
|
||||||
),
|
),
|
||||||
NavigationDestination(
|
|
||||||
icon: Icon(Icons.tv),
|
|
||||||
label: "Display",
|
|
||||||
),
|
),
|
||||||
NavigationDestination(
|
|
||||||
icon: Icon(Icons.settings),
|
if (!hideUI)
|
||||||
label: "Settings",
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 2,
|
||||||
|
color: Colors.white70,
|
||||||
),
|
),
|
||||||
],
|
|
||||||
onDestinationSelected: (int index) {
|
if (!hideUI)
|
||||||
|
Container(
|
||||||
|
height: 50,
|
||||||
|
|
||||||
|
child: Row(
|
||||||
|
|
||||||
|
children: [
|
||||||
|
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: const EdgeInsets.all(10),
|
||||||
|
child: Text(
|
||||||
|
"Home",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedIndex = index;
|
_selectedIndex = 0;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
) : null,
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
surfaceTintColor: Colors.transparent,
|
||||||
|
foregroundColor: Colors.transparent,
|
||||||
|
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(0),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Container()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
width: 2,
|
||||||
|
height: double.infinity,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: const EdgeInsets.all(10),
|
||||||
|
child: Text(
|
||||||
|
"Routes",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = 1;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
surfaceTintColor: Colors.transparent,
|
||||||
|
foregroundColor: Colors.transparent,
|
||||||
|
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(0),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Container()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
width: 2,
|
||||||
|
height: double.infinity,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: const EdgeInsets.all(10),
|
||||||
|
child: Text(
|
||||||
|
"Display",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = 2;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
surfaceTintColor: Colors.transparent,
|
||||||
|
foregroundColor: Colors.transparent,
|
||||||
|
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(0),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Container()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
Container(
|
||||||
|
width: 2,
|
||||||
|
height: double.infinity,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
margin: const EdgeInsets.all(10),
|
||||||
|
child: Text(
|
||||||
|
"Settings",
|
||||||
|
style: GoogleFonts.teko(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = 3;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
shadowColor: Colors.transparent,
|
||||||
|
surfaceTintColor: Colors.transparent,
|
||||||
|
foregroundColor: Colors.transparent,
|
||||||
|
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(0),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
child: Container()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
// bottomNavigationBar: !hideUI ? NavigationBar(
|
||||||
|
// selectedIndex: _selectedIndex,
|
||||||
|
// destinations: const [
|
||||||
|
// NavigationDestination(
|
||||||
|
// icon: Icon(Icons.home),
|
||||||
|
// label: "Home",
|
||||||
|
// ),
|
||||||
|
// NavigationDestination(
|
||||||
|
// icon: Icon(Icons.bus_alert),
|
||||||
|
// label: "Routes",
|
||||||
|
// ),
|
||||||
|
// NavigationDestination(
|
||||||
|
// icon: Icon(Icons.tv),
|
||||||
|
// label: "Display",
|
||||||
|
// ),
|
||||||
|
// NavigationDestination(
|
||||||
|
// icon: Icon(Icons.settings),
|
||||||
|
// label: "Settings",
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// onDestinationSelected: (int index) {
|
||||||
|
// setState(() {
|
||||||
|
// _selectedIndex = index;
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// ) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,855 +0,0 @@
|
|||||||
|
|
||||||
// Singleton
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:appwrite/appwrite.dart' as appwrite;
|
|
||||||
import 'package:appwrite/models.dart' as models;
|
|
||||||
import 'package:bus_infotainment/audio_cache.dart';
|
|
||||||
import 'package:bus_infotainment/auth/api_constants.dart';
|
|
||||||
import 'package:bus_infotainment/auth/auth_api.dart';
|
|
||||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
|
||||||
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
|
||||||
import 'package:bus_infotainment/utils/delegates.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:ntp/ntp.dart';
|
|
||||||
|
|
||||||
class LiveInformation {
|
|
||||||
|
|
||||||
static final LiveInformation _singleton = LiveInformation._internal();
|
|
||||||
|
|
||||||
factory LiveInformation() {
|
|
||||||
return _singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveInformation._internal();
|
|
||||||
|
|
||||||
Future<void> Initialize() async {
|
|
||||||
|
|
||||||
{
|
|
||||||
// Load the bus sequences
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
http.Response response = await http.get(Uri.parse('https://tfl.gov.uk/bus-sequences.csv'));
|
|
||||||
|
|
||||||
busSequences = BusSequences.fromCSV(response.body);
|
|
||||||
|
|
||||||
print("Loaded bus sequences from TFL");
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
String csv = await rootBundle.loadString("assets/datasets/bus-sequences.csv");
|
|
||||||
|
|
||||||
busSequences = BusSequences.fromCSV(csv);
|
|
||||||
|
|
||||||
print("Loaded bus sequences from assets");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth.isAuthenticated()){
|
|
||||||
print("Auth is authenticated");
|
|
||||||
setupRealtime();
|
|
||||||
} else {
|
|
||||||
print("Auth is not authenticated");
|
|
||||||
auth.onLogin.addListener((value) {
|
|
||||||
setupRealtime();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Timer refreshTimer() => Timer.periodic(const Duration(milliseconds: 100), (timer) async {
|
|
||||||
await updateNtpOffset();
|
|
||||||
_handleAnnouncementQueue();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
int ntpOffset = -1;
|
|
||||||
DateTime lastNtpUpdate = DateTime.now().add(const Duration(seconds: -15));
|
|
||||||
/// updates the NTP offset from DateTime.now()
|
|
||||||
Future<void> updateNtpOffset() async {
|
|
||||||
|
|
||||||
// Only update the NTP offset every 10 seconds
|
|
||||||
if (DateTime.now().difference(lastNtpUpdate).inSeconds < 10) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = await http.get(Uri.parse('http://worldtimeapi.org/api/timezone/Europe/London'));
|
|
||||||
if (res.statusCode == 200) {
|
|
||||||
var json = jsonDecode(res.body);
|
|
||||||
DateTime time = DateTime.parse(json['datetime']);
|
|
||||||
ntpOffset = time.millisecondsSinceEpoch - DateTime.now().millisecondsSinceEpoch;
|
|
||||||
lastNtpUpdate = DateTime.now();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DateTime getNow() {
|
|
||||||
if (ntpOffset == -1) {
|
|
||||||
throw Exception("NTP offset not set");
|
|
||||||
}
|
|
||||||
return DateTime.now().add(Duration(milliseconds: ntpOffset));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AudioWrapper audioPlayer = AudioWrapper();
|
|
||||||
AnnouncementCache announcementCache = AnnouncementCache();
|
|
||||||
List<AnnouncementQueueEntry> announcementQueue = [];
|
|
||||||
DateTime lastAnnouncementTimeStamp = DateTime.now().toUtc();
|
|
||||||
EventDelegate<AnnouncementQueueEntry> announcementDelegate = EventDelegate();
|
|
||||||
String _currentAnnouncement = "*** NO MESSAGE ***";
|
|
||||||
|
|
||||||
String get currentAnnouncement => _currentAnnouncement;
|
|
||||||
void set currentAnnouncement(String value) {
|
|
||||||
_currentAnnouncement = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isPlayingAnnouncement = false;
|
|
||||||
void _handleAnnouncementQueue() async {
|
|
||||||
|
|
||||||
int timerInterval = 100;
|
|
||||||
|
|
||||||
// print("Handling announcement queue");
|
|
||||||
if (!isPlayingAnnouncement) {
|
|
||||||
if (announcementQueue.isNotEmpty) {
|
|
||||||
|
|
||||||
print("Handling announcement queue");
|
|
||||||
|
|
||||||
AnnouncementQueueEntry announcement = announcementQueue.first;
|
|
||||||
|
|
||||||
print("Queue length: ${announcementQueue.length}");
|
|
||||||
|
|
||||||
{
|
|
||||||
DateTime now = getNow();
|
|
||||||
if (announcement.scheduledTime != null) {
|
|
||||||
int milisecondDifference = abs(now.millisecondsSinceEpoch - announcement.scheduledTime!.millisecondsSinceEpoch);
|
|
||||||
// print("Q Difference: ${milisecondDifference}");
|
|
||||||
if (milisecondDifference <= timerInterval) {
|
|
||||||
// Account for the time lost by the periodic timer
|
|
||||||
announcementQueue.remove(announcement);
|
|
||||||
await Future.delayed(Duration(milliseconds: timerInterval - milisecondDifference));
|
|
||||||
} else {
|
|
||||||
print("Due in: ${milisecondDifference}ms");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isPlayingAnnouncement = true;
|
|
||||||
|
|
||||||
if (kIsWeb) {
|
|
||||||
await Future.delayed(Duration(milliseconds: 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
print("Displaying announcement: ${announcement.displayText}");
|
|
||||||
announcementDelegate.trigger(announcement);
|
|
||||||
_currentAnnouncement = announcement.displayText;
|
|
||||||
|
|
||||||
lastAnnouncementTimeStamp = getNow();
|
|
||||||
|
|
||||||
if (announcement.audioSources.isNotEmpty) {
|
|
||||||
try {
|
|
||||||
for (AudioWrapperSource source in announcement.audioSources) {
|
|
||||||
|
|
||||||
Duration? duration = await audioPlayer.play(source);
|
|
||||||
await Future.delayed(duration!);
|
|
||||||
if (announcement.audioSources.last != source) {
|
|
||||||
await Future.delayed(Duration(milliseconds: 500));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
audioPlayer.stop();
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (announcementQueue.isNotEmpty) {
|
|
||||||
await Future.delayed(Duration(seconds: 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (announcementQueue.contains(announcement)) {
|
|
||||||
announcementQueue.remove(announcement);
|
|
||||||
}
|
|
||||||
|
|
||||||
isPlayingAnnouncement = false;
|
|
||||||
print("Popped announcement queue");
|
|
||||||
print("Queue length after: ${announcementQueue.length}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<AnnouncementQueueEntry> _getDestinationAnnouncement(BusRouteVariant routeVariant, {bool sendToServer = false}) async {
|
|
||||||
|
|
||||||
String display = "${routeVariant.busRoute.routeNumber} to ${routeVariant.busStops.last.formattedStopName}";
|
|
||||||
|
|
||||||
String audio_route = "R_${routeVariant.busRoute.routeNumber}_001.mp3";
|
|
||||||
String audio_destination = routeVariant.busStops.last.getAudioFileName();
|
|
||||||
|
|
||||||
// Cache the audio files
|
|
||||||
await announcementCache.loadAnnouncements([audio_route, audio_destination]);
|
|
||||||
|
|
||||||
AudioWrapperSource source_route = AudioWrapperByteSource(announcementCache[audio_route]);
|
|
||||||
AudioWrapperSource source_destination = AudioWrapperByteSource(announcementCache[audio_destination]);
|
|
||||||
|
|
||||||
return AnnouncementQueueEntry(
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
|
|
||||||
displayText: display,
|
|
||||||
audioSources: [source_route, AudioWrapperAssetSource("audio/to_destination.wav"), source_destination]
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<AnnouncementQueueEntry> getDestinationAnnouncement(BusRouteVariant routeVariant, {bool sendToServer = true}) async {
|
|
||||||
return DestinationAnnouncementEntry(
|
|
||||||
routeVariant: routeVariant,
|
|
||||||
audioSources: [],
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
late BusSequences busSequences;
|
|
||||||
BusRouteVariant? _currentRouteVariant;
|
|
||||||
EventDelegate<BusRouteVariant> routeVariantDelegate = EventDelegate();
|
|
||||||
|
|
||||||
Future<void> setRouteVariant(BusRouteVariant routeVariant) async {
|
|
||||||
_currentRouteVariant = routeVariant;
|
|
||||||
routeVariantDelegate.trigger(routeVariant);
|
|
||||||
|
|
||||||
// cache all of the stop announcements
|
|
||||||
|
|
||||||
List<String> audioFiles = [];
|
|
||||||
|
|
||||||
for (BusRouteStops stop in routeVariant.busStops) {
|
|
||||||
audioFiles.add(stop.getAudioFileName());
|
|
||||||
print("Cached stop audio: ${stop.getAudioFileName()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
await announcementCache.loadAnnouncements(audioFiles);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BusRouteVariant? getRouteVariant() {
|
|
||||||
return _currentRouteVariant;
|
|
||||||
}
|
|
||||||
|
|
||||||
void queueAnnouncement(AnnouncementQueueEntry announcement) async {
|
|
||||||
|
|
||||||
|
|
||||||
// Make sure the timestamp of the announcement is after the last announcement
|
|
||||||
// If so, dont queue it
|
|
||||||
// If timestamp is null, then skip this check
|
|
||||||
if (announcement.timestamp != null && announcement.timestamp!.toUtc().isBefore(lastAnnouncementTimeStamp)) {
|
|
||||||
print("Announcement is too old");
|
|
||||||
|
|
||||||
print("LastAnnouncement: $lastAnnouncementTimeStamp");
|
|
||||||
print("Announcement: ${announcement.timestamp}");
|
|
||||||
|
|
||||||
int difference = announcement.timestamp!.difference(lastAnnouncementTimeStamp).inMilliseconds;
|
|
||||||
print("Difference: $difference");
|
|
||||||
return;
|
|
||||||
} else if (announcement.timestamp == null) {
|
|
||||||
print("Announcement `${announcement.displayText}` does not have timestamp");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If there is an announcement in the queue with the same timestamp, dont queue it
|
|
||||||
if (announcementQueue.any((element) => element.timestamp == announcement.timestamp)) {
|
|
||||||
print("Announcement with same timestamp already in queue");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!announcement.sendToServer) {
|
|
||||||
|
|
||||||
if (announcement is DestinationAnnouncementEntry) {
|
|
||||||
|
|
||||||
BusRouteVariant routeVariant = announcement.routeVariant;
|
|
||||||
|
|
||||||
if (getRouteVariant() != routeVariant) {
|
|
||||||
setRouteVariant(routeVariant);
|
|
||||||
}
|
|
||||||
|
|
||||||
announcementQueue.add(
|
|
||||||
await _getDestinationAnnouncement(
|
|
||||||
routeVariant,
|
|
||||||
sendToServer: false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
print("Queued destination announcement: ${announcement.displayText}");
|
|
||||||
print("Audios: ${announcement.audioSources.length}");
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else if (announcement is ManualAnnouncementEntry) {
|
|
||||||
|
|
||||||
List<AudioWrapperSource> audioSources = [];
|
|
||||||
|
|
||||||
for (String filename in announcement.audioFileNames) {
|
|
||||||
audioSources.add(AudioWrapperByteSource(announcementCache[filename]));
|
|
||||||
}
|
|
||||||
|
|
||||||
announcementQueue.add(
|
|
||||||
ManualAnnouncementEntry(
|
|
||||||
shortName: announcement.shortName,
|
|
||||||
informationText: announcement.displayText,
|
|
||||||
audioFileNames: announcement.audioFileNames,
|
|
||||||
audioSources: audioSources,
|
|
||||||
sendToServer: false,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
print("Queued manual announcement: ${announcement.displayText} (no server)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
announcementQueue.add(announcement);
|
|
||||||
print("Queued announcement: ${announcement.displayText} (no server)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final databases = appwrite.Databases(auth.client);
|
|
||||||
|
|
||||||
print("Queuing announcement: ${announcement.displayText} (server)");
|
|
||||||
print("Announcement type: ${announcement.runtimeType}");
|
|
||||||
|
|
||||||
if (announcement.runtimeType == InformationAnnouncementEntry) {
|
|
||||||
announcement as InformationAnnouncementEntry;
|
|
||||||
print("Queing to InformationAnnouncementEntry");
|
|
||||||
|
|
||||||
// 5 sedonds in the future
|
|
||||||
DateTime scheduledTime = (await getNow()).add(Duration(seconds: 1));
|
|
||||||
|
|
||||||
|
|
||||||
final document = databases.createDocument(
|
|
||||||
documentId: appwrite.ID.unique(),
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.INFORMATION_Q_COLLECTION_ID,
|
|
||||||
data: {
|
|
||||||
"ManualAnnouncementIndex": manualAnnouncements.indexOf(announcement),
|
|
||||||
"ScheduledTime": scheduledTime.toIso8601String(),
|
|
||||||
"SessionID": sessionID,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
print("Queued manual announcement: ${announcement.shortName} (server)");
|
|
||||||
|
|
||||||
} else if (announcement.runtimeType == ManualAnnouncementEntry) {
|
|
||||||
announcement as ManualAnnouncementEntry;
|
|
||||||
print("Queing to ManualAnnouncementEntry");
|
|
||||||
|
|
||||||
// 5 sedonds in the future
|
|
||||||
DateTime scheduledTime = (await getNow()).add(Duration(seconds: 1));
|
|
||||||
|
|
||||||
final document = databases.createDocument(
|
|
||||||
documentId: appwrite.ID.unique(),
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.MANUAL_Q_COLLECTION_ID,
|
|
||||||
data: {
|
|
||||||
"DisplayText": announcement.displayText,
|
|
||||||
"AudioFileNames": announcement.audioFileNames,
|
|
||||||
|
|
||||||
"ScheduledTime": scheduledTime.toIso8601String(),
|
|
||||||
"SessionID": sessionID,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
print("Queued manual announcement: ${announcement.shortName}");
|
|
||||||
|
|
||||||
} else if (announcement.runtimeType == DestinationAnnouncementEntry) {
|
|
||||||
announcement as DestinationAnnouncementEntry;
|
|
||||||
print("Queing to DestinationAnnouncementEntry");
|
|
||||||
|
|
||||||
// 5 sedonds in the future
|
|
||||||
DateTime scheduledTime = (getNow()).add(Duration(seconds: 2));
|
|
||||||
|
|
||||||
final document = databases.createDocument(
|
|
||||||
documentId: appwrite.ID.unique(),
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.DEST_Q_COLLECTION_ID,
|
|
||||||
data: {
|
|
||||||
"RouteNumber": announcement.routeVariant.busRoute.routeNumber,
|
|
||||||
"RouteVariantIndex": announcement.routeVariant.routeVariant,
|
|
||||||
|
|
||||||
"ScheduledTime": scheduledTime.toIso8601String(),
|
|
||||||
"SessionID": sessionID,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
print("Queued manual announcement: ${announcement.shortName} (server)");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
List<InformationAnnouncementEntry> manualAnnouncements = [
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Driver Change",
|
|
||||||
informationText: "Driver Change",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/driverchange.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "No Standing Upr Deck",
|
|
||||||
informationText: "No standing on the upper deck",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/nostanding.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Face Covering",
|
|
||||||
informationText: "Please wear a face covering!",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/facecovering.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Seats Upstairs",
|
|
||||||
informationText: "Seats are available upstairs",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/seatsupstairs.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Bus Terminates Here",
|
|
||||||
informationText: "Bus terminates here. Please take your belongings with you",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/busterminateshere.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Bus On Diversion",
|
|
||||||
informationText: "Bus on diversion. Please listen for further announcements",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/busondiversion.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Destination Change",
|
|
||||||
informationText: "Destination Changed - please listen for further instructions",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/destinationchange.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Wheelchair Space",
|
|
||||||
informationText: "Wheelchair space requested",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/wheelchairspace1.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Move Down The Bus",
|
|
||||||
informationText: "Please move down the bus",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/movedownthebus.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Next Stop Closed",
|
|
||||||
informationText: "The next bus stop is closed",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/nextstopclosed.wav")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "CCTV In Operation",
|
|
||||||
informationText: "CCTV is in operation on this bus",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/cctvoperation.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Safe Door Opening",
|
|
||||||
informationText: "Driver will open the doors when it is safe to do so",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/safedooropening.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Buggy Safety",
|
|
||||||
informationText: "For your child's safety, please remain with your buggy",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/buggysafety.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Wheelchair Space 2",
|
|
||||||
informationText: "Wheelchair priority space required",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/wheelchairspace2.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Service Regulation",
|
|
||||||
informationText: "Regulating service - please listen for further information",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/serviceregulation.mp3")],
|
|
||||||
),
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: "Bus Ready To Depart",
|
|
||||||
informationText: "This bus is ready to depart",
|
|
||||||
audioSources: [AudioWrapperAssetSource("audio/manual_announcements/readytodepart.mp3")],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
AuthAPI auth = AuthAPI();
|
|
||||||
String sessionID = "65de648aa7f44684ecce";
|
|
||||||
void updateServer() async {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final databases = appwrite.Databases(auth.client);
|
|
||||||
|
|
||||||
// final document = databases.updateDocument(
|
|
||||||
// databaseId: ApiConstants.INFO_DATABASE_ID,
|
|
||||||
// collectionId: ApiConstants.INFO_COLLECTION_ID,
|
|
||||||
// documentId: documentID,
|
|
||||||
// data: {
|
|
||||||
// "Display": _currentAnnouncement,
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
print("Updated server with announcement: $_currentAnnouncement");
|
|
||||||
|
|
||||||
}
|
|
||||||
void pullServer() async {
|
|
||||||
|
|
||||||
if (auth.status == AuthStatus.UNAUTHENTICATED) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final databases = appwrite.Databases(auth.client);
|
|
||||||
|
|
||||||
// final document = await databases.getDocument(
|
|
||||||
// databaseId: ApiConstants.INFO_DATABASE_ID,
|
|
||||||
// collectionId: ApiConstants.INFO_COLLECTION_ID,
|
|
||||||
// documentId: documentID,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// queueAnnouncement(AnnouncementQueueEntry(
|
|
||||||
// displayText: document.data['Display'],
|
|
||||||
// audioSources: [],
|
|
||||||
// sendToServer: false, // Don't send this back to the server, else we'll get an infinite loop
|
|
||||||
// ));
|
|
||||||
|
|
||||||
// print("Pulled announcement from server: ${document.data['Display']}");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool purgeRunning = false;
|
|
||||||
Future<void> deleteAllManualQueueEntries() async {
|
|
||||||
|
|
||||||
if (purgeRunning) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
purgeRunning = true;
|
|
||||||
|
|
||||||
final databases = appwrite.Databases(auth.client);
|
|
||||||
int offset = 0;
|
|
||||||
const int limit = 25; // Maximum number of documents that can be fetched at once
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
// Fetch a page of documents from the manual queue collection
|
|
||||||
print("Deleting manual queue entries");
|
|
||||||
final manual_q = await databases.listDocuments(
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.MANUAL_Q_COLLECTION_ID,
|
|
||||||
queries: [
|
|
||||||
appwrite.Query.search("SessionID", sessionID),
|
|
||||||
appwrite.Query.limit(limit),
|
|
||||||
appwrite.Query.offset(offset),
|
|
||||||
appwrite.Query.orderDesc('\$createdAt')
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// If there are no documents in the fetched page, break the loop
|
|
||||||
if (manual_q.documents.isEmpty) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete each document in the fetched page
|
|
||||||
for (models.Document doc in manual_q.documents) {
|
|
||||||
await databases.deleteDocument(
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.MANUAL_Q_COLLECTION_ID,
|
|
||||||
documentId: doc.$id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go to the next page
|
|
||||||
offset += limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Deleted all manual queue entries");
|
|
||||||
}
|
|
||||||
|
|
||||||
void pullQueue() async {
|
|
||||||
|
|
||||||
if (auth.status == AuthStatus.UNAUTHENTICATED) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AnnouncementQueueEntry> queue = [];
|
|
||||||
|
|
||||||
final databases = appwrite.Databases(auth.client);
|
|
||||||
|
|
||||||
// Pull the information queue
|
|
||||||
{
|
|
||||||
final manual_q = await databases.listDocuments(
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.INFORMATION_Q_COLLECTION_ID,
|
|
||||||
queries: [
|
|
||||||
appwrite.Query.search("SessionID", sessionID),
|
|
||||||
appwrite.Query.limit(25),
|
|
||||||
appwrite.Query.offset(0),
|
|
||||||
appwrite.Query.orderDesc('\$createdAt')
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
for (models.Document doc in manual_q.documents) {
|
|
||||||
int index = doc.data['ManualAnnouncementIndex'];
|
|
||||||
|
|
||||||
InformationAnnouncementEntry announcement_clone =
|
|
||||||
InformationAnnouncementEntry(
|
|
||||||
shortName: manualAnnouncements[index].shortName,
|
|
||||||
informationText: manualAnnouncements[index].displayText,
|
|
||||||
audioSources: manualAnnouncements[index].audioSources,
|
|
||||||
scheduledTime: doc.data["ScheduledTime"] != null
|
|
||||||
? DateTime.parse(doc.data["ScheduledTime"])
|
|
||||||
: null,
|
|
||||||
timestamp: DateTime.parse(doc.$createdAt),
|
|
||||||
sendToServer: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// sort the queue by timestamp, so the oldest announcements are at the front
|
|
||||||
|
|
||||||
queue.add(announcement_clone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pull the destination queue
|
|
||||||
{
|
|
||||||
final dest_q = await databases.listDocuments(
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.DEST_Q_COLLECTION_ID,
|
|
||||||
queries: [
|
|
||||||
appwrite.Query.search("SessionID", sessionID),
|
|
||||||
appwrite.Query.limit(25),
|
|
||||||
appwrite.Query.offset(0),
|
|
||||||
appwrite.Query.orderDesc('\$createdAt')
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
for (models.Document doc in dest_q.documents) {
|
|
||||||
|
|
||||||
BusRoute? route = busSequences.routes[doc.data["RouteNumber"]];
|
|
||||||
|
|
||||||
BusRouteVariant? routeVariant = route!.routeVariants[doc.data["RouteVariantIndex"]];
|
|
||||||
|
|
||||||
|
|
||||||
DestinationAnnouncementEntry announcement_clone =
|
|
||||||
DestinationAnnouncementEntry(
|
|
||||||
routeVariant: routeVariant!,
|
|
||||||
scheduledTime: doc.data["ScheduledTime"] != null
|
|
||||||
? DateTime.parse(doc.data["ScheduledTime"])
|
|
||||||
: null,
|
|
||||||
timestamp: DateTime.parse(doc.$createdAt),
|
|
||||||
sendToServer: false,
|
|
||||||
audioSources: [],
|
|
||||||
);
|
|
||||||
|
|
||||||
// sort the queue by timestamp, so the oldest announcements are at the front
|
|
||||||
|
|
||||||
queue.add(announcement_clone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pull the manual queue
|
|
||||||
{
|
|
||||||
final manual_q = await databases.listDocuments(
|
|
||||||
databaseId: ApiConstants.INFO_Q_DATABASE_ID,
|
|
||||||
collectionId: ApiConstants.MANUAL_Q_COLLECTION_ID,
|
|
||||||
queries: [
|
|
||||||
appwrite.Query.search("SessionID", sessionID),
|
|
||||||
appwrite.Query.limit(25),
|
|
||||||
appwrite.Query.offset(0),
|
|
||||||
appwrite.Query.orderDesc('\$createdAt')
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
for (models.Document doc in manual_q.documents) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<String> audioFileNames = doc.data["AudioFileNames"].cast<String>();
|
|
||||||
|
|
||||||
ManualAnnouncementEntry announcement_clone =
|
|
||||||
ManualAnnouncementEntry(
|
|
||||||
sendToServer: false,
|
|
||||||
|
|
||||||
shortName: "",
|
|
||||||
informationText: doc.data["DisplayText"],
|
|
||||||
audioFileNames: audioFileNames,
|
|
||||||
|
|
||||||
scheduledTime: doc.data["ScheduledTime"] != null
|
|
||||||
? DateTime.parse(doc.data["ScheduledTime"])
|
|
||||||
: null,
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// sort the queue by timestamp, so the oldest announcements are at the front
|
|
||||||
|
|
||||||
queue.add(announcement_clone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (AnnouncementQueueEntry entry in queue) {
|
|
||||||
|
|
||||||
// Dont queue announcements that are older than now
|
|
||||||
if (entry.scheduledTime != null && entry.scheduledTime!.isBefore(await getNow())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
queueAnnouncement(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
appwrite.RealtimeSubscription? information_q_subscription;
|
|
||||||
appwrite.RealtimeSubscription? manual_q_subscription;
|
|
||||||
appwrite.RealtimeSubscription? destination_q_subscription;
|
|
||||||
|
|
||||||
Future<void> setupRealtime() async {
|
|
||||||
|
|
||||||
if (information_q_subscription != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// await deleteAllManualQueueEntries(); //todo
|
|
||||||
|
|
||||||
print("Setting up realtime");
|
|
||||||
|
|
||||||
// Websocket
|
|
||||||
appwrite.Realtime realtime = appwrite.Realtime(auth.client);
|
|
||||||
|
|
||||||
information_q_subscription = realtime.subscribe(
|
|
||||||
['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.INFORMATION_Q_COLLECTION_ID}.documents'],
|
|
||||||
);
|
|
||||||
information_q_subscription?.stream.listen((event) {
|
|
||||||
print("Manual queue entry added");
|
|
||||||
|
|
||||||
pullQueue();
|
|
||||||
});
|
|
||||||
|
|
||||||
manual_q_subscription = realtime.subscribe(
|
|
||||||
['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.MANUAL_Q_COLLECTION_ID}.documents'],
|
|
||||||
);
|
|
||||||
manual_q_subscription?.stream.listen((event) {
|
|
||||||
print("Manual queue entry added");
|
|
||||||
|
|
||||||
pullQueue();
|
|
||||||
});
|
|
||||||
|
|
||||||
destination_q_subscription = realtime.subscribe(
|
|
||||||
['databases.${ApiConstants.INFO_Q_DATABASE_ID}.collections.${ApiConstants.DEST_Q_COLLECTION_ID}.documents'],
|
|
||||||
);
|
|
||||||
destination_q_subscription?.stream.listen((event) {
|
|
||||||
print("Destination queue entry added");
|
|
||||||
|
|
||||||
pullQueue();
|
|
||||||
});
|
|
||||||
|
|
||||||
print("Subscribed to servers");
|
|
||||||
|
|
||||||
await Future.delayed(Duration(seconds: 90));
|
|
||||||
|
|
||||||
information_q_subscription?.close();
|
|
||||||
information_q_subscription = null;
|
|
||||||
manual_q_subscription?.close();
|
|
||||||
manual_q_subscription = null;
|
|
||||||
destination_q_subscription?.close();
|
|
||||||
destination_q_subscription = null;
|
|
||||||
print("Restarting realtime");
|
|
||||||
setupRealtime();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnnouncementQueueEntry {
|
|
||||||
final String displayText;
|
|
||||||
final List<AudioWrapperSource> audioSources;
|
|
||||||
bool sendToServer = true;
|
|
||||||
DateTime? scheduledTime;
|
|
||||||
DateTime? timestamp;
|
|
||||||
|
|
||||||
AnnouncementQueueEntry({required this.displayText, required this.audioSources, this.sendToServer = true, this.scheduledTime, this.timestamp});
|
|
||||||
}
|
|
||||||
|
|
||||||
class NamedAnnouncementQueueEntry extends AnnouncementQueueEntry {
|
|
||||||
final String shortName;
|
|
||||||
|
|
||||||
NamedAnnouncementQueueEntry({
|
|
||||||
required this.shortName,
|
|
||||||
required String displayText,
|
|
||||||
required List<AudioWrapperSource> audioSources,
|
|
||||||
DateTime? scheduledTime,
|
|
||||||
DateTime? timestamp,
|
|
||||||
bool sendToServer = true,
|
|
||||||
}) : super(
|
|
||||||
displayText: displayText,
|
|
||||||
audioSources: audioSources,
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
scheduledTime: scheduledTime,
|
|
||||||
timestamp: timestamp,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ManualAnnouncementEntry extends NamedAnnouncementQueueEntry {
|
|
||||||
|
|
||||||
final List<String> audioFileNames;
|
|
||||||
|
|
||||||
ManualAnnouncementEntry({
|
|
||||||
required String shortName,
|
|
||||||
required String informationText,
|
|
||||||
required this.audioFileNames,
|
|
||||||
List<AudioWrapperSource> audioSources = const [],
|
|
||||||
DateTime? scheduledTime,
|
|
||||||
DateTime? timestamp,
|
|
||||||
bool sendToServer = true,
|
|
||||||
}) : super(
|
|
||||||
shortName: shortName,
|
|
||||||
displayText: informationText,
|
|
||||||
audioSources: audioSources,
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
scheduledTime: scheduledTime,
|
|
||||||
timestamp: timestamp,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class InformationAnnouncementEntry extends NamedAnnouncementQueueEntry {
|
|
||||||
|
|
||||||
|
|
||||||
InformationAnnouncementEntry({
|
|
||||||
required String shortName,
|
|
||||||
required String informationText,
|
|
||||||
required List<AudioWrapperSource> audioSources,
|
|
||||||
DateTime? scheduledTime,
|
|
||||||
DateTime? timestamp,
|
|
||||||
bool sendToServer = true,
|
|
||||||
}) : super(
|
|
||||||
shortName: shortName,
|
|
||||||
displayText: informationText,
|
|
||||||
audioSources: audioSources,
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
scheduledTime: scheduledTime,
|
|
||||||
timestamp: timestamp,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
class DestinationAnnouncementEntry extends NamedAnnouncementQueueEntry {
|
|
||||||
|
|
||||||
final BusRouteVariant routeVariant;
|
|
||||||
|
|
||||||
DestinationAnnouncementEntry({
|
|
||||||
required this.routeVariant,
|
|
||||||
required List<AudioWrapperSource> audioSources,
|
|
||||||
DateTime? scheduledTime,
|
|
||||||
DateTime? timestamp,
|
|
||||||
bool sendToServer = true,
|
|
||||||
}) : super(
|
|
||||||
shortName: "Destination",
|
|
||||||
displayText: "${routeVariant.busRoute.routeNumber} to ${routeVariant.busStops.last.formattedStopName}",
|
|
||||||
audioSources: audioSources,
|
|
||||||
sendToServer: sendToServer,
|
|
||||||
scheduledTime: scheduledTime,
|
|
||||||
timestamp: timestamp,
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var abs = (int value) => value < 0 ? -value : value;
|
|
||||||
@@ -3,24 +3,64 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:bus_infotainment/audio_cache.dart';
|
import 'package:bus_infotainment/audio_cache.dart';
|
||||||
|
import 'package:bus_infotainment/backend/live_information.dart';
|
||||||
|
import 'package:bus_infotainment/backend/modules/info_module.dart';
|
||||||
import 'package:bus_infotainment/utils/NameBeautify.dart';
|
import 'package:bus_infotainment/utils/NameBeautify.dart';
|
||||||
|
import 'package:bus_infotainment/utils/OrdinanceSurveyUtils.dart';
|
||||||
import 'package:csv/csv.dart';
|
import 'package:csv/csv.dart';
|
||||||
|
import 'package:vector_math/vector_math.dart';
|
||||||
|
|
||||||
class BusSequences {
|
class BusSequences extends InfoModule {
|
||||||
|
|
||||||
Map<String, BusRoute> routes = {};
|
Map<String, BusRoute> routes = {};
|
||||||
|
|
||||||
BusSequences.fromCSV(String csv) {
|
Map<String, BusDestination> destinations = {};
|
||||||
|
|
||||||
List<List<dynamic>> rowsAsListOfValues = const CsvToListConverter().convert(csv);
|
BusSequences.fromCSV(String destinationsCSV, String busSequencesCSV) {
|
||||||
|
|
||||||
rowsAsListOfValues.removeAt(0);
|
// Init the bus destinations
|
||||||
|
List<List<dynamic>> destinationRows = const CsvToListConverter().convert(destinationsCSV);
|
||||||
for (int i = 0; i < rowsAsListOfValues.length; i++) {
|
destinationRows.removeAt(0);
|
||||||
|
|
||||||
|
for (int i = 0; i < destinationRows.length; i++) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<dynamic> entries = rowsAsListOfValues[i];
|
List<dynamic> entries = destinationRows[i];
|
||||||
|
|
||||||
|
String routeNumber = entries[0].toString();
|
||||||
|
|
||||||
|
BusRoute route = routes.containsKey(routeNumber) ? routes[routeNumber]! : BusRoute(routeNumber: routeNumber);
|
||||||
|
|
||||||
|
String blind = entries[1].toString();
|
||||||
|
|
||||||
|
double lat = double.parse(entries[2].toString());
|
||||||
|
double long = double.parse(entries[3].toString());
|
||||||
|
|
||||||
|
Vector2 grid = OSGrid.toNorthingEasting(lat, long);
|
||||||
|
|
||||||
|
BusDestination destination = BusDestination();
|
||||||
|
destination.destination = blind;
|
||||||
|
destination.easting = grid.x;
|
||||||
|
destination.northing = grid.y;
|
||||||
|
|
||||||
|
route.destinations.add(destination);
|
||||||
|
|
||||||
|
routes[routeNumber] = route;
|
||||||
|
destinations[blind] = destination;
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init the bus routes
|
||||||
|
|
||||||
|
List<List<dynamic>> busSequenceRows = const CsvToListConverter().convert(busSequencesCSV);
|
||||||
|
busSequenceRows.removeAt(0);
|
||||||
|
|
||||||
|
for (int i = 0; i < busSequenceRows.length; i++) {
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
List<dynamic> entries = busSequenceRows[i];
|
||||||
|
|
||||||
String routeNumber = entries[0].toString();
|
String routeNumber = entries[0].toString();
|
||||||
|
|
||||||
@@ -28,26 +68,29 @@ class BusSequences {
|
|||||||
|
|
||||||
int routeVariant = entries[1];
|
int routeVariant = entries[1];
|
||||||
|
|
||||||
BusRouteVariant variant = route.routeVariants.containsKey(routeVariant) ? route.routeVariants[routeVariant]! : BusRouteVariant(routeVariant: routeVariant, busRoute: route);
|
BusRouteStop stop = BusRouteStop();
|
||||||
|
|
||||||
BusRouteStops stop = BusRouteStops();
|
|
||||||
|
|
||||||
stop.stopName = entries[6].toString();
|
stop.stopName = entries[6].toString();
|
||||||
stop.stopCode = entries[4].toString();
|
stop.stopCode = entries[4].toString();
|
||||||
stop.easting = entries[7];
|
stop.easting = entries[7];
|
||||||
stop.northing = entries[8];
|
stop.northing = entries[8];
|
||||||
|
stop.heading = entries[9] != "" ? entries[9] : -1;
|
||||||
|
|
||||||
|
BusRouteVariant variant = route.routeVariants.containsKey(routeVariant) ? route.routeVariants[routeVariant]! : BusRouteVariant(routeVariant: routeVariant, busRoute: route);
|
||||||
|
|
||||||
variant.busStops.add(stop);
|
variant.busStops.add(stop);
|
||||||
|
|
||||||
|
|
||||||
route.routeVariants[routeVariant] = variant;
|
route.routeVariants[routeVariant] = variant;
|
||||||
routes[routeNumber] = route;
|
routes[routeNumber] = route;
|
||||||
|
|
||||||
} catch (e) {
|
}
|
||||||
// print("Error parsing bus sequence: $e");
|
catch (e) {
|
||||||
|
print("Error parsing bus sequence: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +98,8 @@ class BusRoute {
|
|||||||
|
|
||||||
String routeNumber = "";
|
String routeNumber = "";
|
||||||
|
|
||||||
|
List<BusDestination> destinations = [];
|
||||||
|
|
||||||
AnnouncementCache? announcementCache;
|
AnnouncementCache? announcementCache;
|
||||||
|
|
||||||
Map<int, BusRouteVariant> routeVariants = {};
|
Map<int, BusRouteVariant> routeVariants = {};
|
||||||
@@ -70,7 +115,7 @@ class BusRouteVariant {
|
|||||||
|
|
||||||
int routeVariant = -1;
|
int routeVariant = -1;
|
||||||
|
|
||||||
List<BusRouteStops> busStops = [];
|
List<BusRouteStop> busStops = [];
|
||||||
|
|
||||||
late BusRoute busRoute;
|
late BusRoute busRoute;
|
||||||
|
|
||||||
@@ -78,14 +123,66 @@ class BusRouteVariant {
|
|||||||
this.routeVariant = -1,
|
this.routeVariant = -1,
|
||||||
required this.busRoute,
|
required this.busRoute,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BusDestination? _destination;
|
||||||
|
BusDestination? get destination {
|
||||||
|
if (_destination == null) {
|
||||||
|
|
||||||
|
// Get the nearest destination
|
||||||
|
BusDestination? nearestDestinationA;
|
||||||
|
double nearestDistanceA = double.infinity;
|
||||||
|
|
||||||
|
Vector2 stopLocation = Vector2(busStops.last.northing.toDouble(), busStops.last.easting.toDouble());
|
||||||
|
|
||||||
|
for (BusDestination destination in busRoute.destinations) {
|
||||||
|
|
||||||
|
Vector2 destinationLocation = Vector2(destination.northing.toDouble(), destination.easting.toDouble());
|
||||||
|
|
||||||
|
double distance = stopLocation.distanceTo(destinationLocation);
|
||||||
|
|
||||||
|
if (distance < nearestDistanceA) {
|
||||||
|
nearestDestinationA = destination;
|
||||||
|
nearestDistanceA = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the nearest destination from global pool of destinations
|
||||||
|
BusDestination? nearestDestinationB;
|
||||||
|
double nearestDistanceB = double.infinity;
|
||||||
|
|
||||||
|
for (BusDestination destination in LiveInformation().busSequences.destinations.values) {
|
||||||
|
|
||||||
|
Vector2 destinationLocation = Vector2(destination.northing.toDouble(), destination.easting.toDouble());
|
||||||
|
|
||||||
|
double distance = stopLocation.distanceTo(destinationLocation);
|
||||||
|
|
||||||
|
if (distance < nearestDistanceB) {
|
||||||
|
nearestDestinationB = destination;
|
||||||
|
nearestDistanceB = distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose the nearest destination
|
||||||
|
if (nearestDistanceA < nearestDistanceB) {
|
||||||
|
_destination = nearestDestinationA;
|
||||||
|
} else {
|
||||||
|
_destination = nearestDestinationB;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return _destination;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BusRouteStops {
|
class BusRouteStop {
|
||||||
|
|
||||||
String stopName = "";
|
String stopName = "";
|
||||||
|
|
||||||
int easting = -1;
|
int easting = -1;
|
||||||
int northing = -1;
|
int northing = -1;
|
||||||
|
int heading = -1;
|
||||||
|
|
||||||
String stopCode = "";
|
String stopCode = "";
|
||||||
|
|
||||||
@@ -123,3 +220,59 @@ class BusRouteStops {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BusDestination {
|
||||||
|
|
||||||
|
String destination = "";
|
||||||
|
|
||||||
|
double easting = -1;
|
||||||
|
double northing = -1;
|
||||||
|
|
||||||
|
Future<Uint8List> getAudioBytes() async {
|
||||||
|
|
||||||
|
// Convert the stop name to all caps
|
||||||
|
String name = destination.toUpperCase();
|
||||||
|
|
||||||
|
name = NameBeautify.beautifyStopName(name);
|
||||||
|
|
||||||
|
// replace & with N
|
||||||
|
name = name.replaceAll('&', 'N');
|
||||||
|
|
||||||
|
name = name.replaceAll('/', '');
|
||||||
|
|
||||||
|
name = name.replaceAll('\'', '');
|
||||||
|
|
||||||
|
name = name.replaceAll(' ', ' ');
|
||||||
|
|
||||||
|
// Replace space with underscore
|
||||||
|
name = name.replaceAll(' ', '_');
|
||||||
|
|
||||||
|
// convert to all caps
|
||||||
|
name = name.toUpperCase();
|
||||||
|
|
||||||
|
String audioNameA = "D_${name}_001.mp3";
|
||||||
|
String audioNameB = "S_${name}_001.mp3";
|
||||||
|
String audioNameC = "A_${name}_001.mp3";
|
||||||
|
|
||||||
|
print("Audio name A: $audioNameA");
|
||||||
|
print("Audio name B: $audioNameB");
|
||||||
|
print("Audio name C: $audioNameC");
|
||||||
|
|
||||||
|
await LiveInformation().announcementModule.announcementCache.loadAnnouncements([audioNameA, audioNameB, audioNameC]);
|
||||||
|
|
||||||
|
Uint8List? audioBytesA = LiveInformation().announcementModule.announcementCache[audioNameA];
|
||||||
|
Uint8List? audioBytesB = LiveInformation().announcementModule.announcementCache[audioNameB];
|
||||||
|
Uint8List? audioBytesC = LiveInformation().announcementModule.announcementCache[audioNameC];
|
||||||
|
|
||||||
|
if (audioBytesA != null) return audioBytesA;
|
||||||
|
if (audioBytesB != null) return audioBytesB;
|
||||||
|
if (audioBytesC != null) return audioBytesC;
|
||||||
|
|
||||||
|
print("No audio bytes found for $name");
|
||||||
|
|
||||||
|
return Uint8List(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
35
lib/utils/OrdinanceSurveyUtils.dart
Normal file
35
lib/utils/OrdinanceSurveyUtils.dart
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
import 'package:proj4dart/proj4dart.dart' as proj4;
|
||||||
|
import 'package:vector_math/vector_math.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class OSGrid {
|
||||||
|
|
||||||
|
static List<double> toLatLong(double northing, double easting) {
|
||||||
|
|
||||||
|
final sourceProjection = proj4.Projection.parse('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 '
|
||||||
|
'+x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'); // British National Grid
|
||||||
|
final destinationProjection = proj4.Projection.WGS84;// WGS84
|
||||||
|
|
||||||
|
final point = proj4.Point(x: easting, y: northing);
|
||||||
|
final transformedPoint = sourceProjection.transform(destinationProjection, point);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [transformedPoint.y, transformedPoint.x];
|
||||||
|
}
|
||||||
|
|
||||||
|
static Vector2 toNorthingEasting(double latitude, double longitude) {
|
||||||
|
|
||||||
|
final sourceProjection = proj4.Projection.WGS84;// WGS84
|
||||||
|
final destinationProjection = proj4.Projection.parse('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 '
|
||||||
|
'+x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'); // British National Grid
|
||||||
|
|
||||||
|
final point = proj4.Point(x: longitude, y: latitude);
|
||||||
|
final transformedPoint = sourceProjection.transform(destinationProjection, point);
|
||||||
|
|
||||||
|
return Vector2(transformedPoint.x, transformedPoint.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,11 @@ import 'package:audioplayers/audioplayers.dart' as audioplayers;
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:just_audio/just_audio.dart' as justaudio;
|
import 'package:just_audio/just_audio.dart' as justaudio;
|
||||||
|
|
||||||
|
enum AudioWrapper_Mode {
|
||||||
|
Web,
|
||||||
|
Mobile
|
||||||
|
}
|
||||||
|
|
||||||
enum AudioWrapper_State {
|
enum AudioWrapper_State {
|
||||||
Playing,
|
Playing,
|
||||||
NotPlaying
|
NotPlaying
|
||||||
@@ -13,6 +18,16 @@ class AudioWrapper {
|
|||||||
audioplayers.AudioPlayer _audioPlayer_AudioPlayer = audioplayers.AudioPlayer();
|
audioplayers.AudioPlayer _audioPlayer_AudioPlayer = audioplayers.AudioPlayer();
|
||||||
justaudio.AudioPlayer _justAudio_AudioPlayer = justaudio.AudioPlayer();
|
justaudio.AudioPlayer _justAudio_AudioPlayer = justaudio.AudioPlayer();
|
||||||
|
|
||||||
|
AudioWrapper_Mode mode = kIsWeb ? AudioWrapper_Mode.Web : AudioWrapper_Mode.Mobile;
|
||||||
|
|
||||||
|
AudioWrapper() {
|
||||||
|
// mode = AudioWrapper_Mode.Web;
|
||||||
|
|
||||||
|
print("AudioWrapper mode: $mode");
|
||||||
|
|
||||||
|
// mode = AudioWrapper_Mode.Mobile;
|
||||||
|
}
|
||||||
|
|
||||||
justaudio.AudioSource _convertSource_JustAudio(AudioWrapperSource source){
|
justaudio.AudioSource _convertSource_JustAudio(AudioWrapperSource source){
|
||||||
if (source is AudioWrapperByteSource){
|
if (source is AudioWrapperByteSource){
|
||||||
return _ByteSource(source.bytes);
|
return _ByteSource(source.bytes);
|
||||||
@@ -33,45 +48,94 @@ class AudioWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Duration?> play(AudioWrapperSource source) async {
|
|
||||||
|
|
||||||
Duration? duration;
|
Future<void> loadSource(AudioWrapperSource source) async {
|
||||||
|
if (mode == AudioWrapper_Mode.Web) {
|
||||||
if (kIsWeb) {
|
|
||||||
// Use just_audio
|
// Use just_audio
|
||||||
|
|
||||||
justaudio.AudioSource audioSource = _convertSource_JustAudio(source);
|
justaudio.AudioSource audioSource = _convertSource_JustAudio(source);
|
||||||
|
|
||||||
duration = await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
||||||
|
|
||||||
_justAudio_AudioPlayer.play();
|
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Use audioplayers
|
// Use audioplayers
|
||||||
|
|
||||||
audioplayers.Source audioSource = _convertSource_AudioPlayers(source);
|
audioplayers.Source audioSource = _convertSource_AudioPlayers(source);
|
||||||
|
|
||||||
await _audioPlayer_AudioPlayer.play(audioSource);
|
await _audioPlayer_AudioPlayer.setSource(audioSource);
|
||||||
|
// await _audioPlayer_AudioPlayer.play(audioSource);
|
||||||
duration = await _audioPlayer_AudioPlayer.getDuration();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Duration?> getDuration() async {
|
||||||
|
if (mode == AudioWrapper_Mode.Web) {
|
||||||
|
return _justAudio_AudioPlayer.duration;
|
||||||
|
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||||
|
return await _audioPlayer_AudioPlayer.getDuration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Duration?> play() async {
|
||||||
|
|
||||||
|
Duration? duration;
|
||||||
|
|
||||||
|
if (mode == AudioWrapper_Mode.Web) {
|
||||||
|
_justAudio_AudioPlayer.play();
|
||||||
|
duration = _justAudio_AudioPlayer.duration;
|
||||||
|
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||||
|
_audioPlayer_AudioPlayer.resume();
|
||||||
|
duration = await _audioPlayer_AudioPlayer.getDuration();
|
||||||
|
}
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Future<Duration?> play(AudioWrapperSource source) async {
|
||||||
|
//
|
||||||
|
// Duration? duration;
|
||||||
|
//
|
||||||
|
// if (mode == AudioWrapper_Mode.Web) {
|
||||||
|
// // Use just_audio
|
||||||
|
//
|
||||||
|
// justaudio.AudioSource audioSource = _convertSource_JustAudio(source);
|
||||||
|
//
|
||||||
|
// duration = await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
||||||
|
//
|
||||||
|
// _justAudio_AudioPlayer.play();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// } else if (mode == AudioWrapper_Mode.Mobile) {
|
||||||
|
// // Use audioplayers
|
||||||
|
//
|
||||||
|
// audioplayers.Source audioSource = _convertSource_AudioPlayers(source);
|
||||||
|
//
|
||||||
|
// await _audioPlayer_AudioPlayer.play(audioSource);
|
||||||
|
//
|
||||||
|
// duration = await _audioPlayer_AudioPlayer.getDuration();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return duration;
|
||||||
|
// }
|
||||||
|
|
||||||
void stop(){
|
void stop(){
|
||||||
if (kIsWeb) {
|
if (mode == AudioWrapper_Mode.Web) {
|
||||||
_justAudio_AudioPlayer.stop();
|
_justAudio_AudioPlayer.stop();
|
||||||
} else {
|
try {
|
||||||
|
_justAudio_AudioPlayer.dispose();
|
||||||
|
} catch (e) {}
|
||||||
|
_justAudio_AudioPlayer = justaudio.AudioPlayer();
|
||||||
|
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||||
_audioPlayer_AudioPlayer.stop();
|
_audioPlayer_AudioPlayer.stop();
|
||||||
|
try {
|
||||||
|
_audioPlayer_AudioPlayer.dispose();
|
||||||
|
} catch (e) {}
|
||||||
|
_audioPlayer_AudioPlayer = audioplayers.AudioPlayer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioWrapper_State get state {
|
AudioWrapper_State get state {
|
||||||
if (kIsWeb) {
|
if (mode == AudioWrapper_Mode.Web) {
|
||||||
if (_justAudio_AudioPlayer.playing){
|
if (_justAudio_AudioPlayer.playing){
|
||||||
return AudioWrapper_State.Playing;
|
return AudioWrapper_State.Playing;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -26,15 +26,17 @@ class EventDelegate<T> {
|
|||||||
|
|
||||||
void trigger(T event) {
|
void trigger(T event) {
|
||||||
print("triggering event");
|
print("triggering event");
|
||||||
|
try {
|
||||||
for (var receipt in _receipts) {
|
for (var receipt in _receipts) {
|
||||||
print("triggering listener");
|
print("triggering listener");
|
||||||
try {
|
try {
|
||||||
receipt.listener(event);
|
receipt.listener(event);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("Error in listener: $e");
|
|
||||||
removeListener(receipt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("Error in trigger: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,24 @@
|
|||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <audioplayers_linux/audioplayers_linux_plugin.h>
|
#include <audioplayers_linux/audioplayers_linux_plugin.h>
|
||||||
|
#include <screen_retriever/screen_retriever_plugin.h>
|
||||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||||
|
#include <window_manager/window_manager_plugin.h>
|
||||||
#include <window_to_front/window_to_front_plugin.h>
|
#include <window_to_front/window_to_front_plugin.h>
|
||||||
|
|
||||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||||
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
|
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
|
||||||
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
|
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
|
||||||
|
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
|
||||||
|
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
|
||||||
|
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
|
||||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||||
|
g_autoptr(FlPluginRegistrar) window_manager_registrar =
|
||||||
|
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
|
||||||
|
window_manager_plugin_register_with_registrar(window_manager_registrar);
|
||||||
g_autoptr(FlPluginRegistrar) window_to_front_registrar =
|
g_autoptr(FlPluginRegistrar) window_to_front_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowToFrontPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowToFrontPlugin");
|
||||||
window_to_front_plugin_register_with_registrar(window_to_front_registrar);
|
window_to_front_plugin_register_with_registrar(window_to_front_registrar);
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
audioplayers_linux
|
audioplayers_linux
|
||||||
|
screen_retriever
|
||||||
url_launcher_linux
|
url_launcher_linux
|
||||||
|
window_manager
|
||||||
window_to_front
|
window_to_front
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ import audio_session
|
|||||||
import audioplayers_darwin
|
import audioplayers_darwin
|
||||||
import device_info_plus
|
import device_info_plus
|
||||||
import flutter_web_auth_2
|
import flutter_web_auth_2
|
||||||
|
import geolocator_apple
|
||||||
import just_audio
|
import just_audio
|
||||||
import package_info_plus
|
import package_info_plus
|
||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
|
import screen_retriever
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
import url_launcher_macos
|
import url_launcher_macos
|
||||||
|
import window_manager
|
||||||
import window_to_front
|
import window_to_front
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
@@ -21,10 +24,13 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
|||||||
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
|
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
|
||||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||||
FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin"))
|
FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin"))
|
||||||
|
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
|
||||||
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
|
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
|
||||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
|
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||||
|
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
|
||||||
WindowToFrontPlugin.register(with: registry.registrar(forPlugin: "WindowToFrontPlugin"))
|
WindowToFrontPlugin.register(with: registry.registrar(forPlugin: "WindowToFrontPlugin"))
|
||||||
}
|
}
|
||||||
|
|||||||
116
pubspec.lock
116
pubspec.lock
@@ -272,6 +272,54 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
geolocator:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: geolocator
|
||||||
|
sha256: "694ec58afe97787b5b72b8a0ab78c1a9244811c3c10e72c4362ef3c0ceb005cd"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "11.0.0"
|
||||||
|
geolocator_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: geolocator_android
|
||||||
|
sha256: "136f1c97e1903366393bda514c5d9e98843418baea52899aa45edae9af8a5cd6"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.5.2"
|
||||||
|
geolocator_apple:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: geolocator_apple
|
||||||
|
sha256: "2f2d4ee16c4df269e93c0e382be075cc01d5db6703c3196e4af20a634fe49ef4"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.6"
|
||||||
|
geolocator_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: geolocator_platform_interface
|
||||||
|
sha256: "009a21c4bc2761e58dccf07c24f219adaebe0ff707abdfd40b0a763d4003fab9"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.2.2"
|
||||||
|
geolocator_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: geolocator_web
|
||||||
|
sha256: "49d8f846ebeb5e2b6641fe477a7e97e5dd73f03cbfef3fd5c42177b7300fb0ed"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.0"
|
||||||
|
geolocator_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: geolocator_windows
|
||||||
|
sha256: a92fae29779d5c6dc60e8411302f5221ade464968fe80a36d330e80a71f087af
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.2"
|
||||||
google_fonts:
|
google_fonts:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -496,6 +544,54 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.1"
|
version: "2.2.1"
|
||||||
|
permission_handler:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: permission_handler
|
||||||
|
sha256: "74e962b7fad7ff75959161bb2c0ad8fe7f2568ee82621c9c2660b751146bfe44"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "11.3.0"
|
||||||
|
permission_handler_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: permission_handler_android
|
||||||
|
sha256: "1acac6bae58144b442f11e66621c062aead9c99841093c38f5bcdcc24c1c3474"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "12.0.5"
|
||||||
|
permission_handler_apple:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: permission_handler_apple
|
||||||
|
sha256: bdafc6db74253abb63907f4e357302e6bb786ab41465e8635f362ee71fd8707b
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "9.4.0"
|
||||||
|
permission_handler_html:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: permission_handler_html
|
||||||
|
sha256: "54bf176b90f6eddd4ece307e2c06cf977fb3973719c35a93b85cc7093eb6070d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.1"
|
||||||
|
permission_handler_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: permission_handler_platform_interface
|
||||||
|
sha256: "23dfba8447c076ab5be3dee9ceb66aad345c4a648f0cac292c77b1eb0e800b78"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.2.0"
|
||||||
|
permission_handler_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: permission_handler_windows
|
||||||
|
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.1"
|
||||||
platform:
|
platform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -544,6 +640,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.27.7"
|
version: "0.27.7"
|
||||||
|
screen_retriever:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: screen_retriever
|
||||||
|
sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.9"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -774,7 +878,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: uuid
|
name: uuid
|
||||||
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
|
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
|
||||||
@@ -782,7 +886,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.3.3"
|
version: "4.3.3"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
||||||
@@ -821,6 +925,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.2"
|
version: "1.1.2"
|
||||||
|
window_manager:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: window_manager
|
||||||
|
sha256: b3c895bdf936c77b83c5254bec2e6b3f066710c1f89c38b20b8acc382b525494
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.3.8"
|
||||||
window_to_front:
|
window_to_front:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ dependencies:
|
|||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
url_launcher: ^6.2.2
|
url_launcher: ^6.2.2
|
||||||
ntp: ^2.0.0
|
ntp: ^2.0.0
|
||||||
|
uuid: ^4.3.3
|
||||||
|
window_manager: ^0.3.8
|
||||||
|
geolocator: ^11.0.0
|
||||||
|
vector_math: ^2.1.4
|
||||||
|
permission_handler: ^11.3.0
|
||||||
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
@@ -78,6 +84,7 @@ flutter:
|
|||||||
- assets/fonts/ibus/london-buses-ibus.ttf
|
- assets/fonts/ibus/london-buses-ibus.ttf
|
||||||
- assets/audio/manual_announcements/
|
- assets/audio/manual_announcements/
|
||||||
- assets/audio/to_destination.wav
|
- assets/audio/to_destination.wav
|
||||||
|
- assets/datasets/bus-blinds.csv
|
||||||
|
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
# - images/a_dot_ham.jpeg
|
# - images/a_dot_ham.jpeg
|
||||||
|
|||||||
@@ -7,17 +7,29 @@
|
|||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <audioplayers_windows/audioplayers_windows_plugin.h>
|
#include <audioplayers_windows/audioplayers_windows_plugin.h>
|
||||||
|
#include <geolocator_windows/geolocator_windows.h>
|
||||||
#include <just_audio_windows/just_audio_windows_plugin.h>
|
#include <just_audio_windows/just_audio_windows_plugin.h>
|
||||||
|
#include <permission_handler_windows/permission_handler_windows_plugin.h>
|
||||||
|
#include <screen_retriever/screen_retriever_plugin.h>
|
||||||
#include <url_launcher_windows/url_launcher_windows.h>
|
#include <url_launcher_windows/url_launcher_windows.h>
|
||||||
|
#include <window_manager/window_manager_plugin.h>
|
||||||
#include <window_to_front/window_to_front_plugin.h>
|
#include <window_to_front/window_to_front_plugin.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
AudioplayersWindowsPluginRegisterWithRegistrar(
|
AudioplayersWindowsPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
|
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
|
||||||
|
GeolocatorWindowsRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("GeolocatorWindows"));
|
||||||
JustAudioWindowsPluginRegisterWithRegistrar(
|
JustAudioWindowsPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("JustAudioWindowsPlugin"));
|
registry->GetRegistrarForPlugin("JustAudioWindowsPlugin"));
|
||||||
|
PermissionHandlerWindowsPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
|
||||||
|
ScreenRetrieverPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
|
||||||
UrlLauncherWindowsRegisterWithRegistrar(
|
UrlLauncherWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||||
|
WindowManagerPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
|
||||||
WindowToFrontPluginRegisterWithRegistrar(
|
WindowToFrontPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("WindowToFrontPlugin"));
|
registry->GetRegistrarForPlugin("WindowToFrontPlugin"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,12 @@
|
|||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
audioplayers_windows
|
audioplayers_windows
|
||||||
|
geolocator_windows
|
||||||
just_audio_windows
|
just_audio_windows
|
||||||
|
permission_handler_windows
|
||||||
|
screen_retriever
|
||||||
url_launcher_windows
|
url_launcher_windows
|
||||||
|
window_manager
|
||||||
window_to_front
|
window_to_front
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user