Skip to content

Addismaptransit realtime #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: addismaptransit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/base/models/journey_plan/leg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Leg extends Equatable {
static const _fromPlace = "from";
static const _startTime = "startTime";
static const _endTime = "endTime";
static const _arrivalDelay = "arrivalDelay";
static const _intermediatePlaces = "intermediatePlaces";
static const _transitLeg = "transitLeg";

Expand All @@ -28,6 +29,7 @@ class Leg extends Equatable {
final Place fromPlace;
final DateTime startTime;
final DateTime endTime;
final int? arrivalDelay;
final List<Place>? intermediatePlaces;
final bool transitLeg;
final List<TrufiLatLng> accumulatedPoints;
Expand All @@ -45,6 +47,7 @@ class Leg extends Equatable {
required this.fromPlace,
required this.startTime,
required this.endTime,
this.arrivalDelay,
required this.intermediatePlaces,
required this.transitLeg,
this.accumulatedPoints = const [],
Expand Down Expand Up @@ -77,6 +80,7 @@ class Leg extends Equatable {
int.tryParse(json[_startTime].toString()) ?? 0),
endTime: DateTime.fromMillisecondsSinceEpoch(
int.tryParse(json[_endTime].toString()) ?? 0),
arrivalDelay: json[_arrivalDelay],
intermediatePlaces: json[_intermediatePlaces] != null
? List<Place>.from(
(json[_intermediatePlaces] as List<dynamic>).map(
Expand All @@ -102,6 +106,7 @@ class Leg extends Equatable {
_fromPlace: fromPlace.toJson(),
_startTime: startTime.millisecondsSinceEpoch,
_endTime: endTime.millisecondsSinceEpoch,
_arrivalDelay: arrivalDelay,
_intermediatePlaces:
intermediatePlaces?.map((itinerary) => itinerary.toJson()).toList(),
_transitLeg: transitLeg,
Expand All @@ -121,6 +126,7 @@ class Leg extends Equatable {
Place? fromPlace,
DateTime? startTime,
DateTime? endTime,
int? arrivalDelay,
bool? rentedBike,
bool? intermediatePlace,
bool? transitLeg,
Expand All @@ -141,6 +147,7 @@ class Leg extends Equatable {
fromPlace: fromPlace ?? this.fromPlace,
startTime: startTime ?? this.startTime,
endTime: endTime ?? this.endTime,
arrivalDelay: arrivalDelay ?? this.arrivalDelay,
transitLeg: transitLeg ?? this.transitLeg,
intermediatePlaces: intermediatePlaces ?? this.intermediatePlaces,
accumulatedPoints: accumulatedPoints ?? this.accumulatedPoints,
Expand Down Expand Up @@ -194,6 +201,7 @@ class Leg extends Equatable {
fromPlace,
startTime,
endTime,
arrivalDelay,
intermediatePlaces,
transitLeg,
accumulatedPoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RestRequestPlanService implements RequestPlanService {
"fromPlace": from.toString(),
"toPlace": to.toString(),
"date": _todayMonthDayYear(),
"time": '12:00:00',
"time": "20:00", // _nowHourMinute(),
"numItineraries": "5",
"mode": _parseTransportModes(transportModes),
});
Expand All @@ -69,10 +69,16 @@ class RestRequestPlanService implements RequestPlanService {
String _todayMonthDayYear() {
final today = DateTime.now();
return "${today.month.toString().padLeft(2, '0')}-"
"01-" +
"${today.day.toString().padLeft(2, '0')}-"+
today.year.toString();
}

String _nowHourMinute() {
final today = DateTime.now();
return "${today.hour.toString().padLeft(2, '0')}-"
"${today.minute.toString().padLeft(2, '0')}";
}

String _parseTransportModes(List<TransportMode> list) {
return list.map((e) => e.name).join(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ItineraryDetailsCard extends StatelessWidget {
location:
mapRouteState.fromPlace?.displayName(localization) ??
'',
arrivalAt: itineraryLeg.arrivalDelay != null ? itineraryLeg.startTime.add(new Duration(seconds: itineraryLeg.arrivalDelay!)) : null,
child: Stack(
clipBehavior: Clip.none,
children: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:timer_count_down/timer_count_down.dart';

import 'package:trufi_core/base/models/enums/transport_mode.dart';
import 'package:trufi_core/base/models/journey_plan/plan.dart';
Expand Down Expand Up @@ -28,6 +29,7 @@ class TransportDash extends StatelessWidget {
if (showBeforeLine)
DashLinePlace(
date: leg.startTimeString,
arrivalAt: leg.arrivalDelay != null ? leg.startTime.add(new Duration(seconds: leg.arrivalDelay!)) : null,
location: leg.fromPlace.name,
color: leg.primaryColor,
),
Expand All @@ -46,6 +48,7 @@ class TransportDash extends StatelessWidget {
if (showAfterLine)
DashLinePlace(
date: leg.endTimeString.toString(),
arrivalAt: leg.arrivalDelay != null ? leg.endTime.add(new Duration(seconds: leg.arrivalDelay!)) : null,
location: leg.toPlace.name.toString(),
color: leg.primaryColor,
),
Expand Down Expand Up @@ -154,6 +157,7 @@ class SeparatorPlace extends StatelessWidget {
class DashLinePlace extends StatelessWidget {
final String date;
final String location;
final DateTime? arrivalAt;
final Widget? child;
final Color? color;

Expand All @@ -163,6 +167,7 @@ class DashLinePlace extends StatelessWidget {
required this.location,
this.child,
this.color,
this.arrivalAt
}) : super(key: key);

@override
Expand Down Expand Up @@ -216,6 +221,32 @@ class DashLinePlace extends StatelessWidget {
),
),
),
if (arrivalAt != null)
Row(
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 3),
child:
Countdown(
seconds: 3600,
build: (BuildContext context, double time) => Text(
(arrivalAt!.difference(DateTime.now()).inMinutes.toString() + " min " + (arrivalAt!.difference(DateTime.now()).inSeconds % 60).toString().padLeft(2, '0')) + " sec",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.orange,
),
),
interval: Duration(milliseconds: 500),
),
),
Icon(
Icons.share_arrival_time,
size: 18,
color: Colors.orange,
),
]
) ,
],
),
);
Expand Down
79 changes: 43 additions & 36 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
app_review:
dependency: "direct main"
description:
name: app_review
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2+1"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
async_executor:
dependency: "direct main"
description:
Expand Down Expand Up @@ -63,28 +56,28 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cross_file:
dependency: transitive
description:
name: cross_file
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3+4"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -154,7 +147,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -370,7 +363,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
latlong2:
dependency: "direct main"
description:
Expand Down Expand Up @@ -398,14 +391,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
mgrs_dart:
dependency: transitive
description:
Expand Down Expand Up @@ -489,7 +489,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.2"
path_drawing:
dependency: transitive
description:
Expand Down Expand Up @@ -636,42 +636,42 @@ packages:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
version: "4.5.3"
share_plus_linux:
dependency: transitive
description:
name: share_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "3.0.1"
share_plus_macos:
dependency: transitive
description:
name: share_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "3.0.1"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "3.2.0"
share_plus_web:
dependency: transitive
description:
name: share_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
version: "3.1.0"
share_plus_windows:
dependency: transitive
description:
name: share_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -683,7 +683,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.9.0"
sqflite:
dependency: transitive
description:
Expand Down Expand Up @@ -718,7 +718,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
synchronized:
dependency: "direct main"
description:
Expand All @@ -732,14 +732,21 @@ packages:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.12"
timer_count_down:
dependency: "direct main"
description:
name: timer_count_down
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.2"
transparent_image:
dependency: transitive
description:
Expand Down Expand Up @@ -858,7 +865,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -895,5 +902,5 @@ packages:
source: hosted
version: "5.3.1"
sdks:
dart: ">=2.15.0 <3.0.0"
flutter: ">=2.8.1"
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.11.0"
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ dependencies:
uni_links: ^0.5.1
# Workaround fix version errors for device_info_plus
device_info_plus_platform_interface: '2.3.0+1'

timer_count_down: ^2.2.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down