Last changes not published

This commit is contained in:
vjrj 2026-03-05 01:18:27 +01:00
parent ac65ccf990
commit 21ec08303a
43 changed files with 607 additions and 613 deletions

View file

@ -5,21 +5,21 @@ import 'package:connectivity/connectivity.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:latlong/latlong.dart';
import 'package:meta/meta.dart';
import 'fireMapState.dart';
import 'user.dart';
export 'fireMapState.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
part 'appState.g.dart';
@immutable
@JsonSerializable(nullable: false)
class AppState extends Object with _$AppStateSerializerMixin {
class AppState {
@JsonKey(ignore: true)
final bool isLoading;
@JsonKey(ignore: true)
@ -58,7 +58,7 @@ class AppState extends Object with _$AppStateSerializerMixin {
this.user: const User.initial(),
this.isLoading: false,
this.isLoaded: false,
this.error: null,
this.error,
this.gmapKey,
this.firesApiKey,
this.firesApiUrl,
@ -102,11 +102,7 @@ class AppState extends Object with _$AppStateSerializerMixin {
@override
String toString() {
return 'AppState{\nuser: ${user}\nconnectivity: ${connectivity
.toString()}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(
firesApiKey,
8)}\napiUrl: ${firesApiUrl}\nserverUrl: ${serverUrl}\nfireMapState: $fireMapState\nyourLocations count: ${yourLocations
.length}\nunread notif: ${fireNotificationsUnread}\nfireNotifications: ${fireNotifications}\nyourLocations: ${yourLocations}}';
return 'AppState{\nuser: $user\nconnectivity: ${connectivity.toString()}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(firesApiKey, 8)}\napiUrl: $firesApiUrl\nserverUrl: $serverUrl\nfireMapState: $fireMapState\nyourLocations count: ${yourLocations.length}\nunread notif: $fireNotificationsUnread\nfireNotifications: $fireNotifications\nyourLocations: $yourLocations}';
}
}

View file

