diff --git a/lib/consts.dart b/lib/consts.dart index 85c2227..2a1c1b2 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -9,7 +9,7 @@ class TTConsts { static get SESSION_SERVER => "https://api.zontreck.com/timetrack/${UPDATE_CHANNEL}/timetrack.php"; - static const VERSION = "1.0.0-beta.3"; + static const VERSION = "1.0.0-beta.4"; static bool UPDATE_AVAILABLE = false; static UpdateChannel UPDATE_CHANNEL = UpdateChannel.beta; diff --git a/lib/data.dart b/lib/data.dart index 460585f..8ba75f4 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -18,7 +18,7 @@ class SessionData { static Delivery? currentDelivery; static Trip? currentTrip; - static List positions = []; + static List positions = []; static late StreamSubscription _listener; static Callbacks Calls = Callbacks(); static String LastSessionID = ""; @@ -27,30 +27,6 @@ class SessionData { /// This flag is usually set when data is loaded from a saved state. Or when accessed using the Web version of the app. static bool IsReadOnly = false; - static double GetTotalBasePay() { - double total = 0; - for (var trip in Trips) { - total += trip.BasePay; - } - - return total; - } - - static double GetTotalTips() { - double total = 0; - for (var trip in Trips) { - for (var drop in trip.deliveries) { - total += drop.TipAmount; - } - } - - return total; - } - - static double GetTotalPay() { - return GetTotalBasePay() + GetTotalTips(); - } - static double GetTotalMiles() { double total = 0; total = _totalMilesTraveled( @@ -106,7 +82,7 @@ class SessionData { /// * [minDistanceMeters] – drop segments shorter than this (jitter). /// * [maxDistanceMeters] – drop segments longer than this (impossible jump). static double _totalMilesTraveled( - List positions, { + List positions, { double minDistanceMeters = 5, double? maxDistanceMeters, }) { @@ -171,7 +147,7 @@ class SessionData { _listener.cancel(); return; } - positions.add(pos); + positions.add(SmallPosition.fromPosition(pos)); SessionData.Calls.dispatch(); }); @@ -214,7 +190,7 @@ class SessionData { List> _pos = []; for (var pos in positions) { - _pos.add(pos.toJson()); + _pos.add(pos.toMap()); } saveData["trips"] = _trips; @@ -252,7 +228,7 @@ class SessionData { } for (var position in _pos) { - positions.add(Position.fromMap(position)); + positions.add(SmallPosition.fromMap(position)); } IsReadOnly = true; @@ -266,8 +242,8 @@ class SessionData { return pos; } - static Trip GetNewTrip({required double basePay}) { - currentTrip = Trip(BasePay: basePay); + static Trip GetNewTrip() { + currentTrip = Trip(); Trips.add(currentTrip!); return currentTrip!; } @@ -290,7 +266,6 @@ class SessionData { } class Delivery { - double TipAmount = 0; Position? endLocation; DateTime StartTime = DateTime.now(); @@ -305,7 +280,6 @@ class Delivery { Map toJsonMap() { return { - "tip": TipAmount, "start": StartTime.toString(), "endPos": endLocation?.toJson() ?? "incomplete", }; @@ -314,7 +288,6 @@ class Delivery { static Delivery fromMap(Map jsx) { Delivery delivery = Delivery(); delivery.StartTime = DateTime.parse(jsx['start'] as String); - delivery.TipAmount = jsx['tip'] as double; if (jsx['endPos'] as String == "incomplete") delivery.endLocation = null; else @@ -329,9 +302,7 @@ class Trip { DateTime StartTime = DateTime(0); - double BasePay = 0.0; - - Trip({required this.BasePay}) { + Trip() { StartTime = DateTime.now(); } @@ -343,7 +314,7 @@ class Trip { } Map toJsonMap() { - Map _trip = {"start": StartTime.toString(), "pay": BasePay}; + Map _trip = {"start": StartTime.toString()}; List> _dropOffs = []; for (var delivery in deliveries) { _dropOffs.add(delivery.toJsonMap()); @@ -355,8 +326,7 @@ class Trip { } static Trip fromJsonMap(Map jsx) { - Trip trip = Trip(BasePay: 0); - trip.BasePay = jsx['pay'] as double; + Trip trip = Trip(); trip.StartTime = DateTime.parse(jsx['start'] as String); trip.deliveries = []; List> _dropOffs = @@ -383,3 +353,29 @@ class Callbacks { if (WorkDataCallback != null) WorkDataCallback!(); } } + +/// A simple wrapper for a position that strips away unnecessary information to create a more compact piece of save data +class SmallPosition { + double latitude; + double longitude; + + SmallPosition({required this.latitude, required this.longitude}); + + static SmallPosition fromPosition(Position position) { + return SmallPosition( + latitude: position.latitude, + longitude: position.longitude, + ); + } + + Map toMap() { + return {"latitude": latitude, "longitude": longitude}; + } + + static SmallPosition fromMap(Map map) { + return SmallPosition( + latitude: map['latitude'] as double, + longitude: map['longitude'] as double, + ); + } +} diff --git a/lib/pages/HomePage.dart b/lib/pages/HomePage.dart index 9d9b7b9..7a7bcb0 100644 --- a/lib/pages/HomePage.dart +++ b/lib/pages/HomePage.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:libacflutter/Constants.dart'; -import 'package:libacflutter/Prompt.dart'; import 'package:timetrack/consts.dart'; import 'package:timetrack/data.dart'; @@ -151,10 +150,7 @@ class _HomePageState extends State { Widget GetTripWidgets() { return Column( children: [ - Text( - "Trip started; Base Pay: \$${SessionData.currentTrip!.BasePay}", - style: TextStyle(fontSize: 18), - ), + Text("Trip started", style: TextStyle(fontSize: 18)), Text( "To end both your current delivery, and the trip, tap on END TRIP", style: TextStyle(fontSize: 18), @@ -164,20 +160,6 @@ class _HomePageState extends State { ), ElevatedButton( onPressed: () async { - var reply = await showDialog( - context: context, - builder: (bld) { - return InputPrompt( - title: "What was the tip?", - prompt: "If there was no tip, enter a 0, or just hit submit.", - type: InputPromptType.Number, - ); - }, - ); - - if (reply == null || reply == "") reply = "0"; - double tip = double.parse(reply as String); - SessionData.currentDelivery!.TipAmount = tip; SessionData.currentDelivery!.MarkEndLocation(); SessionData.EndTrip(); @@ -195,21 +177,6 @@ class _HomePageState extends State { children: [ ElevatedButton( onPressed: () async { - var reply = await showDialog( - context: context, - builder: (bld) { - return InputPrompt( - title: "What was the tip?", - prompt: - "If there was no tip, enter a 0, or hit submit and leave blank", - type: InputPromptType.Number, - ); - }, - ); - - if (reply == null || reply == "") reply = "0"; - double tip = double.parse(reply as String); - SessionData.currentDelivery!.TipAmount = tip; SessionData.currentDelivery!.MarkEndLocation(); SessionData.GetNewDelivery(); @@ -226,20 +193,7 @@ class _HomePageState extends State { children: [ ElevatedButton( onPressed: () async { - var reply = await showDialog( - context: context, - builder: (builder) { - return InputPrompt( - title: "What is the base pay?", - prompt: "Enter the base pay amount below.", - type: InputPromptType.Number, - ); - }, - ); - if (reply == null || reply == "") reply = "0"; - - double basePay = double.parse(reply as String); - SessionData.GetNewTrip(basePay: basePay); + SessionData.GetNewTrip(); SessionData.GetNewDelivery(); setState(() {}); diff --git a/lib/pages/MapPage.dart b/lib/pages/MapPage.dart index fc05285..25cd217 100644 --- a/lib/pages/MapPage.dart +++ b/lib/pages/MapPage.dart @@ -67,9 +67,6 @@ class _MapPage extends State { title: Text( "Trip #${SessionData.Trips.indexOf(trip) + 1}; DropOff #${trip.deliveries.indexOf(dropOff) + 1}", ), - content: Text( - "Pay: \$${trip.BasePay}\nTip: \$${dropOff.TipAmount}", - ), ); }, ); diff --git a/lib/pages/WorkData.dart b/lib/pages/WorkData.dart index f99e551..deb322e 100644 --- a/lib/pages/WorkData.dart +++ b/lib/pages/WorkData.dart @@ -51,23 +51,7 @@ class _WorkData extends State { style: TextStyle(fontSize: 18), ), SizedBox(height: 20), - Text( - "Total Trips: ${SessionData.Trips.length}", - style: TextStyle(fontSize: 18), - ), - Text( - "Total Base Pay: \$${SessionData.GetTotalBasePay()}", - style: TextStyle(fontSize: 18), - ), - Text( - "Total Tips: \$${SessionData.GetTotalTips()}", - style: TextStyle(fontSize: 18), - ), - Text( - "Total Earnings: \$${SessionData.GetTotalPay()}", - style: TextStyle(fontSize: 18), - ), - SizedBox(height: 20), + Text( "Total Estimated Miles: ${SessionData.GetTotalMilesAsString()}\n(Note: The miles displayed above may not be 100% accurate)", style: TextStyle(fontSize: 24), diff --git a/pubspec.yaml b/pubspec.yaml index dd244a5..eebd3a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0-beta.3 +version: 1.0.0-beta.4 environment: sdk: ^3.7.2 @@ -67,6 +67,9 @@ flutter: # the material Icons class. uses-material-design: true + assets: + - server/php/timetrack.php + # To add assets to your application, add an assets section, like this: # assets: # - images/a_dot_burr.jpeg