Skip to content
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

Bring free ride view into release #635

Closed
wants to merge 1 commit into from
Closed
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
74 changes: 62 additions & 12 deletions lib/common/map/layers/sg_layers_free.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class AllTrafficLightsPredictionLayer {
textFont: ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
textSize: 24,
textColor: Colors.white.value,
textHaloColor: Colors.black.value,
textHaloWidth: 1,
textHaloColor: const Color.fromARGB(255, 31, 31, 31).value,
textHaloWidth: 0.75,
textAnchor: mapbox.TextAnchor.BOTTOM,
textOffset: [0, -1],
textOpacity: 0.8,
textOpacity: 1,
),
mapbox.LayerPosition(at: at),
);
Expand Down Expand Up @@ -140,6 +140,14 @@ class AllTrafficLightsPredictionLayer {
"get",
"textSize",
]));

await mapController.style.setStyleLayerProperty(
layerId,
'text-opacity',
jsonEncode([
"get",
"opacity",
]));
}
}

Expand All @@ -157,9 +165,15 @@ class AllTrafficLightsPredictionGeometryLayer {
/// The ID of the Mapbox source.
static const sourceId = "all-traffic-lights-prediction-geometry-source";

/// The ID of the chevron layer.
static const layerIdChevrons = "all-traffic-lights-predictions-geometry-layer-chevrons";

/// The ID of the Mapbox layer.
static const layerId = "all-traffic-lights-predictions-geometry-layer";

/// The ID of the background layer.
static const layerIdBackground = "all-traffic-lights-predictions-geometry-layer-background";

/// The features to display.
final List<dynamic> features = List.empty(growable: true);

Expand Down Expand Up @@ -196,12 +210,41 @@ class AllTrafficLightsPredictionGeometryLayer {
await update(mapController);
}

final trafficLightLineChevronLayerExists = await mapController.style.styleLayerExists(layerIdChevrons);
if (!trafficLightLineChevronLayerExists) {
await mapController.style.addLayerAt(
mapbox.SymbolLayer(
sourceId: sourceId,
id: layerIdChevrons,
symbolPlacement: mapbox.SymbolPlacement.LINE,
symbolSpacing: 0,
iconSize: 1,
iconAllowOverlap: true,
iconOpacity: 0.6,
iconIgnorePlacement: true,
iconRotate: 90,
iconImage: "routechevrondark",
),
mapbox.LayerPosition(at: at));

await mapController.style.setStyleLayerProperty(
layerIdChevrons,
'icon-opacity',
jsonEncode([
"get",
"opacity",
]));
}

final trafficLightLineLayerExists = await mapController.style.styleLayerExists(layerId);
if (!trafficLightLineLayerExists) {
await mapController.style.addLayerAt(
mapbox.LineLayer(
sourceId: sourceId,
id: layerId,
lineJoin: mapbox.LineJoin.ROUND,
lineCap: mapbox.LineCap.ROUND,
lineWidth: 20,
),
mapbox.LayerPosition(at: at),
);
Expand All @@ -216,13 +259,13 @@ class AllTrafficLightsPredictionGeometryLayer {
["get", "greenNow"],
false
],
"#ff0000",
"#f30034",
[
"==",
["get", "greenNow"],
true
],
"#00ff00",
"#30c73f",
"#000000",
]),
);
Expand All @@ -234,14 +277,21 @@ class AllTrafficLightsPredictionGeometryLayer {
"get",
"opacity",
]));
}

await mapController.style.setStyleLayerProperty(
layerId,
'line-width',
jsonEncode([
"get",
"lineWidth",
]));
final trafficLightLineBackgroundLayerExists = await mapController.style.styleLayerExists(layerIdBackground);
if (!trafficLightLineBackgroundLayerExists) {
await mapController.style.addLayerAt(
mapbox.LineLayer(
sourceId: sourceId,
id: layerIdBackground,
lineJoin: mapbox.LineJoin.ROUND,
lineCap: mapbox.LineCap.ROUND,
lineWidth: 24,
lineColor: const Color.fromARGB(255, 31, 31, 31).value,
),
mapbox.LayerPosition(at: at),
);
}
}