@ -1,5 +1,3 @@
// Copyright (c) 2018, Comunes Association.
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'appState.dart';
@ -8,37 +6,30 @@ part of 'appState.dart';
// JsonSerializableGenerator
// **************************************************************************
AppState _$AppStateFromJson(Map<String, dynamic> json) => new AppState(
yourLocations: (json['yourLocations'] as List)
.map((e) => new YourLocation.fromJson(e as Map<String, dynamic>))
.toList(),
fireNotifications: (json['fireNotifications'] as List)
.map((e) => new FireNotification.fromJson(e as Map<String, dynamic>))
.toList());
abstract class _$AppStateSerializerMixin {
List<YourLocation> get yourLocations;
List<FireNotification> get fireNotifications;
Map<String, dynamic> toJson() => new _$AppStateJsonMapWrapper(this);
AppState _$AppStateFromJson(Map json) {
return $checkedNew('AppState', json, () {
final val = AppState(
yourLocations: $checkedConvert(
json,
'yourLocations',
(v) => (v as List)
.map((e) =>
YourLocation.fromJson(Map<String, dynamic>.from(e as Map)))
.toList()),
fireNotifications: $checkedConvert(
json,
'fireNotifications',
(v) => (v as List)
.map((e) => FireNotification.fromJson(
Map<String, dynamic>.from(e as Map)))
.toList()),
);
return val;
});
}
class _$AppStateJsonMapWrapper extends $JsonMapWrapper {
final _$AppStateSerializerMixin _v;
_$AppStateJsonMapWrapper(this._v);
@override
Iterable<String> get keys => const ['yourLocations', 'fireNotifications'];
@override
dynamic operator [](Object key) {
if (key is String) {
switch (key) {
case 'yourLocations':
return _v.yourLocations;
case 'fireNotifications':
return _v.fireNotifications;
}
}
return null;
}
}
Map<String, dynamic> _$AppStateToJson(AppState instance) => <String, dynamic>{
'yourLocations': instance.yourLocations.map((e) => e.toJson()).toList(),
'fireNotifications':
instance.fireNotifications.map((e) => e.toJson()).toList(),
};

View file

@ -1,13 +1,14 @@
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:objectid/objectid.dart';
import '../objectIdUtils.dart';
part 'fireNotification.g.dart';
@JsonSerializable(nullable: false)
class FireNotification extends Object with _$FireNotificationSerializerMixin {
class FireNotification {
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id;
final double lat;
@ -74,11 +75,11 @@ class FireNotification extends Object with _$FireNotificationSerializerMixin {
@override
String toString() {
return 'FireNotification {id: $id, lat: $lat, lon: $lon, when: $when, read: $read, subsId: $subsId, sealed ${ellipse(
sealed)}';
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>>{};
Map<String, dynamic> toJson() => _$FireNotificationToJson(this);
/*
Route<Null> getRoute(Store store) {

View file

@ -1,5 +1,3 @@
// Copyright (c) 2018, Comunes Association.
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'fireNotification.dart';
@ -8,67 +6,31 @@ part of 'fireNotification.dart';
// JsonSerializableGenerator
// **************************************************************************
FireNotification _$FireNotificationFromJson(Map<String, dynamic> json) =>
new FireNotification(
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,
sealed: json['sealed'] as String,
subsId: objectIdFromJson(json['subsId'] as String));
abstract class _$FireNotificationSerializerMixin {
ObjectId get id;
double get lat;
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);
FireNotification _$FireNotificationFromJson(Map json) {
return $checkedNew('FireNotification', json, () {
final val = FireNotification(
id: $checkedConvert(json, 'id', (v) => objectIdFromJson(v as String)),
lat: $checkedConvert(json, 'lat', (v) => (v as num).toDouble()),
lon: $checkedConvert(json, 'lon', (v) => (v as num).toDouble()),
description: $checkedConvert(json, 'description', (v) => v as String),
when: $checkedConvert(json, 'when', (v) => DateTime.parse(v as String)),
read: $checkedConvert(json, 'read', (v) => v as bool),
sealed: $checkedConvert(json, 'sealed', (v) => v as String),
subsId:
$checkedConvert(json, 'subsId', (v) => objectIdFromJson(v as String)),
);
return val;
});
}
class _$FireNotificationJsonMapWrapper extends $JsonMapWrapper {
final _$FireNotificationSerializerMixin _v;
_$FireNotificationJsonMapWrapper(this._v);
@override
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);
case 'lat':
return _v.lat;
case 'lon':
return _v.lon;
case 'description':
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;
}
}
return null;
}
}
Map<String, dynamic> _$FireNotificationToJson(FireNotification instance) =>
<String, dynamic>{
'id': objectIdToJson(instance.id),
'lat': instance.lat,
'lon': instance.lon,
'description': instance.description,
'when': instance.when.toIso8601String(),
'sealed': instance.sealed,
'subsId': objectIdToJson(instance.subsId),
'read': instance.read,
};

View file

@ -1,8 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import '../globals.dart' as globals;
final String fireNotificationKey = 'fireNotifications';
@ -10,7 +11,7 @@ final String fireNotificationKey = 'fireNotifications';
Future<List<FireNotification>> loadFireNotifications() async {
return await globals.prefs.then((prefs) {
List<String> FireNotifications = prefs.getStringList(fireNotificationKey);
List<FireNotification> persistedList = List<FireNotification>();
List<FireNotification> persistedList = [];
if (FireNotifications == null) {
FireNotifications = [];
// first run, init with empty list

View file

@ -1,26 +1,26 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter/material.dart';
import 'falsePositiveTypes.dart';
import 'package:bson_objectid/bson_objectid.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:http/http.dart' as ht;
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
import 'package:latlong/latlong.dart';
import '../globals.dart' as globals;
import '../objectIdUtils.dart';
import '../redux/actions.dart';
import 'appState.dart';
import 'falsePositiveTypes.dart';
class FiresApi {
FiresApi() {
resty.globalClient = new ht.IOClient();
}
Future<String> createUser(AppState state, String mobileToken,
String lang) async {
Future<String> createUser(
AppState state, String mobileToken, String lang) async {
assert(state.firesApiUrl != null);
assert(state.firesApiKey != null);
assert(mobileToken != null);
@ -38,6 +38,8 @@ class FiresApi {
if (response.statusCode == 200) {
// print(response.body);
return json.decode(response.body)['data']['userId'];
} else {
return throw "Unexpected error on create user";
}
});
}
@ -45,28 +47,29 @@ class FiresApi {
Future<List<YourLocation>> fetchYourLocations(AppState state) async {
final apiKey = state.firesApiKey;
final mobileToken = state.user.token;
final String url = '${state
.firesApiUrl}mobile/subscriptions/all/$apiKey/$mobileToken';
final String url =
'${state.firesApiUrl}mobile/subscriptions/all/$apiKey/$mobileToken';
// if (globals.isDevelopment) print('$url');
return await resty.get(url).go().then((response) {
if (response.statusCode == 200) {
// if (globals.isDevelopment) print(response.body);
final dataSubscriptions =
json.decode(response.body)['data']['subscriptions'];
json.decode(response.body)['data']['subscriptions'];
List<YourLocation> subscribed = [];
for (int i = 0; i < dataSubscriptions.length; i++) {
var el = dataSubscriptions[i];
var lat = el['location']['lat'];
var lon = el['location']['lon'];
subscribed.add(new YourLocation(
id: ObjectId.fromHexString(el['_id']['_str']),
lat: lat,
lon: lon,
subscribed: true,
distance: el['distance']));
id: objectIdFromJson(el['_id']['_str']),
lat: lat,
lon: lon,
subscribed: true,
distance: el['distance']));
}
return subscribed;
} else {
return throw "Unexpected error fetching your locations";
}
});
}
@ -83,13 +86,12 @@ class FiresApi {
final params = {
"token": state.firesApiKey,
"mobileToken": state.user.token,
"id": loc.id.toHexString(),
"id": loc.id.hexString,
"lat": loc.lat,
"lon": loc.lon,
"distance": loc.distance
};
final String url = '${state
.firesApiUrl}mobile/subscriptions';
final String url = '${state.firesApiUrl}mobile/subscriptions';
return await resty.post(url).json(params).go().then((response) {
if (response.statusCode == 200) {
// print(response.body);
@ -97,6 +99,7 @@ class FiresApi {
} else {
// take care of? "Unexpected error in REST call: Error: The user is already subscribed to this area [on-already-subscribed]"
print(response.body);
return throw "Unexpected error on subscribe";
}
});
}
@ -108,22 +111,24 @@ class FiresApi {
final apiKey = state.firesApiKey;
final mobileToken = state.user.token;
assert(subsId != null);
final String url = '${state
.firesApiUrl}mobile/subscriptions/$apiKey/$mobileToken/$subsId';
final String url =
'${state.firesApiUrl}mobile/subscriptions/$apiKey/$mobileToken/$subsId';
return await resty.delete(url).go().then((response) {
if (response.statusCode == 200) {
// print(response.body);
return true;
} else {
return throw "Unexpected error on unsubscribe";
}
});
}
Future<UpdateFireMapStatsAction> getFiresInLocation(
{AppState state, double lat, double lon, int distance}) async {
{AppState state, double lat, double lon, int distance}) async {
assert(state.firesApiUrl != null);
assert(state.firesApiKey != null);
var url = '${state.firesApiUrl}fires-in-full/${state
.firesApiKey}/${lat}/${lon}/${distance}';
var url =
'${state.firesApiUrl}fires-in-full/${state.firesApiKey}/$lat/$lon/$distance';
if (globals.isDevelopment) print(url);
return await resty.get(url).go().then((response) {
if (response.statusCode == 200) {
@ -138,13 +143,13 @@ class FiresApi {
var industriesCount = industries.length;
var falsePosCount = falsePos.length;
print(
'(Pos: $lat, $lon) real: $numFires, fire: $firesCount falsePos: $falsePosCount industries: $industriesCount');
'(Pos: $lat, $lon) real: $numFires, fire: $firesCount falsePos: $falsePosCount industries: $industriesCount');
}
return new UpdateFireMapStatsAction(
numFires: numFires,
fires: fires,
falsePos: falsePos,
industries: industries);
numFires: numFires,
fires: fires,
falsePos: falsePos,
industries: industries);
} else
throw Exception('Wrong response trying to get fire data');
});
@ -153,8 +158,8 @@ class FiresApi {
Future<List<Polyline>> getMonitoredAreas({AppState state}) async {
assert(state.firesApiUrl != null);
assert(state.firesApiKey != null);
var url = '${state.firesApiUrl}status/subs-public-union/${state
.firesApiKey}';
var url =
'${state.firesApiUrl}status/subs-public-union/${state.firesApiKey}';
var color = const Color(0xFF145A32);
return await resty.get(url).go().then((response) {
if (response.statusCode == 200) {
@ -162,8 +167,8 @@ class FiresApi {
// print(resultDecoded['data']['union']);
List<Polyline> union = [];
final multipolygon =
json.decode(resultDecoded['data']['union']['value'])['geometry']
['coordinates'];
json.decode(resultDecoded['data']['union']['value'])['geometry']
['coordinates'];
for (List<dynamic> polygon in multipolygon) {
for (List<dynamic> hole in polygon) {
List<LatLng> points = [];
@ -171,7 +176,7 @@ class FiresApi {
points.add(new LatLng(point[1].toDouble(), point[0].toDouble()));
}
union.add(
new Polyline(points: points, color: color, strokeWidth: 3.0));
new Polyline(points: points, color: color, strokeWidth: 3.0));
}
}
return union;
@ -181,7 +186,7 @@ class FiresApi {
}
Future<bool> markFalsePositive(AppState state, String mobileToken,
String sealed, FalsePositiveType type) async {
String sealed, FalsePositiveType type) async {
assert(state.firesApiUrl != null);
assert(state.firesApiKey != null);
assert(mobileToken != null);
@ -198,8 +203,8 @@ class FiresApi {
return await resty.post(url).json(params).go().then((response) {
if (response.statusCode == 200) {
// print(response.body);
if (globals.isDevelopment) print(
json.decode(response.body)['data']['upsert']);
if (globals.isDevelopment)
print(json.decode(response.body)['data']['upsert']);
return true;
} else {
debugPrint(json.decode(response.body));

View file

@ -1,14 +1,12 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:fires_flutter/objectIdUtils.dart';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:fires_flutter/objectIdUtils.dart';
import 'package:objectid/objectid.dart';
part 'yourLocation.g.dart';
@JsonSerializable(nullable: false)
class YourLocation extends Object with _$YourLocationSerializerMixin {
class YourLocation {
@JsonKey(toJson: objectIdToJson, fromJson: objectIdFromJson)
ObjectId id;
final double lat;
@ -22,40 +20,33 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
_$YourLocationFromJson(json);
static YourLocation noLocation = new YourLocation(lat: 0.0, lon: 0.0);
static const int withoutStats = null;
static const int withoutStats = null;
YourLocation(
{this.id,
@required this.lat,
@required this.lon,
this.description,
this.distance: 10,
int currentNumFires: withoutStats,
int currentNumFires: withoutStats,
this.subscribed: false}) {
if (this.description == null)
this.description = 'Position: ${this.lat}, ${this.lon}';
if (this.id == null) this.id = new ObjectId();
}
Map<String, dynamic> toJson() => _$YourLocationToJson(this);
YourLocation copyWith(
{id,
lat,
lon,
description,
distance,
currentNumFires,
subscribed}) {
{id, lat, lon, description, distance, currentNumFires, subscribed}) {
return new YourLocation(
id: id?? this.id,
lat: lat?? this.lat,
lon: lon?? this.lon,
description: description?? this.description,
distance: distance?? this.distance,
currentNumFires: currentNumFires ?? this.currentNumFires,
subscribed: subscribed?? this.subscribed
);
id: id ?? this.id,
lat: lat ?? this.lat,
lon: lon ?? this.lon,
description: description ?? this.description,
distance: distance ?? this.distance,
currentNumFires: currentNumFires ?? this.currentNumFires,
subscribed: subscribed ?? this.subscribed);
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
@ -66,7 +57,7 @@ static const int withoutStats = null;
lon == other.lon &&
description == other.description &&
subscribed == other.subscribed &&
currentNumFires == other.currentNumFires &&
currentNumFires == other.currentNumFires &&
distance == other.distance;
@override

View file

@ -1,5 +1,3 @@
// Copyright (c) 2018, Comunes Association.
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'yourLocation.dart';
@ -8,51 +6,29 @@ part of 'yourLocation.dart';
// JsonSerializableGenerator
// **************************************************************************
YourLocation _$YourLocationFromJson(Map<String, dynamic> json) =>
new YourLocation(
id: objectIdFromJson(json['id'] as String),
lat: (json['lat'] as num).toDouble(),
lon: (json['lon'] as num).toDouble(),
description: json['description'] as String,
distance: json['distance'] as int,
subscribed: json['subscribed'] as bool);
abstract class _$YourLocationSerializerMixin {
ObjectId get id;
double get lat;
double get lon;
String get description;
bool get subscribed;
int get distance;
Map<String, dynamic> toJson() => new _$YourLocationJsonMapWrapper(this);
YourLocation _$YourLocationFromJson(Map json) {
return $checkedNew('YourLocation', json, () {
final val = YourLocation(
id: $checkedConvert(json, 'id', (v) => objectIdFromJson(v as String)),
lat: $checkedConvert(json, 'lat', (v) => (v as num).toDouble()),
lon: $checkedConvert(json, 'lon', (v) => (v as num).toDouble()),
description: $checkedConvert(json, 'description', (v) => v as String),
distance: $checkedConvert(json, 'distance', (v) => v as int),
currentNumFires:
$checkedConvert(json, 'currentNumFires', (v) => v as int),
subscribed: $checkedConvert(json, 'subscribed', (v) => v as bool),
);
return val;
});
}
class _$YourLocationJsonMapWrapper extends $JsonMapWrapper {
final _$YourLocationSerializerMixin _v;
_$YourLocationJsonMapWrapper(this._v);
@override
Iterable<String> get keys =>
const ['id', 'lat', 'lon', 'description', 'subscribed', 'distance'];
@override
dynamic operator [](Object key) {
if (key is String) {
switch (key) {
case 'id':
return objectIdToJson(_v.id);
case 'lat':
return _v.lat;
case 'lon':
return _v.lon;
case 'description':
return _v.description;
case 'subscribed':
return _v.subscribed;
case 'distance':
return _v.distance;
}
}
return null;
}
}
Map<String, dynamic> _$YourLocationToJson(YourLocation instance) =>
<String, dynamic>{
'id': objectIdToJson(instance.id),
'lat': instance.lat,
'lon': instance.lon,
'description': instance.description,
'subscribed': instance.subscribed,
'distance': instance.distance,
'currentNumFires': instance.currentNumFires,
};

View file

@ -1,8 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:comunes_flutter/comunes_flutter.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import '../globals.dart' as globals;
final String locationKey = 'yourlocations';
@ -10,7 +11,7 @@ final String locationKey = 'yourlocations';
Future<List<YourLocation>> loadYourLocations() async {
return await globals.prefs.then((prefs) {
List<String> yourLocations = prefs.getStringList(locationKey);
List<YourLocation> persistedList = List<YourLocation>();
List<YourLocation> persistedList = [];
if (yourLocations == null) {
yourLocations = [];
// first run, init with empty list