diff --git a/lib/fireNotificationList.dart b/lib/fireNotificationList.dart index 385ae72..9657ea4 100644 --- a/lib/fireNotificationList.dart +++ b/lib/fireNotificationList.dart @@ -56,10 +56,12 @@ class _FireNotificationListState extends State { return new ListTile( dense: true, leading: const Icon(Icons.whatshot), - title: new Text(notif.description), + title: new Text(notif.description, + style: new TextStyle( + fontWeight: notif.read ? FontWeight.normal : FontWeight.bold)), subtitle: new Text(Moment.now().from(context, notif.when)), onLongPress: () { - showSnackMsg(S.of(context).toDeleteThisPlace); + showSnackMsg(S.of(context).toDeleteThisNotification); }, onTap: () { onTap(notif); @@ -77,6 +79,8 @@ class _FireNotificationListState extends State { return new RefreshIndicator( child: new ListView.builder( padding: const EdgeInsets.all(16.0), + reverse: true, + shrinkWrap: true, itemCount: notifList.length, itemBuilder: (BuildContext _context, int i) { final ThemeData theme = Theme.of(context); @@ -136,7 +140,12 @@ class _FireNotificationListState extends State { store.dispatch(new AddFireNotificationAction(notif)); }))); }, - onTap: (notif) {}, + onTap: (notif) { + if (!notif.read) { + store.dispatch(new ReadFireNotificationAction( + notif.copyWith(read: true))); + } + }, fireNotifications: store.state.fireNotifications); }, builder: (context, view) { @@ -159,9 +168,7 @@ class _FireNotificationListState extends State { hasFireNotifications ? IconButton( icon: Icon(Icons.delete), - onPressed: () => - _showConfirmDialog(view) - ) + onPressed: () => _showConfirmDialog(view)) : null ])), body: !hasFireNotifications @@ -203,8 +210,8 @@ class _FireNotificationListState extends State { content: new SingleChildScrollView( child: new ListBody( children: [ - new Text(S.of(context).deleteAllFireNotificationsAlertDescription - ) + new Text( + S.of(context).deleteAllFireNotificationsAlertDescription) ], ), ), @@ -222,4 +229,3 @@ class _FireNotificationListState extends State { ); } } - diff --git a/lib/firebaseMessagingConf.dart b/lib/firebaseMessagingConf.dart index 66dc085..9f31d3c 100644 --- a/lib/firebaseMessagingConf.dart +++ b/lib/firebaseMessagingConf.dart @@ -33,6 +33,7 @@ void onMessage(Map message, Store store) { lat: double.parse(message['lat']), lon: double.parse(message['lon']), description: message['description'], + read: false, when: DateTime.parse(message['when'])); print(notif); store.dispatch(new AddFireNotificationAction(notif)); diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 7a49965..48e7497 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -58,6 +58,7 @@ class S implements WidgetsLocalizations { String get privacyPolicy => "Privacy Policy"; String get supportPageDescription => "You can support this initiative, spreading the word, helping us to develop our software, translating this app to your language, etc."; String get supportThisInitiative => "Support this initiative"; + String get toDeleteThisNotification => "Slide horizontally to delete this notification"; String get toDeleteThisPlace => "Slide horizontally to delete this place"; String get toFiresNotifications => "Subscribe to fires notifications"; String get tweetAboutAFireDescription => "Additionally if you use twitter you can share additional information with the emergency services, for example, attaching photos to the tweet if you have good visibility of the fire, when you took the photos, exact location, etc. Use #hashtags type #IFMinicipalTerminal for example #IFJumilla (Forest Fire in Jumilla)."; @@ -94,6 +95,8 @@ class es extends S { @override String get addYourCurrentPosition => "Añade tu ubicación actual"; @override + String get toDeleteThisNotification => "Desliza horizontalmente para borrar esta notificación"; + @override String get alertWhenThereIsAFire => "Alerta cuando hay un fuego"; @override String get fireNotificationsDescription => "Aquí recibirás las notificaciones de fuegos en los lugares a los que te subscribas"; diff --git a/lib/models/fireNotification.dart b/lib/models/fireNotification.dart index 0c87ce8..12062c1 100644 --- a/lib/models/fireNotification.dart +++ b/lib/models/fireNotification.dart @@ -20,20 +20,20 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin { final double lon; final String description; final DateTime when; + final bool read; factory FireNotification.fromJson(Map json) => _$FireNotificationFromJson(json); - // static FireNotification noLocation = new FireNotification(lat: 0.0, lon: 0.0, description: '', when: new DateTime(0)); - - FireNotification({this.id, @required this.lat, @required this.lon, @required this.description, @required this.when}) { + FireNotification({this.id, @required this.lat, @required this.lon, @required this.description, @required this.when, @required this.read}) { if (this.id == null) this.id = new ObjectId(); } - FireNotification copyWith({id, lat, lon, description, when}) { + FireNotification copyWith({id, lat, lon, description, read, when}) { return new FireNotification( id: id ?? this.id, lat: lat ?? this.lat, - lon: lon ?? this.lon, + lon: lon ?? this.lon, + read: read ?? this.read, description: description ?? this.description, when: when ?? this.when); } @@ -45,15 +45,16 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin { runtimeType == other.runtimeType && id == other.id && lat == other.lat && - lon == other.lon && + lon == other.lon && + read == other.read && description == other.description && when == other.when; @override - int get hashCode => id.hashCode ^ lat.hashCode ^ lon.hashCode ^ description.hashCode ^ when.hashCode; + int get hashCode => id.hashCode ^ lat.hashCode ^ lon.hashCode ^ description.hashCode ^ when.hashCode ^ read.hashCode; @override String toString() { - return 'FireNotification {id: $id, lat: $lat, lon: $lon, description: $description, when: $when}'; + return 'FireNotification {id: $id, lat: $lat, lon: $lon, description: $description, when: $when, read: $read}'; } } diff --git a/lib/models/fireNotification.g.dart b/lib/models/fireNotification.g.dart index b50c3c8..14b113c 100644 --- a/lib/models/fireNotification.g.dart +++ b/lib/models/fireNotification.g.dart @@ -14,7 +14,8 @@ FireNotification _$FireNotificationFromJson(Map json) => lat: (json['lat'] as num).toDouble(), lon: (json['lon'] as num).toDouble(), description: json['description'] as String, - when: DateTime.parse(json['when'] as String)); + when: DateTime.parse(json['when'] as String), + read: json['read'] as bool); abstract class _$FireNotificationSerializerMixin { ObjectId get id; @@ -22,6 +23,7 @@ abstract class _$FireNotificationSerializerMixin { double get lon; String get description; DateTime get when; + bool get read; Map toJson() => new _$FireNotificationJsonMapWrapper(this); } @@ -31,7 +33,7 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper { @override Iterable get keys => - const ['id', 'lat', 'lon', 'description', 'when']; + const ['id', 'lat', 'lon', 'description', 'when', 'read']; @override dynamic operator [](Object key) { @@ -47,6 +49,8 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper { return _v.description; case 'when': return _v.when.toIso8601String(); + case 'read': + return _v.read; } } return null; diff --git a/lib/redux/fetchDataMiddleware.dart b/lib/redux/fetchDataMiddleware.dart index 17f0e0c..7e4314c 100644 --- a/lib/redux/fetchDataMiddleware.dart +++ b/lib/redux/fetchDataMiddleware.dart @@ -126,6 +126,11 @@ void fetchDataMiddleware(Store store, action, NextDispatcher next) { } } + if (action is ReadFireNotificationAction) { + store.dispatch(new ReadedFireNotificationAction(action.notif)); + persistFireNotifications(store.state.fireNotifications); + } + if (action is FetchYourLocationsAction) { // Use the api to fetch the YourLocations api diff --git a/lib/redux/fireNotificationActions.dart b/lib/redux/fireNotificationActions.dart index 18d7209..d42df0b 100644 --- a/lib/redux/fireNotificationActions.dart +++ b/lib/redux/fireNotificationActions.dart @@ -33,3 +33,15 @@ class AddedFireNotificationAction extends FireNotificationActions { AddedFireNotificationAction(this.notif); } + +class ReadFireNotificationAction extends FireNotificationActions { + final FireNotification notif; + + ReadFireNotificationAction(this.notif); +} + +class ReadedFireNotificationAction extends FireNotificationActions { + final FireNotification notif; + + ReadedFireNotificationAction(this.notif); +} diff --git a/lib/redux/fireNotificationReducer.dart b/lib/redux/fireNotificationReducer.dart index 92b675e..50b23ac 100644 --- a/lib/redux/fireNotificationReducer.dart +++ b/lib/redux/fireNotificationReducer.dart @@ -9,12 +9,14 @@ final fireNotificationReducer = combineReducers>([ new TypedReducer, DeletedFireNotificationAction>( _deletedFireNotification), new TypedReducer, DeletedAllFireNotificationAction>( - _deletedAllFireNotifications) + _deletedAllFireNotifications), + new TypedReducer, ReadedFireNotificationAction>( + _readedFireNotification) ]); List _receivedFireNotification( - List yourLocations, AddedFireNotificationAction action) { - return new List.from(yourLocations)..add(action.notif); + List notifications, AddedFireNotificationAction action) { + return new List.from(notifications)..add(action.notif); } List _deletedFireNotification( @@ -22,6 +24,14 @@ List _deletedFireNotification( return new List.from(notifications)..remove(action.notif); } +List _readedFireNotification( + List notifications, ReadedFireNotificationAction action) { + return notifications + .map((yourLocation) => + yourLocation.id == action.notif.id ? action.notif : yourLocation) + .toList(); +} + List _deletedAllFireNotifications( List notifications, DeletedAllFireNotificationAction action) { return new List(); diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index 4356773..1c1d31a 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -10,6 +10,7 @@ "youDeletedThisPlace": "You deleted this place", "UNDO": "UNDO", "toDeleteThisPlace": "Slide horizontally to delete this place", + "toDeleteThisNotification": "Slide horizontally to delete this notification", "toFiresNotifications": "Subscribe to fires notifications", "confirm": "Confirm", "unsubscribe": "Unsubscribe", diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index a577572..d07088f 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -10,6 +10,7 @@ "youDeletedThisPlace": "Has borrado este lugar", "UNDO": "DESHACER", "toDeleteThisPlace": "Desliza horizontalmente para borrar este lugar", + "toDeleteThisNotification": "Desliza horizontalmente para borrar esta notificación", "toFiresNotifications": "Suscríbete a alertas de fuegos", "confirm": "Confirmar", "unsubscribe": "Desuscríbete",