Expand Down
48 changes: 47 additions & 1 deletion lib/home/views/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:priobike/main.dart';
import 'package:priobike/news/services/news.dart';
import 'package:priobike/news/views/main.dart';
import 'package:priobike/ride/services/ride.dart';
import 'package:priobike/ride/views/free.dart';
import 'package:priobike/routing/models/waypoint.dart';
import 'package:priobike/routing/services/profile.dart';
import 'package:priobike/routing/services/routing.dart';
Expand Down Expand Up @@ -227,6 +228,8 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver, RouteAw

/// A callback that is fired when free routing was selected.
void onStartFreeRouting() {
if (routing.isFetchingRoute) return;

HapticFeedback.mediumImpact();

pushRoutingView();
Expand All @@ -246,6 +249,45 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver, RouteAw
);
}

/// A callback that is fired when free ride was selected.
void onStartFreeRide() {
if (routing.isFetchingRoute) return;

HapticFeedback.mediumImpact();

if (settings.didViewWarning) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const FreeRideView()));
return;
}

// Before we start the free ride view, we always notify the user of its drawbacks.
showDialog<String>(
context: context,
builder: (BuildContext context) {
return DialogLayout(
title: "Wirklich ohne Route fahren?",
text:
"In diesem Modus siehst Du lediglich Countdowns der Ampeln. Diese können ungenau sein. Mit Routenplanung erhältst Du genauere Geschwindigkeitsempfehlungen. Denke an Deine Sicherheit und achte stets auf Deine Umgebung. Beachte die Hinweisschilder und die örtlichen Gesetze.",
actions: [
BigButtonPrimary(
label: "Fortfahren",
onPressed: () {
getIt<Settings>().setDidViewWarning(true);
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const FreeRideView()));
},
boxConstraints: BoxConstraints(minWidth: MediaQuery.of(context).size.width, minHeight: 36),
),
BigButtonTertiary(
label: "Abbrechen",
onPressed: () => Navigator.pop(context),
boxConstraints: BoxConstraints(minWidth: MediaQuery.of(context).size.width, minHeight: 36),
),
],
);
},
);
}

/// A callback that is fired when the shortcuts should be edited.
void onOpenShortcutEditView() {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const ShortcutsEditView()));
Expand Down Expand Up @@ -375,7 +417,11 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver, RouteAw
padding: EdgeInsets.fromLTRB(25, 0, 25, 24),
),
),
ShortcutsView(onSelectShortcut: onSelectShortcut, onStartFreeRouting: onStartFreeRouting)
ShortcutsView(
onSelectShortcut: onSelectShortcut,
onStartFreeRouting: onStartFreeRouting,
onStartFreeRide: onStartFreeRide,
)
],
),
),
Expand Down
54 changes: 45 additions & 9 deletions lib/home/views/shortcuts/selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart' hide Shortcuts;
import 'package:priobike/common/animation.dart';
import 'package:priobike/common/layout/ci.dart';
import 'package:priobike/common/layout/modal.dart';
import 'package:priobike/common/layout/text.dart';
import 'package:priobike/common/layout/tiles.dart';
import 'package:priobike/home/models/shortcut.dart';
import 'package:priobike/home/models/shortcut_location.dart';
Expand All @@ -16,6 +17,16 @@ import 'package:priobike/routing/services/routing.dart';

