Alot of changes

This commit is contained in:
ImBenji
2024-05-01 12:29:59 +01:00
parent 8cc4016836
commit fc4d3ef898
23 changed files with 1755 additions and 430 deletions

View File

@@ -22,204 +22,206 @@ class pages_Home extends StatelessWidget {
child: Column(
children: [
Row(
children: [
Speedometer(),
],
),
Container(
height: 2,
color: Colors.white70,
),
SingleChildScrollView(
child: Column(
child: SingleChildScrollView(
child: Column(
children: [
Row(
children: [
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: AnnouncementPicker(
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
announcements: [
for (NamedAnnouncementQueueEntry announcement in LiveInformation().announcementModule.manualAnnouncements)
_AnnouncementEntry(
label: announcement.shortName,
index: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
outlineColor: Colors.white70,
onPressed: (){
LiveInformation liveInformation = LiveInformation();
liveInformation.announcementModule.queueAnnounementByInfoIndex(
infoIndex: liveInformation.announcementModule.manualAnnouncements.indexOf(announcement),
sendToServer: true
);
},
)
],
Speedometer(),
],
),
Container(
height: 2,
color: Colors.white70,
),
SingleChildScrollView(
child: Column(
children: [
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: AnnouncementPicker(
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
announcements: [
for (NamedAnnouncementQueueEntry announcement in LiveInformation().announcementModule.manualAnnouncements)
_AnnouncementEntry(
label: announcement.shortName,
index: LiveInformation().announcementModule.manualAnnouncements.indexOf(announcement),
outlineColor: Colors.white70,
onPressed: (){
LiveInformation liveInformation = LiveInformation();
liveInformation.announcementModule.queueAnnounementByInfoIndex(
infoIndex: liveInformation.announcementModule.manualAnnouncements.indexOf(announcement),
sendToServer: true
);
},
)
],
),
),
),
),
Container(
height: 2,
color: Colors.white70,
),
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: DelegateBuilder<BusRouteVariant>(
delegate: LiveInformation().routeVariantDelegate,
builder: (context, routeVariant) {
print("rebuilt stop announcement picker");
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
},
defaultBuilder: (context) {
BusRouteVariant? routeVariant = LiveInformation().getRouteVariant();
if (routeVariant == null) {
return Container(
color: Colors.grey.shade900,
child: Center(
child: Text(
"No route selected",
style: GoogleFonts.teko(
fontSize: 25,
color: Colors.white70
),
),
),
);
} else {
Container(
height: 2,
color: Colors.white70,
),
Container(
margin: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade900,
),
child: DelegateBuilder<BusRouteVariant>(
delegate: LiveInformation().routeVariantDelegate,
builder: (context, routeVariant) {
print("rebuilt stop announcement picker");
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
}
},
},
defaultBuilder: (context) {
BusRouteVariant? routeVariant = LiveInformation().getRouteVariant();
if (routeVariant == null) {
return Container(
color: Colors.grey.shade900,
child: Center(
child: Text(
"No route selected",
style: GoogleFonts.teko(
fontSize: 25,
color: Colors.white70
),
),
),
);
} else {
return StopAnnouncementPicker(
routeVariant: routeVariant,
backgroundColor: Colors.grey.shade900,
outlineColor: Colors.white70,
);
}
},
),
),
),
),
ElevatedButton(
onPressed: () async {
LiveInformation liveInformation = LiveInformation();
final commandModule = liveInformation.commandModule;
// commandModule.executeCommand(
// "announce dest"
// );
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
routeVariant: liveInformation.getRouteVariant()!
);
},
child: Text("Announce current destination"),
),
// Container(
//
// margin: EdgeInsets.all(20),
//
// height: 300-45,
//
// child: ListView(
//
// scrollDirection: Axis.vertical,
//
// children: [
//
// ElevatedButton(
// onPressed: () async {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: false));
// },
// child: Text("Test announcement"),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.updateServer();
// },
// child: Text("Update server"),
// ),
//
// SizedBox(
//
// width: 100,
//
// child: TextField(
// onChanged: (String value) {
// LiveInformation liveInformation = LiveInformation();
// // liveInformation.documentID = value;
// },
// ),
// ),
//
// SizedBox(
//
// width: 200,
//
// child: TextField(
// onSubmitted: (String value) {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(AnnouncementQueueEntry(
// displayText: value,
// audioSources: []
// ));
// },
// ),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.pullServer();
// },
// child: Text("Pull server"),
// ),
//
// ],
//
// ),
//
// ),
],
ElevatedButton(
onPressed: () async {
LiveInformation liveInformation = LiveInformation();
final commandModule = liveInformation.commandModule;
// commandModule.executeCommand(
// "announce dest"
// );
liveInformation.announcementModule.queueAnnouncementByRouteVariant(
routeVariant: liveInformation.getRouteVariant()!
);
},
child: Text("Announce current destination"),
),
// Container(
//
// margin: EdgeInsets.all(20),
//
// height: 300-45,
//
// child: ListView(
//
// scrollDirection: Axis.vertical,
//
// children: [
//
// ElevatedButton(
// onPressed: () async {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(await liveInformation.getDestinationAnnouncement(liveInformation.getRouteVariant()!, sendToServer: false));
// },
// child: Text("Test announcement"),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.updateServer();
// },
// child: Text("Update server"),
// ),
//
// SizedBox(
//
// width: 100,
//
// child: TextField(
// onChanged: (String value) {
// LiveInformation liveInformation = LiveInformation();
// // liveInformation.documentID = value;
// },
// ),
// ),
//
// SizedBox(
//
// width: 200,
//
// child: TextField(
// onSubmitted: (String value) {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.queueAnnouncement(AnnouncementQueueEntry(
// displayText: value,
// audioSources: []
// ));
// },
// ),
// ),
//
// ElevatedButton(
// onPressed: () {
// LiveInformation liveInformation = LiveInformation();
// liveInformation.pullServer();
// },
// child: Text("Pull server"),
// ),
//
// ],
//
// ),
//
// ),
],
),
),
),
],
],
),
)
);

