More work with fire notifications

This commit is contained in:
Vicente J. Ruiz Jurado 2018-07-31 12:51:10 +02:00
parent 5fdaf239c0
commit 9dd8a7de97
24 changed files with 512 additions and 288 deletions

View file

@ -1,6 +1,6 @@
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
@ -25,12 +25,16 @@ class AppState extends Object with _$AppStateSerializerMixin {
@JsonKey(ignore: true)
final String gmapKey;
@JsonKey(ignore: true)
final String serverUrl;
@JsonKey(ignore: true)
final String firesApiKey;
@JsonKey(ignore: true)
final String firesApiUrl;
final List<YourLocation> yourLocations;
final List<FireNotification> fireNotifications;
@JsonKey(ignore: true)
final int fireNotificationsUnread;
@JsonKey(ignore: true)
final FireMapState fireMapState;
@JsonKey(ignore: true)
@ -40,13 +44,15 @@ class AppState extends Object with _$AppStateSerializerMixin {
AppState(
{this.yourLocations: const <YourLocation>[],
this.fireNotifications: const <FireNotification>[],
this.fireNotificationsUnread: 0,
this.user: const User.initial(),
this.isLoading: false,
this.isLoaded: false,
this.error: null,
this.gmapKey,
this.firesApiKey,
this.firesApiUrl,
this.firesApiUrl,
this.serverUrl,
this.fireMapState: const FireMapState.initial()});
AppState copyWith(
@ -55,10 +61,12 @@ class AppState extends Object with _$AppStateSerializerMixin {
String user,
String error,
String gmapKey,
String firesApiKey,
String firesApiKey,
String serverUrl,
String firesApiUrl,
List<YourLocation> yourLocations,
List<FireNotification> fireNotifications,
List<FireNotification> fireNotifications,
int fireNotificationsUnread,
FireMapState fireMapState}) {
return new AppState(
isLoading: isLoading ?? this.isLoading,
@ -67,9 +75,12 @@ class AppState extends Object with _$AppStateSerializerMixin {
error: error ?? this.error,
gmapKey: gmapKey ?? this.gmapKey,
firesApiKey: firesApiKey ?? this.firesApiKey,
firesApiUrl: firesApiUrl ?? this.firesApiUrl,
firesApiUrl: firesApiUrl ?? this.firesApiUrl,
serverUrl: serverUrl ?? this.serverUrl,
yourLocations: yourLocations ?? this.yourLocations,
fireNotifications: fireNotifications ?? this.fireNotifications,
fireNotificationsUnread:
fireNotificationsUnread ?? this.fireNotificationsUnread,
fireMapState: fireMapState ?? this.fireMapState);
}
@ -77,8 +88,8 @@ class AppState extends Object with _$AppStateSerializerMixin {
String toString() {
return 'AppState{\nuser: ${user}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(
firesApiKey, 8)}\napiUrl: ${ellipse(
firesApiUrl, 8)}\nyourLocations count: ${yourLocations
.length}\nyourLocations: ${yourLocations}\nfireNotifications: ${fireNotifications}\nfireMapState: $fireMapState}';
firesApiUrl, 8)}\nserverUrl: ${serverUrl}\nfireNotifications: ${fireNotifications}\nyourLocations count: ${yourLocations
.length}\nunread notif: ${fireNotificationsUnread}\nyourLocations: ${yourLocations}\nfireMapState: $fireMapState}';
}
}

View file