class ShortcutView extends StatelessWidget {
final Shortcut? shortcut;

/// What text to show when no shortcut is available.
final String? alternativeText;

/// What icon to show when no shortcut is available.
final IconData? alternativeIcon;

/// The content of a small badge that is shown on the shortcut.
final String? badge;

final void Function() onPressed;
final void Function()? onLongPressed;
final double width;
Expand All @@ -28,6 +39,9 @@ class ShortcutView extends StatelessWidget {
const ShortcutView({
super.key,
this.shortcut,
this.alternativeText,
this.alternativeIcon,
this.badge,
required this.onPressed,
required this.width,
required this.height,
Expand All @@ -52,9 +66,9 @@ class ShortcutView extends StatelessWidget {
content: Stack(
children: [
if (shortcut == null)
const Padding(
padding: EdgeInsets.all(8),
child: Icon(Icons.map_rounded, size: 64, color: Colors.white),
Padding(
padding: const EdgeInsets.all(8),
child: Icon(alternativeIcon ?? Icons.error, size: 64, color: Colors.white),
)
else if (shortcut is ShortcutRoute)
Container(
Expand Down Expand Up @@ -93,6 +107,15 @@ class ShortcutView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: Container()),
if (badge != null)
Container(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
),
child: Small(text: badge!, context: context, color: Colors.white),
),
FittedBox(
// Scale the text to fit the width.
fit: BoxFit.fitWidth,
Expand All @@ -104,9 +127,9 @@ class ShortcutView extends StatelessWidget {
shortcut == null ? null : Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.75),
),
child: shortcut == null
? const Text(
'Freie Route',
style: TextStyle(
? Text(
alternativeText ?? 'Missing alternative text',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
Expand Down Expand Up @@ -150,9 +173,13 @@ class ShortcutsView extends StatefulWidget {
/// A callback that will be executed when free routing is started.
final void Function() onStartFreeRouting;

/// A callback that will be executed when free ride is started.
final void Function() onStartFreeRide;

const ShortcutsView({
required this.onSelectShortcut,
required this.onStartFreeRouting,
required this.onStartFreeRide,
super.key,
});

Expand Down Expand Up @@ -227,9 +254,18 @@ class ShortcutsViewState extends State<ShortcutsView> {
padding: EdgeInsets.only(left: leftPad),
),
ShortcutView(
onPressed: () {
if (!routing.isFetchingRoute) widget.onStartFreeRouting();
},
alternativeText: 'Ohne Route fahren',
alternativeIcon: Icons.navigation,
onPressed: widget.onStartFreeRide,
width: shortcutWidth,
height: shortcutHeight,
rightPad: shortcutRightPad,
),
ShortcutView(
alternativeText: 'Route planen',
alternativeIcon: Icons.map_rounded,
onPressed: widget.onStartFreeRouting,
badge: 'Empfohlen',
width: shortcutWidth,
height: shortcutHeight,
rightPad: shortcutRightPad,
Expand Down
16 changes: 16 additions & 0 deletions lib/positioning/services/positioning.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ class Positioning with ChangeNotifier {
[settings.city.center];
positionSource = PathMockPositionSource(idealSpeed: 18 / 3.6, positions: positions, autoSpeed: true);
log.i("Using mocked auto speed positioning source.");
} else if (settings.positioningMode == PositioningMode.hamburgInCircles) {
// In circles around Millerntorplatz, an area with many traffic lights.
positionSource = PathMockPositionSource(idealSpeed: 18 / 3.6, positions: const [
LatLng(53.549912, 9.967677),
LatLng(53.550012, 9.971065),
LatLng(53.549654, 9.972879),
LatLng(53.549981, 9.973134),
LatLng(53.550216, 9.971639),
LatLng(53.551221, 9.969480),
LatLng(53.550957, 9.969092),
LatLng(53.550727, 9.969593),
LatLng(53.550174, 9.969269),
LatLng(53.550115, 9.967710),
LatLng(53.549912, 9.967677),
]);
log.i("Using mocked position source for Hamburg in circles.");
} else if (settings.positioningMode == PositioningMode.sensor) {
final routing = getIt<Routing>();
final positions = routing.selectedRoute?.route // Fallback to center location of city.
Expand Down
2 changes: 1 addition & 1 deletion lib/ride/services/free_ride.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FreeRide with ChangeNotifier {
final Set<String> subscriptions = {};

/// The max distance in meters for an SG to be considered on screen.
static const maxDistance = 200;
static const maxDistance = 300;

final vincenty = const Distance(roundResult: false);

Expand Down
4 changes: 1 addition & 3 deletions lib/ride/views/free.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ class FreeRideViewState extends State<FreeRideView> {
),
],
)
: const Center(
child: Text('Error.'),
),
: Container(),
),
),
);
Expand Down
Loading
Loading