From 29df8c44db4e20f9c26d36410f4961fc307e1fa1 Mon Sep 17 00:00:00 2001 From: vjrj Date: Sun, 16 Sep 2018 08:10:56 +0200 Subject: [PATCH] Fire press dialog --- lib/generated/i18n.dart | 9 +++++++ lib/genericMap.dart | 54 +++++++++++++++++++++++++-------------- lib/locationUtils.dart | 18 ++++++------- lib/models/appState.dart | 2 +- res/values/strings_en.arb | 5 +++- res/values/strings_es.arb | 5 +++- 6 files changed, 62 insertions(+), 31 deletions(-) diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index ef11433..c4426c2 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -43,6 +43,8 @@ class S implements WidgetsLocalizations { String get appMoto => "Strengthening neighborhoods against wildfires"; String get appName => "All Against The Fire!"; String get areYouSureTitle => "Are you sure?"; + String get byNASAsatellites => "by NASA satellites"; + String get byOurUsers => "by one of our users"; String get callEmergencyServicesDescription => "You should call 112 if you have not already done so to notify the emergency services."; String get callEmergencyServicesTitle => "Call 112"; String get chooseAPlace => "Choose a place"; @@ -95,6 +97,7 @@ class S implements WidgetsLocalizations { String get youDeletedThisNotification => "You deleted this notification"; String get youDeletedThisPlace => "You deleted this place"; String activeFiresWorldWide(String activeFires) => "$activeFires active fires worldwide"; + String additionalInfoAboutFire(String where, String when, String by) => "Fire detected in $where $when $by"; String appLicense(String thisYear) => "(c) 2017-$thisYear Comunes Association under the GNU Affero GPL v3"; String fireAroundThisArea(String kmAround) => "A fire at $kmAround км around this area"; String firesAroundThisArea(String numFires, String kmAround) => "$numFires fires at $kmAround км around this area"; @@ -142,6 +145,8 @@ class es extends S { @override String get fireNotificationsDescription => "Aquí recibirás las notificaciones de fuegos en los lugares a los que te subscribas"; @override + String get byOurUsers => "por uno de nuestros usuarios/as"; + @override String get anHour => "una hora"; @override String get areYouSureTitle => "¿Seguro?"; @@ -274,6 +279,8 @@ class es extends S { @override String get appMoto => "Fortaleciendo vecindarios contra incendios forestales"; @override + String get byNASAsatellites => "por satélites de la NASA"; + @override String get chooseAWatchRadio => "Elige un radio de vigilancia"; @override String get CANCEL => "CANCELAR"; @@ -292,6 +299,8 @@ class es extends S { @override String somethingAgo(String something) => "hace $something"; @override + String additionalInfoAboutFire(String where, String when, String by) => "Información adicional sobre fuego detectado en $where $when $by"; + @override String tweetAboutSelf(String location, String hash) => "Fuego en $location $hash"; @override String subscribeToValueAroundThisArea(String sliderValue) => "Suscríbete a $sliderValue км a la redonda"; diff --git a/lib/genericMap.dart b/lib/genericMap.dart index 1af4707..7b74864 100644 --- a/lib/genericMap.dart +++ b/lib/genericMap.dart @@ -1,5 +1,5 @@ import 'dart:core'; - +import 'locationUtils.dart'; import 'package:comunes_flutter/comunes_flutter.dart'; import 'package:fires_flutter/models/yourLocation.dart'; import 'package:flutter/material.dart'; @@ -24,10 +24,12 @@ import 'redux/actions.dart'; import 'sentryReport.dart'; import 'slider.dart'; import 'zoomMapPlugin.dart'; +import 'customMoment.dart'; @immutable class _ViewModel { final String serverUrl; + final String lang; final FireMapState mapState; final OnSubscribeFunction onSubs; final OnSubscribeConfirmedFunction onSubsConfirmed; @@ -43,6 +45,7 @@ class _ViewModel { _ViewModel( {@required this.mapState, @required this.serverUrl, + @required this.lang, @required this.onSubs, @required this.onSubsConfirmed, @required this.onUnSubs, @@ -59,10 +62,12 @@ class _ViewModel { identical(this, other) || other is _ViewModel && runtimeType == other.runtimeType && + serverUrl == other.serverUrl && + lang == other.lang && mapState == other.mapState; @override - int get hashCode => mapState.hashCode; + int get hashCode => serverUrl.hashCode ^ lang.hashCode ^ mapState.hashCode; } class genericMap extends StatefulWidget { @@ -115,10 +120,12 @@ class _genericMapState extends State { }, onFalsePositive: (notif, type) => store .dispatch(new MarkFireAsFalsePositiveAction(notif, type)), - onFirePressed: (LatLng latLng, DateTime when) { - // _showFireDialog(latLng, when); + onFirePressed: (LatLng latLng, DateTime when, type) { + _showFireDialog(latLng, when, type); }, serverUrl: store.state.serverUrl, + // Not used yet, but maybe in the future for date format + lang: store.state.user.lang, mapState: store.state.fireMapState); }, builder: (context, view) { @@ -429,7 +436,7 @@ class _genericMapState extends State { try { var loc = new LatLng(fire['lat'], fire['lon']); markers.add(FireMarker(loc, FireMarkType.fire, () { - onFirePressed(loc, DateTime.parse(fire['when'])); + onFirePressed(loc, DateTime.parse(fire['when']), fire['type']); print('fire $fire pressed'); })); markers.add(FireMarker(loc, FireMarkType.pixel)); @@ -444,19 +451,28 @@ class _genericMapState extends State { return markers; } - void _showFireDialog(LatLng latLng, DateTime when) { - showDialog( - context: _scaffoldKey.currentContext, - builder: (_) => new AlertDialog( - content: new Text('FIXME'), - actions: [ - new FlatButton( - child: Text(S.of(_scaffoldKey.currentContext).CLOSE), - onPressed: () { - Navigator.pop(_scaffoldKey.currentContext); - }, - ), - ], - )); + void _showFireDialog(LatLng pos, DateTime date, String type) { + var when = Moment.fromDate(date).fromNow(context); + getReverseLocation(lat: pos.latitude, lon: pos.longitude) + .then((reverseLoc) { + String by = type == 'vecinal' + ? S.of(context).byOurUsers + : S.of(context).byNASAsatellites; + String fireDesc = + S.of(context).additionalInfoAboutFire(reverseLoc, when, by); + showDialog( + context: _scaffoldKey.currentContext, + builder: (_) => new AlertDialog( + content: new Text(fireDesc), + actions: [ + new FlatButton( + child: Text(S.of(context).CLOSE), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + )); + }); } } diff --git a/lib/locationUtils.dart b/lib/locationUtils.dart index 1c7f340..2f3b55a 100644 --- a/lib/locationUtils.dart +++ b/lib/locationUtils.dart @@ -15,21 +15,21 @@ Future getUserLocation( Map location = await _location.getLocation; // It seems that the lib fails with lat/lon values - var yourLocation = new YourLocation( + var yl = new YourLocation( lat: location['latitude'], lon: location['longitude']); var address; try { - address = await getReverseLocation(yourLocation); - yourLocation.description = address; + address = await getReverseLocation(lat: yl.lat, lon: yl.lon); + yl.description = address; } catch (e) { try { - address = await getReverseLocation(yourLocation, true); - yourLocation.description = address; + address = await getReverseLocation(lat: yl.lat, lon: yl.lon, external: true); + yl.description = address; } catch (e) { print('We cannot reverse geolocate'); } } - return yourLocation; + return yl; } on PlatformException catch (e) { if (e.code == 'PERMISSION_DENIED') { scaffoldKey.currentState.showSnackBar(new SnackBar( @@ -44,9 +44,9 @@ Future getUserLocation( } } -Future getReverseLocation(YourLocation loc, - [bool external = false]) async { - final coordinates = new Coordinates(loc.lat, loc.lon); +Future getReverseLocation({@required lat, @required lon, + bool external = false}) async { + final coordinates = new Coordinates(lat, lon); var geoCoder = external ? Geocoder.google(Injector.getInjector().get(key: "gmapKey")) : Geocoder.local; var addresses = await geoCoder.findAddressesFromCoordinates(coordinates); var first = addresses.first; diff --git a/lib/models/appState.dart b/lib/models/appState.dart index b4cba15..f1cc365 100644 --- a/lib/models/appState.dart +++ b/lib/models/appState.dart @@ -124,7 +124,7 @@ typedef void OnLocationEditing(YourLocation loc); typedef void OnLocationEditConfirm(YourLocation loc); typedef void OnLocationEditCancel(YourLocation loc); typedef void TapFireNotificationFunction(FireNotification notif); -typedef void OnFirePressedInMap(LatLng latLng, DateTime when); +typedef void OnFirePressedInMap(LatLng latLng, DateTime when, String source); // typedef void OnReceivedFireNotificationFunction(FireNotification notif); typedef void DeleteFireNotificationFunction(FireNotification notif); typedef void DeleteAllFireNotificationFunction(); diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index eb81593..fcbd60b 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -86,5 +86,8 @@ "unsubscribedToFires": "Unsubscribed to fires notifications", "subscribedToFires": "Subscribed to fires notifications", "inDevelopment": "In development", - "translateBtn": "Help with translations" + "translateBtn": "Help with translations", + "additionalInfoAboutFire": "Fire detected in $where $when $by", + "byNASAsatellites": "by NASA satellites", + "byOurUsers": "by one of our users" } \ No newline at end of file diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index 0986e91..b735530 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -86,5 +86,8 @@ "unsubscribedToFires": "Desuscrito a notificaciones de fuegos", "subscribedToFires": "Suscrito a notificaciones de fuegos", "inDevelopment": "En desarrollo", - "translateBtn": "Ayuda con las traducciones" + "translateBtn": "Ayuda con las traducciones", + "additionalInfoAboutFire": "Información adicional sobre fuego detectado en $where $when $by", + "byNASAsatellites": "por satélites de la NASA", + "byOurUsers": "por uno de nuestros usuarios/as" } \ No newline at end of file