@ -1,40 +1,53 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:redux/src/store.dart';
import '../genericMap.dart';
import '../objectIdUtils.dart';
import '../redux/actions.dart';
part 'fireNotification.g.dart';
_objectIdFromJson(String json) {
return new ObjectId.fromHexString(json);
}
_objectIdToJson(ObjectId o) {
return o.toString();
}
@JsonSerializable(nullable: false)
class FireNotification extends Object with _$FireNotificationSerializerMixin {
@JsonKey(toJson: _objectIdToJson, fromJson: _objectIdFromJson)
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id;
final double lat;
final double lon;
final String description;
final DateTime when;
final String sealed;
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
final ObjectId subsId;
final bool read;
factory FireNotification.fromJson(Map<String, dynamic> json) => _$FireNotificationFromJson(json);
factory FireNotification.fromJson(Map<String, dynamic> json) =>
_$FireNotificationFromJson(json);
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,
@required this.read,
@required this.sealed,
@required this.subsId}) {
if (this.id == null) this.id = new ObjectId();
}
FireNotification copyWith({id, lat, lon, description, read, when}) {
FireNotification copyWith(
{id, lat, lon, description, read, when, sealed, subsId}) {
return new FireNotification(
id: id ?? this.id,
lat: lat ?? this.lat,
lon: lon ?? this.lon,
read: read ?? this.read,
lon: lon ?? this.lon,
read: read ?? this.read,
description: description ?? this.description,
sealed: sealed ?? this.sealed,
subsId: subsId ?? this.subsId,
when: when ?? this.when);
}
@ -45,16 +58,46 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin {
runtimeType == other.runtimeType &&
id == other.id &&
lat == other.lat &&
lon == other.lon &&
read == other.read &&
lon == other.lon &&
read == other.read &&
description == other.description &&
sealed == other.sealed &&
subsId == other.subsId &&
when == other.when;
@override
int get hashCode => id.hashCode ^ lat.hashCode ^ lon.hashCode ^ description.hashCode ^ when.hashCode ^ read.hashCode;
int get hashCode =>
id.hashCode ^
lat.hashCode ^
lon.hashCode ^
description.hashCode ^
when.hashCode ^
read.hashCode ^
sealed.hashCode ^
subsId.hashCode;
@override
String toString() {
return 'FireNotification {id: $id, lat: $lat, lon: $lon, description: $description, when: $when, read: $read}';
return 'FireNotification {id: $id, lat: $lat, lon: $lon, when: $when, read: $read, subsId: $subsId, sealed ${ellipse(
sealed)}';
}
static final Map<String, Route<Null>> routes = <String, Route<Null>>{};
Route<Null> getRoute(Store store) {
final String routeName = '/fire/${id}';
return routes.putIfAbsent(
routeName,
() => new MaterialPageRoute<Null>(
settings: new RouteSettings(name: routeName),
builder: (BuildContext context) {
store.dispatch(new ShowFireNotificationMapAction(this));
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new genericMap()));
},
),
);
}
}

View file

@ -10,12 +10,14 @@ part of 'fireNotification.dart';
FireNotification _$FireNotificationFromJson(Map<String, dynamic> json) =>
new FireNotification(
id: _objectIdFromJson(json['id'] as String),
id: objectIdFromJson(json['id'] as String),
lat: (json['lat'] as num).toDouble(),
lon: (json['lon'] as num).toDouble(),
description: json['description'] as String,
when: DateTime.parse(json['when'] as String),
read: json['read'] as bool);
read: json['read'] as bool,
sealed: json['sealed'] as String,
subsId: objectIdFromJson(json['subsId'] as String));
abstract class _$FireNotificationSerializerMixin {
ObjectId get id;
@ -23,6 +25,8 @@ abstract class _$FireNotificationSerializerMixin {
double get lon;
String get description;
DateTime get when;
String get sealed;
ObjectId get subsId;
bool get read;
Map<String, dynamic> toJson() => new _$FireNotificationJsonMapWrapper(this);
}
@ -32,15 +36,23 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
_$FireNotificationJsonMapWrapper(this._v);
@override
Iterable<String> get keys =>
const ['id', 'lat', 'lon', 'description', 'when', 'read'];
Iterable<String> get keys => const [
'id',
'lat',
'lon',
'description',
'when',
'sealed',
'subsId',
'read'
];
@override
dynamic operator [](Object key) {
if (key is String) {
switch (key) {
case 'id':
return _objectIdToJson(_v.id);
return objectIdToJson(_v.id);
case 'lat':
return _v.lat;
case 'lon':
@ -49,6 +61,10 @@ class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
return _v.description;
case 'when':
return _v.when.toIso8601String();
case 'sealed':
return _v.sealed;
case 'subsId':
return objectIdToJson(_v.subsId);
case 'read':
return _v.read;
}

View file

@ -1,20 +1,15 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:fires_flutter/objectIdUtils.dart';
part 'yourLocation.g.dart';
_objectIdFromJson(String json) {
return new ObjectId.fromHexString(json);
}
_objectIdToJson(ObjectId o) {
return o.toString();
}
@JsonSerializable(nullable: false)
class YourLocation extends Object with _$YourLocationSerializerMixin {
@JsonKey(toJson: _objectIdToJson, fromJson: _objectIdFromJson)
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id;
final double lat;
final double lon;

View file

@ -10,7 +10,7 @@ part of 'yourLocation.dart';
YourLocation _$YourLocationFromJson(Map<String, dynamic> json) =>
new YourLocation(
id: _objectIdFromJson(json['id'] as String),
id: objectIdFromJson(json['id'] as String),
lat: (json['lat'] as num).toDouble(),
lon: (json['lon'] as num).toDouble(),
description: json['description'] as String,
@ -40,7 +40,7 @@ class _$YourLocationJsonMapWrapper extends $JsonMapWrapper {
if (key is String) {
switch (key) {
case 'id':
return _objectIdToJson(_v.id);
return objectIdToJson(_v.id);
case 'lat':
return _v.lat;
case 'lon':