Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/app/map/_lib/managers/precipitation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class PrecipitationMapLayerManager extends MapLayerManager {
final currentPrecipitationInterval = ValueNotifier<String>('now');
final isLoading = ValueNotifier<bool>(false);

DateTime? _lastFetchTime;

Function(String)? onTimeChanged;

Future<void> setPrecipitationTime(String time) async {
Expand Down Expand Up @@ -108,6 +110,19 @@ class PrecipitationMapLayerManager extends MapLayerManager {
}
}

Future<void> _fetchData() async {
try {
final precipitationList = (await ExpTech().getRainList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setPrecipitation(precipitationList);
currentPrecipitationTime.value ??= precipitationList.first;
_lastFetchTime = DateTime.now();
} catch (e, s) {
TalkerManager.instance.error('PrecipitationMapLayerManager._fetchData', e, s);
}
}

@override
Future<void> setup() async {
if (didSetup) return;
Expand All @@ -116,11 +131,7 @@ class PrecipitationMapLayerManager extends MapLayerManager {

try {
if (GlobalProviders.data.precipitation.isEmpty) {
final precipitationList = (await ExpTech().getRainList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setPrecipitation(precipitationList);
currentPrecipitationTime.value = precipitationList.first;
await _fetchData();
}

final time = currentPrecipitationTime.value;
Expand Down Expand Up @@ -276,6 +287,8 @@ class PrecipitationMapLayerManager extends MapLayerManager {
await _focus();

visible = true;

if (_lastFetchTime == null || DateTime.now().difference(_lastFetchTime!).inMinutes > 5) await _fetchData();
} catch (e, s) {
TalkerManager.instance.error('PrecipitationMapLayerManager.show', e, s);
}
Expand Down
26 changes: 18 additions & 8 deletions lib/app/map/_lib/managers/radar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class RadarMapLayerManager extends MapLayerManager {
final playStartTime = ValueNotifier<String?>(null);
final playEndTime = ValueNotifier<String?>(null);

DateTime? _lastFetchTime;

Timer? _playTimer;
final Set<String> _preloadedLayers = {};
final int Function()? getActiveLayerCount;
Expand Down Expand Up @@ -324,21 +326,27 @@ class RadarMapLayerManager extends MapLayerManager {
}
}

Future<void> _fetchData() async {
final radarList = (await ExpTech().getRadarList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setRadar(radarList);
currentRadarTime.value ??= radarList.first;
_lastFetchTime = DateTime.now();
}

@override
Future<void> setup() async {
if (didSetup) return;

try {
if (GlobalProviders.data.radar.isEmpty) {
final radarList = (await ExpTech().getRadarList()).reversed.toList();
if (!context.mounted) return;
if (GlobalProviders.data.radar.isEmpty) await _fetchData();

GlobalProviders.data.setRadar(radarList);
currentRadarTime.value = radarList.first;
}
final time = currentRadarTime.value;
if (time == null) throw Exception('Time is null');

await _setupAndShowLayer(currentRadarTime.value!);
await _preloadAdjacentLayers(currentRadarTime.value!);
await _setupAndShowLayer(time);
await _preloadAdjacentLayers(time);

didSetup = true;
} catch (e, s) {
Expand Down Expand Up @@ -376,6 +384,8 @@ class RadarMapLayerManager extends MapLayerManager {
await _focus();

visible = true;

if (_lastFetchTime == null || DateTime.now().difference(_lastFetchTime!).inMinutes > 5) await _fetchData();
} catch (e, s) {
TalkerManager.instance.error('RadarMapLayerManager.show', e, s);
}
Expand Down
19 changes: 13 additions & 6 deletions lib/app/map/_lib/managers/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ReportMapLayerManager extends MapLayerManager {
final currentReport = ValueNotifier<PartialEarthquakeReport?>(null);
final isLoading = ValueNotifier<bool>(false);

DateTime? _lastFetchTime;

Future<void> setReport(String? reportId, {bool focus = true}) async {
if (isLoading.value) return;

Expand Down Expand Up @@ -96,17 +98,20 @@ class ReportMapLayerManager extends MapLayerManager {
);
}

Future<void> _fetchData() async {
final reportList = await ExpTech().getReportList();
if (!context.mounted) return;

GlobalProviders.data.setPartialReport(reportList);
_lastFetchTime = DateTime.now();
}

@override
Future<void> setup() async {
if (didSetup) return;

try {
if (GlobalProviders.data.partialReport.isEmpty) {
final reportList = await ExpTech().getReportList();
if (!context.mounted) return;

GlobalProviders.data.setPartialReport(reportList);
}
if (GlobalProviders.data.partialReport.isEmpty) await _fetchData();

final sourceId = MapSourceIds.report();
final layerId = MapLayerIds.report();
Expand Down Expand Up @@ -201,6 +206,8 @@ class ReportMapLayerManager extends MapLayerManager {
}

visible = true;

if (_lastFetchTime == null || DateTime.now().difference(_lastFetchTime!).inMinutes > 5) await _fetchData();
} catch (e, s) {
TalkerManager.instance.error('ReportMapLayerManager.show', e, s);
}
Expand Down
25 changes: 18 additions & 7 deletions lib/app/map/_lib/managers/temperature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class TemperatureMapLayerManager extends MapLayerManager {
final currentTemperatureTime = ValueNotifier<String?>(GlobalProviders.data.temperature.firstOrNull);
final isLoading = ValueNotifier<bool>(false);

DateTime? _lastFetchTime;

Function(String)? onTimeChanged;

Future<void> setTemperatureTime(String time) async {
Expand Down Expand Up @@ -86,20 +88,27 @@ class TemperatureMapLayerManager extends MapLayerManager {
}
}

Future<void> _fetchData() async {
try {
final temperatureList = (await ExpTech().getWeatherList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setTemperature(temperatureList);
currentTemperatureTime.value ??= temperatureList.first;
_lastFetchTime = DateTime.now();
} catch (e, s) {
TalkerManager.instance.error('TemperatureMapLayerManager._fetchData', e, s);
}
}

@override
Future<void> setup() async {
if (didSetup) return;

final colors = context.colors;

try {
if (GlobalProviders.data.temperature.isEmpty) {
final temperatureList = (await ExpTech().getWeatherList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setTemperature(temperatureList);
currentTemperatureTime.value = temperatureList.first;
}
if (GlobalProviders.data.temperature.isEmpty) await _fetchData();

final time = currentTemperatureTime.value;

Expand Down Expand Up @@ -248,6 +257,8 @@ class TemperatureMapLayerManager extends MapLayerManager {
await _focus();

visible = true;

if (_lastFetchTime == null || DateTime.now().difference(_lastFetchTime!).inMinutes > 5) await _fetchData();
} catch (e, s) {
TalkerManager.instance.error('TemperatureMapLayerManager.show', e, s);
}
Expand Down
21 changes: 14 additions & 7 deletions lib/app/map/_lib/managers/wind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class WindMapLayerManager extends MapLayerManager {
final currentWindTime = ValueNotifier<String?>(GlobalProviders.data.wind.firstOrNull);
final isLoading = ValueNotifier<bool>(false);

DateTime? _lastFetchTime;

Function(String)? onTimeChanged;

Future<void> setWindTime(String time) async {
Expand All @@ -64,20 +66,23 @@ class WindMapLayerManager extends MapLayerManager {
}
}

Future<void> _fetchData() async {
final windList = (await ExpTech().getWeatherList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setWind(windList);
currentWindTime.value ??= windList.first;
_lastFetchTime = DateTime.now();
}

@override
Future<void> setup() async {
if (didSetup) return;

final colors = context.colors;

try {
if (GlobalProviders.data.wind.isEmpty) {
final windList = (await ExpTech().getWeatherList()).reversed.toList();
if (!context.mounted) return;

GlobalProviders.data.setWind(windList);
currentWindTime.value = windList.first;
}
if (GlobalProviders.data.wind.isEmpty) await _fetchData();

final time = currentWindTime.value;

Expand Down Expand Up @@ -201,6 +206,8 @@ class WindMapLayerManager extends MapLayerManager {
await controller.setLayerVisibility('$layerId-label', true);

visible = true;

if (_lastFetchTime == null || DateTime.now().difference(_lastFetchTime!).inMinutes > 5) await _fetchData();
} catch (e, s) {
TalkerManager.instance.error('WindMapLayerManager.show', e, s);
}
Expand Down
Loading