View File

@@ -1,7 +1,12 @@
import 'dart:convert';
import 'package:bus_infotainment/backend/live_information.dart';
import 'package:bus_infotainment/pages/settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
class InitialStartup extends StatefulWidget {
@@ -9,11 +14,43 @@ class InitialStartup extends StatefulWidget {
State<InitialStartup> createState() => _InitialStartupState();
}
const String Version = "0.2.0";
// Get the current version from /assets/version.txt
Future<String> GetVersion() async {
return await rootBundle.loadString("assets/version.txt");
}
class _InitialStartupState extends State<InitialStartup> {
bool AllowPassage = false;
@override
void initState() {
// TODO: implement initState
super.initState();
SharedPreferences.getInstance().then((prefs) {
String? base64String = prefs.getString("announcements");
if (base64String != null) {
print("Found previois announcement file");
Uint8List ByteList = base64Decode(base64String);
LiveInformation().announcementModule.setBundleBytes(ByteList);
Navigator.pushNamed(context, "/application");
} else {
print("No previous announcement file found");
}
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
@@ -28,6 +65,8 @@ class _InitialStartupState extends State<InitialStartup> {
children: [
PermissionsSetup(),
SizedBox(
height: 8,
),
@@ -79,13 +118,29 @@ class _InitialStartupState extends State<InitialStartup> {
height: 8,
),
Text(
"Version $Version",
style: GoogleFonts.inter(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.grey
),
FutureBuilder(
future: GetVersion(),
builder: (context, snapshot){
if (snapshot.hasData){
return Text(
"Version ${snapshot.data}",
style: GoogleFonts.inter(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.grey
),
);
} else {
return Text(
"Version -.-.-",
style: GoogleFonts.inter(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.grey
),
);
}
},
)
],

View File

@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:bus_infotainment/audio_cache.dart';
@@ -7,9 +8,12 @@ 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:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:text_scroll/text_scroll.dart';
import 'package:url_launcher/url_launcher_string.dart';
@@ -184,10 +188,24 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
AnnouncementCache cache = LiveInformation().announcementModule.announcementCache;
LiveInformation().announcementModule.setBundleBytes(result.files[0].bytes!);
late Uint8List bytes;
if (kIsWeb) {
bytes = result.files.single.bytes!;
} else {
File file = File(result.files.single.path!);
bytes = file.readAsBytesSync();
}
LiveInformation().announcementModule.setBundleBytes(bytes);
// load a random announcement to ensure that the file is usable
await cache.loadAnnouncementsFromBytes(result.files[0].bytes!, ["S_WALTHAMSTOW_CENTRAL_001.mp3"]);
await cache.loadAnnouncementsFromBytes(bytes, ["S_WALTHAMSTOW_CENTRAL_001.mp3"]);
print("Loaded announcements");
@@ -195,17 +213,60 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
});
if (!kIsWeb) {
// Use shared preferences to store the file location
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString("AnnouncementsFileLocation", result.files.single.path!);
}
widget.onUploaded();
} else {
// User canceled the picker
}
}
@override
void initState() {
// TODO: implement initState
super.initState();
if (!kIsWeb) {
SharedPreferences.getInstance().then((prefs) async {
String FileLocation = prefs.getString("AnnouncementsFileLocation")!;
File file = File(FileLocation);
Uint8List bytes = file.readAsBytesSync();
LiveInformation().announcementModule.setBundleBytes(bytes);
AnnouncementCache cache = LiveInformation().announcementModule.announcementCache;
await cache.loadAnnouncementsFromBytes(bytes, ["S_WALTHAMSTOW_CENTRAL_001.mp3"]);
setState(() {
});
print("Loaded announcemends from SharedPrefs");
widget.onUploaded();
});
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
bool checkPassed = LiveInformation().announcementModule.announcementCache.keys.length != 0;
return Container(
decoration: BoxDecoration(
border: Border.all(
@@ -224,77 +285,61 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
child: Column(
children: [
if (!checkPassed)
Row(
Row(
children: [
children: [
Icon(
Icons.error,
color: Colors.red,
size: 18,
),
SizedBox(
width: 4,
),
Transform.translate(
offset: Offset(0, 0),
child: Text(
"IMPORTANT",
style: GoogleFonts.interTight(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white70,
letterSpacing: 0.1,
),
),
)
],
),
Row(
children: [
if (LiveInformation().announcementModule.announcementCache.keys.length == 0)
Icon(
Icons.error,
color: Colors.red,
size: 18,
)
else
),
SizedBox(
width: 4,
),
Transform.translate(
offset: Offset(0, 0),
child: Text(
"NO ANNOUNCEMENTS LOADED",
style: GoogleFonts.interTight(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white70,
letterSpacing: 0.1,
),
),
)
],
)
else
Row(
children: [
Icon(
Icons.check,
Icons.check_box,
color: Colors.green,
size: 18,
),
SizedBox(
width: 4,
),
SizedBox(
width: 4,
),
if (LiveInformation().announcementModule.announcementCache.keys.length == 0)
Transform.translate(
offset: Offset(0, 0),
child: Text(
"No announcements",
style: GoogleFonts.interTight(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white70,
letterSpacing: 0.1,
),
),
)
else
Transform.translate(
offset: Offset(0, 0),
child: Text(
"Announcements loaded successfully",
"ANNOUNCEMENTS LOADED",
style: GoogleFonts.interTight(
fontSize: 18,
fontWeight: FontWeight.bold,
@@ -303,10 +348,9 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
),
),
)
],
],
),
),
SizedBox(
height: 8,
@@ -368,6 +412,23 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
),
),
if (kIsWeb)
SizedBox(
height: 8,
),
if (kIsWeb)
Text(
"Announcements uploaded on web are not persistent, and will need to be re-uploaded each time the site is loaded.",
style: GoogleFonts.interTight(
fontSize: 12,
fontWeight: FontWeight.w400,
color: Colors.white70,
letterSpacing: 0.1,
height: 1
),
),
SizedBox(
height: 8,
),
@@ -407,6 +468,153 @@ class _AnnouncementUploadState extends State<AnnouncementUpload> {
}
}
class PermissionsSetup extends StatefulWidget {
@override
State<PermissionsSetup> createState() => _PermissionsSetupState();
}
class _PermissionsSetupState extends State<PermissionsSetup> {
List<bool> _hasPermissions = [];
bool get hasPermissions {
return !_hasPermissions.contains(false) && _hasPermissions.length > 0;
}
Future<void> requestPermission() async {
_hasPermissions = [];
print("Requesting location permission");
if (!await Permission.location.isGranted){
PermissionStatus locationStatus = await Permission.location.request();
if (locationStatus.isGranted) {
_hasPermissions.add(true);
LiveInformation().initTrackerModule();
} else {
_hasPermissions.add(false);
}
} else {
_hasPermissions.add(true);
}
print("Gotten result for location permission");
if (!kIsWeb){
print("Requesting storage permissions");
PermissionStatus fileStatus = await Permission.manageExternalStorage.request();
if (fileStatus.isGranted) {
_hasPermissions.add(true);
} else {
_hasPermissions.add(false);
}
} else {
_hasPermissions.add(true);
}
print("Permissions: $_hasPermissions");
setState(() {
});
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.white70,
width: 2
),
),
margin: EdgeInsets.symmetric(
horizontal: 8
),
padding: EdgeInsets.all(8),
child: Column(
children: [
Row(
children: [
Icon(
hasPermissions ? Icons.check_box : Icons.error,
color: hasPermissions ? Colors.green : Colors.red,
size: 18,
),
SizedBox(
width: 4,
),
Transform.translate(
offset: Offset(0, 0),
child: Text(
hasPermissions ? "PERMISSIONS GRANTED" : "MISSING PERMISSIONS",
style: GoogleFonts.interTight(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white70,
letterSpacing: 0.1,
),
),
),
],
),
SizedBox(
height: 8,
),
SizedBox(
height: 32,
width: double.infinity,
child: ElevatedButton(
onPressed: (){
requestPermission();
},
// 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)
),
),
child: Text(
"Request permissions",
style: GoogleFonts.interTight(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.white,
letterSpacing: 0.5
)
)
),
)
],
),
);
}
}
enum _LoginType {
login,
signup

View File

@@ -36,7 +36,7 @@ class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
pages_Home(),
pages_Routes(),
pages_Display(this),
pages_Settings(),
pages_Settings()
];
}
@@ -48,6 +48,11 @@ class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
super.initState();
Future.delayed(Duration.zero, () async {
// if in debug mode skip all this
if (kDebugMode)
return;
try {
await LiveInformation().announcementModule.getBundleBytes();
} catch (e) {
@@ -90,80 +95,6 @@ class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
return Scaffold(
// 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(
width: double.infinity,
@@ -259,6 +190,55 @@ class TfL_Dataset_TestState extends State<TfL_Dataset_Test> {
children: [
if (false)
Expanded(
child: Stack(
children: [
Container(
alignment: Alignment.center,
margin: const EdgeInsets.all(10),
child: Text(
"Dashboard",
style: GoogleFonts.teko(
color: Colors.white70,
fontSize: 20,
fontWeight: FontWeight.bold,
),
)
),
Positioned.fill(
child: ElevatedButton(
onPressed: () {
setState(() {
Navigator.pushNamed(context, "/dashboard");
});
},
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: [