More fire stats
This commit is contained in:
parent
9dd8a7de97
commit
74b0d37839
6 changed files with 54 additions and 9 deletions
|
|
@ -25,6 +25,7 @@ class _ViewModel {
|
||||||
final DeleteYourLocationFunction onDelete;
|
final DeleteYourLocationFunction onDelete;
|
||||||
final ToggleSubscriptionFunction onToggleSubs;
|
final ToggleSubscriptionFunction onToggleSubs;
|
||||||
final OnLocationTapFunction onTap;
|
final OnLocationTapFunction onTap;
|
||||||
|
final OnRefreshYourLocationsFunction onRefresh;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
|
|
||||||
_ViewModel(
|
_ViewModel(
|
||||||
|
|
@ -32,6 +33,7 @@ class _ViewModel {
|
||||||
@required this.onDelete,
|
@required this.onDelete,
|
||||||
@required this.onToggleSubs,
|
@required this.onToggleSubs,
|
||||||
@required this.onTap,
|
@required this.onTap,
|
||||||
|
@required this.onRefresh,
|
||||||
@required this.yourLocations,
|
@required this.yourLocations,
|
||||||
@required this.isLoading});
|
@required this.isLoading});
|
||||||
|
|
||||||
|
|
@ -91,7 +93,12 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
loc.subscribed = !loc.subscribed;
|
loc.subscribed = !loc.subscribed;
|
||||||
onToggle(loc);
|
onToggle(loc);
|
||||||
}),
|
}),
|
||||||
title: new Text(loc.description),
|
title:
|
||||||
|
new Text(loc.description)
|
||||||
|
,
|
||||||
|
subtitle: loc.currentNumFires == YourLocation.withoutStats ||
|
||||||
|
loc.currentNumFires == 0 ? null: new Text(S.of(context).firesAroundThisArea(
|
||||||
|
loc.currentNumFires.toString(), loc.distance.toString())),
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
showSnackMsg(S.of(context).toDeleteThisPlace);
|
showSnackMsg(S.of(context).toDeleteThisPlace);
|
||||||
},
|
},
|
||||||
|
|
@ -173,6 +180,8 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
onTap: (loc) {
|
onTap: (loc) {
|
||||||
gotoLocationMap(store, loc, context);
|
gotoLocationMap(store, loc, context);
|
||||||
},
|
},
|
||||||
|
onRefresh: (refreshCallback) =>
|
||||||
|
store.dispatch(new FetchYourLocationsAction(refreshCallback)),
|
||||||
yourLocations: store.state.yourLocations,
|
yourLocations: store.state.yourLocations,
|
||||||
isLoading: !store.state.isLoaded);
|
isLoading: !store.state.isLoaded);
|
||||||
},
|
},
|
||||||
|
|
@ -203,8 +212,19 @@ class _ActiveFiresPageState extends State<ActiveFiresPage> {
|
||||||
? new SpinKitPulse(color: fires600)
|
? new SpinKitPulse(color: fires600)
|
||||||
: hasLocations
|
: hasLocations
|
||||||
? new Stack(children: <Widget>[
|
? new Stack(children: <Widget>[
|
||||||
_buildSavedLocations(context, view.yourLocations,
|
new RefreshIndicator(
|
||||||
view.onDelete, view.onToggleSubs, view.onTap),
|
child: _buildSavedLocations(
|
||||||
|
context,
|
||||||
|
view.yourLocations,
|
||||||
|
view.onDelete,
|
||||||
|
view.onToggleSubs,
|
||||||
|
view.onTap),
|
||||||
|
onRefresh: () async {
|
||||||
|
final Completer<Null> completer =
|
||||||
|
new Completer<Null>();
|
||||||
|
view.onRefresh(completer);
|
||||||
|
return completer.future;
|
||||||
|
}),
|
||||||
new FabDialer(_fabMiniMenuItemList(context, view.onAdd),
|
new FabDialer(_fabMiniMenuItemList(context, view.onAdd),
|
||||||
fires600, new Icon(Icons.add))
|
fires600, new Icon(Icons.add))
|
||||||
])
|
])
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ import 'package:fires_flutter/models/fireNotification.dart';
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'fireMapState.dart';
|
import 'fireMapState.dart';
|
||||||
import 'user.dart';
|
import 'user.dart';
|
||||||
|
|
@ -95,6 +97,7 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
||||||
|
|
||||||
typedef void AddYourLocationFunction(YourLocation loc);
|
typedef void AddYourLocationFunction(YourLocation loc);
|
||||||
typedef void DeleteYourLocationFunction(YourLocation loc);
|
typedef void DeleteYourLocationFunction(YourLocation loc);
|
||||||
|
typedef void OnRefreshYourLocationsFunction(Completer<Null> callback);
|
||||||
typedef void ToggleSubscriptionFunction(YourLocation loc);
|
typedef void ToggleSubscriptionFunction(YourLocation loc);
|
||||||
typedef void OnLocationTapFunction(YourLocation loc);
|
typedef void OnLocationTapFunction(YourLocation loc);
|
||||||
typedef void OnSubscribeFunction(YourLocation loc);
|
typedef void OnSubscribeFunction(YourLocation loc);
|
||||||
|
|
|
||||||
|
|
@ -16,18 +16,20 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
String description;
|
String description;
|
||||||
bool subscribed;
|
bool subscribed;
|
||||||
int distance;
|
int distance;
|
||||||
|
int currentNumFires;
|
||||||
|
|
||||||
factory YourLocation.fromJson(Map<String, dynamic> json) =>
|
factory YourLocation.fromJson(Map<String, dynamic> json) =>
|
||||||
_$YourLocationFromJson(json);
|
_$YourLocationFromJson(json);
|
||||||
|
|
||||||
static YourLocation noLocation = new YourLocation(lat: 0.0, lon: 0.0);
|
static YourLocation noLocation = new YourLocation(lat: 0.0, lon: 0.0);
|
||||||
|
static const int withoutStats = null;
|
||||||
YourLocation(
|
YourLocation(
|
||||||
{this.id,
|
{this.id,
|
||||||
@required this.lat,
|
@required this.lat,
|
||||||
@required this.lon,
|
@required this.lon,
|
||||||
this.description,
|
this.description,
|
||||||
this.distance: 10,
|
this.distance: 10,
|
||||||
|
int currentNumFires: withoutStats,
|
||||||
this.subscribed: false}) {
|
this.subscribed: false}) {
|
||||||
if (this.description == null)
|
if (this.description == null)
|
||||||
this.description = 'Position: ${this.lat}, ${this.lon}';
|
this.description = 'Position: ${this.lat}, ${this.lon}';
|
||||||
|
|
@ -40,6 +42,7 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
lon,
|
lon,
|
||||||
description,
|
description,
|
||||||
distance,
|
distance,
|
||||||
|
currentNumFires,
|
||||||
subscribed}) {
|
subscribed}) {
|
||||||
return new YourLocation(
|
return new YourLocation(
|
||||||
id: id?? this.id,
|
id: id?? this.id,
|
||||||
|
|
@ -47,6 +50,7 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
lon: lon?? this.lon,
|
lon: lon?? this.lon,
|
||||||
description: description?? this.description,
|
description: description?? this.description,
|
||||||
distance: distance?? this.distance,
|
distance: distance?? this.distance,
|
||||||
|
currentNumFires: currentNumFires ?? this.currentNumFires,
|
||||||
subscribed: subscribed?? this.subscribed
|
subscribed: subscribed?? this.subscribed
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +66,7 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
lon == other.lon &&
|
lon == other.lon &&
|
||||||
description == other.description &&
|
description == other.description &&
|
||||||
subscribed == other.subscribed &&
|
subscribed == other.subscribed &&
|
||||||
|
currentNumFires == other.currentNumFires &&
|
||||||
distance == other.distance;
|
distance == other.distance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -71,10 +76,11 @@ class YourLocation extends Object with _$YourLocationSerializerMixin {
|
||||||
lon.hashCode ^
|
lon.hashCode ^
|
||||||
description.hashCode ^
|
description.hashCode ^
|
||||||
subscribed.hashCode ^
|
subscribed.hashCode ^
|
||||||
|
currentNumFires.hashCode ^
|
||||||
distance.hashCode;
|
distance.hashCode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'YourLocation {id: $id, lat: $lat, lon: $lon, description: $description, subscribed: $subscribed, distance: $distance}';
|
return 'YourLocation {id: $id, lat: $lat, lon: $lon, description: $description, subscribed: $subscribed, distance: $distance, currentNumFires: $currentNumFires}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
import 'package:fires_flutter/models/yourLocation.dart';
|
import 'package:fires_flutter/models/yourLocation.dart';
|
||||||
import 'package:fires_flutter/models/fireNotification.dart';
|
import 'package:fires_flutter/models/fireNotification.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
abstract class AppActions {}
|
abstract class AppActions {}
|
||||||
|
|
||||||
class FetchYourLocationsAction extends AppActions {}
|
class FetchYourLocationsAction extends AppActions {
|
||||||
|
Completer<Null> refreshCallback;
|
||||||
|
|
||||||
|
FetchYourLocationsAction([this.refreshCallback]);
|
||||||
|
}
|
||||||
|
|
||||||
class PersistAppStateAction extends AppActions {}
|
class PersistAppStateAction extends AppActions {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import 'package:fires_flutter/models/fireNotification.dart';
|
||||||
import 'package:flutter_simple_dependency_injection/injector.dart';
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
import 'package:just_debounce_it/just_debounce_it.dart';
|
import 'package:just_debounce_it/just_debounce_it.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import '../models/appState.dart';
|
import '../models/appState.dart';
|
||||||
import '../models/fireNotificationsPersist.dart';
|
import '../models/fireNotificationsPersist.dart';
|
||||||
|
|
@ -150,8 +151,20 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
||||||
localLocations.add(subsLoc);
|
localLocations.add(subsLoc);
|
||||||
}).subscribed = true;
|
}).subscribed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
localLocations.forEach((yl) {
|
||||||
|
api.getYourLocationFireStats(store.state, yl).then((value) {
|
||||||
|
yl.currentNumFires = value.numFires;
|
||||||
|
store.dispatch(new UpdateYourLocationAction(yl));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
store.dispatch(new FetchYourLocationsSucceededAction(localLocations));
|
store.dispatch(new FetchYourLocationsSucceededAction(localLocations));
|
||||||
persistYourLocations(localLocations);
|
persistYourLocations(localLocations);
|
||||||
|
Completer<Null> completer = action.refreshCallback;
|
||||||
|
if (completer != null) {
|
||||||
|
completer.complete(null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}).catchError((Exception error) {
|
}).catchError((Exception error) {
|
||||||
// If it fails, dispatch a failure action. The reducer will
|
// If it fails, dispatch a failure action. The reducer will
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,7 @@ class ToggledSubscriptionAction extends YourLocationActions {
|
||||||
ToggledSubscriptionAction(this.loc);
|
ToggledSubscriptionAction(this.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
class SubscribeAction extends YourLocationActions {
|
class SubscribeAction extends YourLocationActions {}
|
||||||
SubscribeAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
class SubscribeConfirmAction extends YourLocationActions {
|
class SubscribeConfirmAction extends YourLocationActions {
|
||||||
YourLocation loc;
|
YourLocation loc;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue