Fire notification read

This commit is contained in:
Vicente J. Ruiz Jurado 2018-07-26 20:30:24 +02:00
parent 04171cdc12
commit b7468de0d1
10 changed files with 66 additions and 22 deletions

View file

@ -56,10 +56,12 @@ class _FireNotificationListState extends State<FireNotificationList> {
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<FireNotificationList> {
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<FireNotificationList> {
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<FireNotificationList> {
hasFireNotifications
? IconButton(
icon: Icon(Icons.delete),
onPressed: () =>
_showConfirmDialog(view)
)
onPressed: () => _showConfirmDialog(view))
: null
])),
body: !hasFireNotifications
@ -203,8 +210,8 @@ class _FireNotificationListState extends State<FireNotificationList> {
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Text(S.of(context).deleteAllFireNotificationsAlertDescription
)
new Text(
S.of(context).deleteAllFireNotificationsAlertDescription)
],
),
),
@ -222,4 +229,3 @@ class _FireNotificationListState extends State<FireNotificationList> {
);
}
}

View file

@ -33,6 +33,7 @@ void onMessage(Map<String, dynamic> message, Store<AppState> 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));

View file

@ -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";

View file

@ -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<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}) {
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}';
}
}

View file

@ -14,7 +14,8 @@ FireNotification _$FireNotificationFromJson(Map<String, dynamic> 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<String, dynamic> toJson() => new _$FireNotificationJsonMapWrapper(this);
}
@ -31,7 +33,7 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
@override
Iterable<String> 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;

View file

@ -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) {
// Use the api to fetch the YourLocations
api

View file

@ -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);
}

View file

@ -9,12 +9,14 @@ final fireNotificationReducer = combineReducers<List<FireNotification>>([
new TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
_deletedFireNotification),
new TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
_deletedAllFireNotifications)
_deletedAllFireNotifications),
new TypedReducer<List<FireNotification>, ReadedFireNotificationAction>(
_readedFireNotification)
]);
List<FireNotification> _receivedFireNotification(
List<FireNotification> yourLocations, AddedFireNotificationAction action) {
return new List.from(yourLocations)..add(action.notif);
List<FireNotification> notifications, AddedFireNotificationAction action) {
return new List.from(notifications)..add(action.notif);
}
List<FireNotification> _deletedFireNotification(
@ -22,6 +24,14 @@ List<FireNotification> _deletedFireNotification(
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> notifications, DeletedAllFireNotificationAction action) {
return new List<FireNotification>();

View file

@ -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",

View file

@ -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",