Fire notification read
This commit is contained in:
parent
04171cdc12
commit
b7468de0d1
10 changed files with 66 additions and 22 deletions
|
|
@ -56,10 +56,12 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
return new ListTile(
|
return new ListTile(
|
||||||
dense: true,
|
dense: true,
|
||||||
leading: const Icon(Icons.whatshot),
|
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)),
|
subtitle: new Text(Moment.now().from(context, notif.when)),
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
showSnackMsg(S.of(context).toDeleteThisPlace);
|
showSnackMsg(S.of(context).toDeleteThisNotification);
|
||||||
},
|
},
|
||||||
onTap: () {
|
onTap: () {
|
||||||
onTap(notif);
|
onTap(notif);
|
||||||
|
|
@ -77,6 +79,8 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
return new RefreshIndicator(
|
return new RefreshIndicator(
|
||||||
child: new ListView.builder(
|
child: new ListView.builder(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
reverse: true,
|
||||||
|
shrinkWrap: true,
|
||||||
itemCount: notifList.length,
|
itemCount: notifList.length,
|
||||||
itemBuilder: (BuildContext _context, int i) {
|
itemBuilder: (BuildContext _context, int i) {
|
||||||
final ThemeData theme = Theme.of(context);
|
final ThemeData theme = Theme.of(context);
|
||||||
|
|
@ -136,7 +140,12 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
store.dispatch(new AddFireNotificationAction(notif));
|
store.dispatch(new AddFireNotificationAction(notif));
|
||||||
})));
|
})));
|
||||||
},
|
},
|
||||||
onTap: (notif) {},
|
onTap: (notif) {
|
||||||
|
if (!notif.read) {
|
||||||
|
store.dispatch(new ReadFireNotificationAction(
|
||||||
|
notif.copyWith(read: true)));
|
||||||
|
}
|
||||||
|
},
|
||||||
fireNotifications: store.state.fireNotifications);
|
fireNotifications: store.state.fireNotifications);
|
||||||
},
|
},
|
||||||
builder: (context, view) {
|
builder: (context, view) {
|
||||||
|
|
@ -159,9 +168,7 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
hasFireNotifications
|
hasFireNotifications
|
||||||
? IconButton(
|
? IconButton(
|
||||||
icon: Icon(Icons.delete),
|
icon: Icon(Icons.delete),
|
||||||
onPressed: () =>
|
onPressed: () => _showConfirmDialog(view))
|
||||||
_showConfirmDialog(view)
|
|
||||||
)
|
|
||||||
: null
|
: null
|
||||||
])),
|
])),
|
||||||
body: !hasFireNotifications
|
body: !hasFireNotifications
|
||||||
|
|
@ -203,8 +210,8 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
content: new SingleChildScrollView(
|
content: new SingleChildScrollView(
|
||||||
child: new ListBody(
|
child: new ListBody(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(S.of(context).deleteAllFireNotificationsAlertDescription
|
new Text(
|
||||||
)
|
S.of(context).deleteAllFireNotificationsAlertDescription)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -222,4 +229,3 @@ class _FireNotificationListState extends State<FireNotificationList> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ void onMessage(Map<String, dynamic> message, Store<AppState> store) {
|
||||||
lat: double.parse(message['lat']),
|
lat: double.parse(message['lat']),
|
||||||
lon: double.parse(message['lon']),
|
lon: double.parse(message['lon']),
|
||||||
description: message['description'],
|
description: message['description'],
|
||||||
|
read: false,
|
||||||
when: DateTime.parse(message['when']));
|
when: DateTime.parse(message['when']));
|
||||||
print(notif);
|
print(notif);
|
||||||
store.dispatch(new AddFireNotificationAction(notif));
|
store.dispatch(new AddFireNotificationAction(notif));
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ class S implements WidgetsLocalizations {
|
||||||
String get privacyPolicy => "Privacy Policy";
|
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 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 supportThisInitiative => "Support this initiative";
|
||||||
|
String get toDeleteThisNotification => "Slide horizontally to delete this notification";
|
||||||
String get toDeleteThisPlace => "Slide horizontally to delete this place";
|
String get toDeleteThisPlace => "Slide horizontally to delete this place";
|
||||||
String get toFiresNotifications => "Subscribe to fires notifications";
|
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).";
|
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
|
@override
|
||||||
String get addYourCurrentPosition => "Añade tu ubicación actual";
|
String get addYourCurrentPosition => "Añade tu ubicación actual";
|
||||||
@override
|
@override
|
||||||
|
String get toDeleteThisNotification => "Desliza horizontalmente para borrar esta notificación";
|
||||||
|
@override
|
||||||
String get alertWhenThereIsAFire => "Alerta cuando hay un fuego";
|
String get alertWhenThereIsAFire => "Alerta cuando hay un fuego";
|
||||||
@override
|
@override
|
||||||
String get fireNotificationsDescription => "Aquí recibirás las notificaciones de fuegos en los lugares a los que te subscribas";
|
String get fireNotificationsDescription => "Aquí recibirás las notificaciones de fuegos en los lugares a los que te subscribas";
|
||||||
|
|
|
||||||
|
|
@ -20,20 +20,20 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin {
|
||||||
final double lon;
|
final double lon;
|
||||||
final String description;
|
final String description;
|
||||||
final DateTime when;
|
final DateTime when;
|
||||||
|
final bool read;
|
||||||
|
|
||||||
factory FireNotification.fromJson(Map<String, dynamic> json) => _$FireNotificationFromJson(json);
|
factory FireNotification.fromJson(Map<String, dynamic> 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, @required this.read}) {
|
||||||
|
|
||||||
FireNotification({this.id, @required this.lat, @required this.lon, @required this.description, @required this.when}) {
|
|
||||||
if (this.id == null) this.id = new ObjectId();
|
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(
|
return new FireNotification(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
lat: lat ?? this.lat,
|
lat: lat ?? this.lat,
|
||||||
lon: lon ?? this.lon,
|
lon: lon ?? this.lon,
|
||||||
|
read: read ?? this.read,
|
||||||
description: description ?? this.description,
|
description: description ?? this.description,
|
||||||
when: when ?? this.when);
|
when: when ?? this.when);
|
||||||
}
|
}
|
||||||
|
|
@ -45,15 +45,16 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin {
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
id == other.id &&
|
id == other.id &&
|
||||||
lat == other.lat &&
|
lat == other.lat &&
|
||||||
lon == other.lon &&
|
lon == other.lon &&
|
||||||
|
read == other.read &&
|
||||||
description == other.description &&
|
description == other.description &&
|
||||||
when == other.when;
|
when == other.when;
|
||||||
|
|
||||||
@override
|
@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
|
@override
|
||||||
String toString() {
|
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}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ FireNotification _$FireNotificationFromJson(Map<String, dynamic> json) =>
|
||||||
lat: (json['lat'] as num).toDouble(),
|
lat: (json['lat'] as num).toDouble(),
|
||||||
lon: (json['lon'] as num).toDouble(),
|
lon: (json['lon'] as num).toDouble(),
|
||||||
description: json['description'] as String,
|
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 {
|
abstract class _$FireNotificationSerializerMixin {
|
||||||
ObjectId get id;
|
ObjectId get id;
|
||||||
|
|
@ -22,6 +23,7 @@ abstract class _$FireNotificationSerializerMixin {
|
||||||
double get lon;
|
double get lon;
|
||||||
String get description;
|
String get description;
|
||||||
DateTime get when;
|
DateTime get when;
|
||||||
|
bool get read;
|
||||||
Map<String, dynamic> toJson() => new _$FireNotificationJsonMapWrapper(this);
|
Map<String, dynamic> toJson() => new _$FireNotificationJsonMapWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +33,7 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Iterable<String> get keys =>
|
Iterable<String> get keys =>
|
||||||
const ['id', 'lat', 'lon', 'description', 'when'];
|
const ['id', 'lat', 'lon', 'description', 'when', 'read'];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
dynamic operator [](Object key) {
|
dynamic operator [](Object key) {
|
||||||
|
|
@ -47,6 +49,8 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
|
||||||
return _v.description;
|
return _v.description;
|
||||||
case 'when':
|
case 'when':
|
||||||
return _v.when.toIso8601String();
|
return _v.when.toIso8601String();
|
||||||
|
case 'read':
|
||||||
|
return _v.read;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,11 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action is ReadFireNotificationAction) {
|
||||||
|
store.dispatch(new ReadedFireNotificationAction(action.notif));
|
||||||
|
persistFireNotifications(store.state.fireNotifications);
|
||||||
|
}
|
||||||
|
|
||||||
if (action is FetchYourLocationsAction) {
|
if (action is FetchYourLocationsAction) {
|
||||||
// Use the api to fetch the YourLocations
|
// Use the api to fetch the YourLocations
|
||||||
api
|
api
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,15 @@ class AddedFireNotificationAction extends FireNotificationActions {
|
||||||
|
|
||||||
AddedFireNotificationAction(this.notif);
|
AddedFireNotificationAction(this.notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ReadFireNotificationAction extends FireNotificationActions {
|
||||||
|
final FireNotification notif;
|
||||||
|
|
||||||
|
ReadFireNotificationAction(this.notif);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReadedFireNotificationAction extends FireNotificationActions {
|
||||||
|
final FireNotification notif;
|
||||||
|
|
||||||
|
ReadedFireNotificationAction(this.notif);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,14 @@ final fireNotificationReducer = combineReducers<List<FireNotification>>([
|
||||||
new TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
|
new TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
|
||||||
_deletedFireNotification),
|
_deletedFireNotification),
|
||||||
new TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
|
new TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
|
||||||
_deletedAllFireNotifications)
|
_deletedAllFireNotifications),
|
||||||
|
new TypedReducer<List<FireNotification>, ReadedFireNotificationAction>(
|
||||||
|
_readedFireNotification)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
List<FireNotification> _receivedFireNotification(
|
List<FireNotification> _receivedFireNotification(
|
||||||
List<FireNotification> yourLocations, AddedFireNotificationAction action) {
|
List<FireNotification> notifications, AddedFireNotificationAction action) {
|
||||||
return new List.from(yourLocations)..add(action.notif);
|
return new List.from(notifications)..add(action.notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FireNotification> _deletedFireNotification(
|
List<FireNotification> _deletedFireNotification(
|
||||||
|
|
@ -22,6 +24,14 @@ List<FireNotification> _deletedFireNotification(
|
||||||
return new List.from(notifications)..remove(action.notif);
|
return new List.from(notifications)..remove(action.notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<FireNotification> _readedFireNotification(
|
||||||
|
List<FireNotification> notifications, ReadedFireNotificationAction action) {
|
||||||
|
return notifications
|
||||||
|
.map((yourLocation) =>
|
||||||
|
yourLocation.id == action.notif.id ? action.notif : yourLocation)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
List<FireNotification> _deletedAllFireNotifications(
|
List<FireNotification> _deletedAllFireNotifications(
|
||||||
List<FireNotification> notifications, DeletedAllFireNotificationAction action) {
|
List<FireNotification> notifications, DeletedAllFireNotificationAction action) {
|
||||||
return new List<FireNotification>();
|
return new List<FireNotification>();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
"youDeletedThisPlace": "You deleted this place",
|
"youDeletedThisPlace": "You deleted this place",
|
||||||
"UNDO": "UNDO",
|
"UNDO": "UNDO",
|
||||||
"toDeleteThisPlace": "Slide horizontally to delete this place",
|
"toDeleteThisPlace": "Slide horizontally to delete this place",
|
||||||
|
"toDeleteThisNotification": "Slide horizontally to delete this notification",
|
||||||
"toFiresNotifications": "Subscribe to fires notifications",
|
"toFiresNotifications": "Subscribe to fires notifications",
|
||||||
"confirm": "Confirm",
|
"confirm": "Confirm",
|
||||||
"unsubscribe": "Unsubscribe",
|
"unsubscribe": "Unsubscribe",
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
"youDeletedThisPlace": "Has borrado este lugar",
|
"youDeletedThisPlace": "Has borrado este lugar",
|
||||||
"UNDO": "DESHACER",
|
"UNDO": "DESHACER",
|
||||||
"toDeleteThisPlace": "Desliza horizontalmente para borrar este lugar",
|
"toDeleteThisPlace": "Desliza horizontalmente para borrar este lugar",
|
||||||
|
"toDeleteThisNotification": "Desliza horizontalmente para borrar esta notificación",
|
||||||
"toFiresNotifications": "Suscríbete a alertas de fuegos",
|
"toFiresNotifications": "Suscríbete a alertas de fuegos",
|
||||||
"confirm": "Confirmar",
|
"confirm": "Confirmar",
|
||||||
"unsubscribe": "Desuscríbete",
|
"unsubscribe": "Desuscríbete",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue