Skip to content

Commit

Permalink
Merge pull request #42 from tankste/feature/27-map-launch-settings
Browse files Browse the repository at this point in the history
Map launch settings
  • Loading branch information
Fabi755 authored Nov 11, 2022
2 parents 95ed646 + bf3a43b commit 0527c3c
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 14 deletions.
8 changes: 7 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="app.tankste">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand All @@ -15,6 +16,11 @@
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>

<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
</intent>
</queries>

<application
Expand Down
29 changes: 29 additions & 0 deletions core/lib/common/future.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:tuple/tuple.dart';

Future<Tuple2<T1, T2>> waitConcurrently2<T1, T2>(
Future<T1> future1, Future<T2> future2) async {
late T1 result1;
late T2 result2;

await Future.wait([
future1.then((value) => result1 = value),
future2.then((value) => result2 = value)
]);

return Future.value(Tuple2(result1, result2));
}

Future<Tuple3<T1, T2, T3>> waitConcurrently3<T1, T2, T3>(
Future<T1> future1, Future<T2> future2, Future<T3> future3) async {
late T1 result1;
late T2 result2;
late T3 result3;

await Future.wait([
future1.then((value) => result1 = value),
future2.then((value) => result2 = value),
future3.then((value) => result3 = value)
]);

return Future.value(Tuple3(result1, result2, result3));
}
3 changes: 3 additions & 0 deletions core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies:
# Package Info - https://pub.dev/packages/package_info_plus
package_info_plus: ^2.0.0

# Tuple - https://pub.dev/packages/tuple
tuple: ^2.0.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
40 changes: 37 additions & 3 deletions navigation/lib/ui/preview/route_preview.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:io';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:map/generic/generic_map.dart';
Expand All @@ -6,6 +9,9 @@ import 'package:navigation/coordinate_model.dart';
import 'package:navigation/ui/preview/cubit/route_preview_cubit.dart';
import 'package:navigation/ui/preview/cubit/route_preview_state.dart';
import 'package:navigation/util.dart';
import 'package:settings/map/repository/map_destination_repository.dart';
import 'package:settings/map/usecase/get_map_destination_use_case.dart';
import 'package:url_launcher/url_launcher.dart';

class RoutePreview extends StatelessWidget {
final CoordinateModel target;
Expand Down Expand Up @@ -82,10 +88,38 @@ class RoutePreview extends StatelessWidget {
}

void _openMap() async {
final availableMaps = await MapLauncher.installedMaps;
//TODO: where to locate this, cubit? usecase? split logic to use case & cubit?!
// Hacky solution with use case and type mapping here
GetMapDestinationUseCase getUseCase =
GetMapDestinationUseCaseImpl(LocalMapDestinationRepository());

await availableMaps.first.showMarker(
coords: Coords(target.latitude, target.longitude), title: label ?? "");
final availableMaps = await MapLauncher.installedMaps;
final destinationMap = await getUseCase.invoke();

final mapToLaunch = availableMaps
.where((m) =>
m.mapType ==
//XXX
LocalMapDestinationRepository()
.destinationToType(destinationMap.destination))
.firstOrNull;

if (mapToLaunch != null) {
mapToLaunch.showMarker(
coords: Coords(target.latitude, target.longitude),
title: label ?? "Tankstelle");
} else if (Platform.isAndroid) {
Uri androidUri = Uri.parse(
"geo:${target.latitude},${target.longitude}?q=${target.latitude},${target.longitude} (${label ?? "Tankstelle"})");
if (await canLaunchUrl(androidUri)) {
await launchUrl(androidUri);
}
} else if (Platform.isIOS) {
MapLauncher.showMarker(
mapType: MapType.apple,
coords: Coords(target.latitude, target.longitude),
title: label ?? "Tankstelle");
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions navigation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ dependencies:
core:
path: '../core'

settings:
path: '../settings'

map:
path: '../map'

Expand All @@ -27,6 +30,12 @@ dependencies:
# Map launcher - https://pub.dev/packages/map_launcher
map_launcher: ^2.2.3

# URL Launcher - https://pub.dev/packages/url_launcher
url_launcher: ^6.1.3

# Collection - https://github.com/dart-lang/collection
collection: ^1.17.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
32 changes: 23 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,29 @@ packages:
open_street_map_flutter:
dependency: transitive
description:
path: "../../open_street_map_flutter/open_street_map_flutter"
relative: true
source: path
path: open_street_map_flutter
ref: "26c5ec474605230070609d458d4753ffbacd96ae"
resolved-ref: "26c5ec474605230070609d458d4753ffbacd96ae"
url: "https://github.com/tankste/open_street_map_flutter.git"
source: git
version: "0.0.1"
open_street_map_flutter_android:
dependency: transitive
description:
path: "../../open_street_map_flutter/open_street_map_flutter_android"
relative: true
source: path
path: open_street_map_flutter_android
ref: main
resolved-ref: "26c5ec474605230070609d458d4753ffbacd96ae"
url: "https://github.com/tankste/open_street_map_flutter.git"
source: git
version: "0.0.1"
open_street_map_flutter_platform_interface:
dependency: transitive
description:
path: "../../open_street_map_flutter/open_street_map_flutter_platform_interface"
relative: true
source: path
path: open_street_map_flutter_platform_interface
ref: main
resolved-ref: "26c5ec474605230070609d458d4753ffbacd96ae"
url: "https://github.com/tankste/open_street_map_flutter.git"
source: git
version: "0.0.1"
package_info_plus:
dependency: "direct main"
Expand Down Expand Up @@ -597,6 +603,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.15"
tuple:
dependency: transitive
description:
name: tuple
sha256: "0ea99cd2f9352b2586583ab2ce6489d1f95a5f6de6fb9492faaf97ae2060f0aa"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
typed_data:
dependency: transitive
description:
Expand Down
28 changes: 28 additions & 0 deletions settings/lib/map/model/map_destination_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

class MapDestinationModel {
String label;
MapDestinationDestination destination;

MapDestinationModel(this.label, this.destination);
}

enum MapDestinationDestination {
system,
googleMaps,
googleMapsGo,
appleMaps,
baiduMaps,
amap,
waze,
yandexMaps,
yandexNavigator,
citymapper,
mapsMe,
osmAnd,
osmAndPlus,
twoGis,
tencent,
hereWeGo,
petalMaps,
tomTomGo,
}
Loading

0 comments on commit 0527c3c

Please sign in to comment.