diff --git a/lib/data/realm_helper.dart b/lib/data/realm_helper.dart index 830cc16..2049418 100644 --- a/lib/data/realm_helper.dart +++ b/lib/data/realm_helper.dart @@ -5,13 +5,6 @@ import 'package:avaremp/data/user_plan.dart'; import 'package:avaremp/data/user_recent.dart'; import 'package:avaremp/data/user_settings.dart'; import 'package:avaremp/data/user_wnb.dart'; -import 'package:avaremp/data/weather_airep.dart'; -import 'package:avaremp/data/weather_airsigmet.dart'; -import 'package:avaremp/data/weather_metar.dart'; -import 'package:avaremp/data/weather_notam.dart'; -import 'package:avaremp/data/weather_taf.dart'; -import 'package:avaremp/data/weather_tfr.dart'; -import 'package:avaremp/data/weather_winds.dart'; import 'package:avaremp/wnb.dart'; import 'package:latlong2/latlong.dart'; import 'package:realm/realm.dart'; @@ -20,13 +13,6 @@ import 'package:avaremp/checklist.dart'; import 'package:avaremp/destination/destination.dart'; import 'package:avaremp/plan/plan_route.dart'; import 'package:avaremp/storage.dart'; -import 'package:avaremp/weather/airep.dart'; -import 'package:avaremp/weather/airsigmet.dart'; -import 'package:avaremp/weather/metar.dart'; -import 'package:avaremp/weather/notam.dart'; -import 'package:avaremp/weather/taf.dart'; -import 'package:avaremp/weather/tfr.dart'; -import 'package:avaremp/weather/winds_aloft.dart'; class RealmHelper { @@ -41,7 +27,7 @@ class RealmHelper { // local syncs final Configuration _config = Configuration.local( [ - WeatherAirep.schema, WeatherWinds.schema, WeatherMetar.schema, WeatherTaf.schema, WeatherTfr.schema, WeatherAirSigmet.schema, WeatherNotam.schema, UserSettings.schema, UserRecent.schema, UserPlan.schema, UserAircraft.schema, UserChecklist.schema, UserWnb.schema + UserSettings.schema, UserRecent.schema, UserPlan.schema, UserAircraft.schema, UserChecklist.schema, UserWnb.schema ], schemaVersion: _schemaVersion, migrationCallback: (realm, version) { @@ -569,553 +555,4 @@ class RealmHelper { return ret; } - - void addWindsAloft(WindsAloft wa) { - - deleteWindsAloft(wa.station); - - WeatherWinds object = WeatherWinds(ObjectId(), - wa.station, - wa.expires.millisecondsSinceEpoch, - wa.w0k, - wa.w3k, - wa.w6k, - wa.w9k, - wa.w12k, - wa.w18k, - wa.w24k, - wa.w30k, - wa.w34k, - wa.w39k); - - _realm.write(() { - _realm.add(object); - }); - - } - - Future addWindsAlofts(List wa) async { - - if(wa.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(wa.map((w) { - WeatherWinds object = WeatherWinds(ObjectId(), - w.station, - w.expires.millisecondsSinceEpoch, - w.w0k, - w.w3k, - w.w6k, - w.w9k, - w.w12k, - w.w18k, - w.w24k, - w.w30k, - w.w34k, - w.w39k); - return object; - })); - }); - } - - WindsAloft? getWindsAloft(String station) { - try { - WeatherWinds object = _realm - .all() - .query("station = '$station'") - .first; - return WindsAloft( - object.station, - DateTime.fromMillisecondsSinceEpoch(object.utcMs), - object.w0k, - object.w3k, - object.w6k, - object.w9k, - object.w12k, - object.w18k, - object.w24k, - object.w30k, - object.w34k, - object.w39k, - ); - } catch(e) { - return null; - } - } - - Future> getAllWindsAloft() async { - - RealmResults entries = _realm.all(); - - return entries.map((e) { - return WindsAloft( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.w0k, - e.w3k, - e.w6k, - e.w9k, - e.w12k, - e.w18k, - e.w24k, - e.w30k, - e.w34k, - e.w39k, - ); - }).toList(); - } - - void deleteWindsAloft(String station) { - - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - - } - - void addMetar(Metar metar) { - - deleteMetar(metar.station); - - WeatherMetar object = WeatherMetar(ObjectId(), - metar.station, - metar.text, - metar.expires.millisecondsSinceEpoch, - metar.category, - metar.coordinate.latitude, - metar.coordinate.longitude, - ); - - _realm.write(() { - _realm.add(object); - }); - } - - Future addMetars(List metar) async { - if(metar.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(metar.map((m) { - WeatherMetar object = WeatherMetar(ObjectId(), - m.station, - m.text, - m.expires.millisecondsSinceEpoch, - m.category, - m.coordinate.latitude, - m.coordinate.longitude, - ); - return object; - })); - }); - } - - - Metar? getMetar(String station) { - try { - WeatherMetar object = _realm - .all() - .query("station = '$station'") - .first; - return Metar( - object.station, - DateTime.fromMillisecondsSinceEpoch(object.utcMs), - object.raw, - object.category, - LatLng(object.ARPLatitude, object.ARPLongitude), - ); - } catch(e) { - return null; - } - } - - Future> getAllMetar() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - return Metar( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.raw, - e.category, - LatLng(e.ARPLatitude, e.ARPLongitude), - ); - }).toList(); - } - - void deleteMetar(String station) { - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - } - - - void addTaf(Taf taf) { - deleteTaf(taf.station); - - WeatherTaf object = WeatherTaf(ObjectId(), - taf.station, - taf.text, - taf.expires.millisecondsSinceEpoch, - taf.coordinate.latitude, - taf.coordinate.longitude, - ); - - _realm.write(() { - _realm.add(object); - }); - } - - Future addTafs(List taf) async { - if(taf.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(taf.map((t) { - WeatherTaf object = WeatherTaf(ObjectId(), - t.station, - t.text, - t.expires.millisecondsSinceEpoch, - t.coordinate.latitude, - t.coordinate.longitude, - ); - return object; - })); - }); - } - - - Taf? getTaf(String station) { - try { - WeatherTaf object = _realm - .all() - .query("station = '$station'") - .first; - return Taf( - object.station, - DateTime.fromMillisecondsSinceEpoch(object.utcMs), - object.raw, - LatLng(object.ARPLatitude, object.ARPLongitude), - ); - } catch(e) { - return null; - } - } - - Future> getAllTaf() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - return Taf( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.raw, - LatLng(e.ARPLatitude, e.ARPLongitude), - ); - }).toList(); - } - - void deleteTaf(String station) { - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - } - - void addTfr(Tfr tfr) { - deleteTfr(tfr.station); - - WeatherTfr object = WeatherTfr(ObjectId(), - tfr.station, - jsonEncode(tfr.coordinates), - tfr.expires.millisecondsSinceEpoch, - tfr.upperAltitude, - tfr.lowerAltitude, - tfr.msEffective, - tfr.msExpires, - tfr.labelCoordinate, - ); - - _realm.write(() { - _realm.add(object); - }); - } - - Future addTfrs(List tfr) async { - if(tfr.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(tfr.map((t) { - WeatherTfr object = WeatherTfr(ObjectId(), - t.station, - jsonEncode(t.coordinates), - t.expires.millisecondsSinceEpoch, - t.upperAltitude, - t.lowerAltitude, - t.msEffective, - t.msExpires, - t.labelCoordinate, - ); - return object; - })); - }); - } - - Tfr? getTfr(String station) { - try { - WeatherTfr object = _realm - .all() - .query("station = '$station'") - .first; - List coordinates = jsonDecode(object.coordinates); - List ll = []; - for(dynamic coordinate in coordinates) { - List cc = coordinate['coordinates']; - ll.add(LatLng(cc[1], cc[0])); - } - return Tfr( - object.station, - DateTime.fromMillisecondsSinceEpoch(object.utcMs), - ll, - object.upperAltitude, - object.lowerAltitude, - object.msEffective, - object.msExpires, - object.labelCoordinate, - ); - } catch(e) { - return null; - } - } - - Future> getAllTfr() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - List coordinates = jsonDecode(e.coordinates); - List ll = []; - for(dynamic coordinate in coordinates) { - List cc = coordinate['coordinates']; - ll.add(LatLng(cc[1], cc[0])); - } - return Tfr( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - ll, - e.upperAltitude, - e.lowerAltitude, - e.msEffective, - e.msExpires, - e.labelCoordinate, - ); - }).toList(); - } - - void deleteTfr(String station) { - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - } - - Future> getAllAirep() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - List coordinates = jsonDecode(e.coordinates); - - return Airep( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.raw, - LatLng(coordinates[0], coordinates[1]), - ); - }).toList(); - } - - Future addAireps(List aireps) async { - if(aireps.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(aireps.map((a) { - WeatherAirep object = WeatherAirep(ObjectId(), - a.station, - a.text, - a.expires.millisecondsSinceEpoch, - jsonEncode([a.coordinates.latitude, a.coordinates.longitude]), - ); - return object; - })); - }); - } - - void addAirep(Airep airep) { - deleteAirep(airep.station); - - WeatherAirep object = WeatherAirep(ObjectId(), - airep.station, - airep.text, - airep.expires.millisecondsSinceEpoch, - jsonEncode([airep.coordinates.latitude, airep.coordinates.longitude]), - ); - - _realm.write(() { - _realm.add(object); - }); - } - - void deleteAirep(String station) { - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - } - - - Future> getAllAirSigmet() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - List coordinates = jsonDecode(e.coordinates); - List ll = []; - for(dynamic coordinate in coordinates) { - ll.add(LatLng(coordinate[0], coordinate[1])); - } - - return AirSigmet( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.raw, - ll, - e.hazard, - e.severity, - e.type, - ); - }).toList(); - } - - Future addAirSigmets(List airSigmet) async { - if(airSigmet.isEmpty) { - return; - } - - _realm.write(() { - _realm.deleteAll(); - }); - - _realm.write(() { - _realm.addAll(airSigmet.map((a) { - WeatherAirSigmet object = WeatherAirSigmet(ObjectId(), - a.station, - a.text, - a.expires.millisecondsSinceEpoch, - a.text, - jsonEncode(a.coordinates.map((c) => [c.latitude, c.longitude]).toList()), - a.hazard, - a.severity, - a.type, - ); - return object; - })); - }); - } - - Future> getAllNotams() async { - RealmResults entries = _realm.all(); - - return entries.map((e) { - return Notam( - e.station, - DateTime.fromMillisecondsSinceEpoch(e.utcMs), - e.text, - ); - }).toList(); - } - - Notam? getNotam(String station) { - try { - WeatherNotam object = _realm - .all() - .query("station = '$station'") - .first; - return Notam( - object.station, - DateTime.fromMillisecondsSinceEpoch(object.utcMs), - object.text, - ); - } catch(e) { - return null; - } - } - - void addNotam(Notam notam) { - deleteNotam(notam.station); - - WeatherNotam object = WeatherNotam(ObjectId(), - notam.station, - notam.text, - notam.expires.millisecondsSinceEpoch, - ); - - _realm.write(() { - _realm.add(object); - }); - } - - void deleteNotam(String station) { - RealmResults entries = _realm.all().query("station = '$station'"); - - try { - _realm.write(() { - _realm.delete(entries.first); - }); - } catch(e) {} - } - - } \ No newline at end of file diff --git a/lib/data/user_database_helper.dart b/lib/data/user_database_helper.dart new file mode 100644 index 0000000..12be9be --- /dev/null +++ b/lib/data/user_database_helper.dart @@ -0,0 +1,181 @@ +import 'dart:async'; +import 'dart:io'; +import 'package:avaremp/destination/destination.dart'; +import 'package:avaremp/plan/plan_route.dart'; +import 'package:avaremp/storage.dart'; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; + + + +class UserDatabaseHelper { + UserDatabaseHelper._(); + + static final UserDatabaseHelper _db = UserDatabaseHelper._(); + + static UserDatabaseHelper get db => _db; + static Database? _database; + + Future get database async { + if (_database != null) { + return _database; + } + _database = await _initDB(); + return _database; + } + + _initDB() async { + Directory documentsDirectory = Directory(Storage().dataDir); + String path = join(documentsDirectory.path, "user.db"); + return + await openDatabase( + path, + version: 1, + onCreate: (Database db, int version) async { + await db.execute("create table recent (" + "id integer primary key autoincrement, " + "LocationID text, " + "FacilityName text, " + "Type text, " + "ARPLatitude float, " + "ARPLongitude float, " + "unique(LocationID, Type) on conflict replace);"); + + await db.execute("create table plan (" + "id integer primary key autoincrement, " + "name text, " + "route text, " + "unique(name) on conflict replace);"); + + await db.execute("create table settings (" + "key text primary key, " + "value text, " + "unique(key) on conflict replace);"); + + }, + onOpen: (db) {}); + } + + Future addRecent(Destination recent) async { + final db = await database; + + if (db != null) { + await db.insert("recent", recent.toMap()); + } + } + + Future> getRecentAirports() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from recent where " + "Type='AIRPORT' or " + "Type='HELIPORT' or " + "Type='ULTRALIGHT' or " + "Type='BALLOONPORT' order by id desc;"); + return List.generate(maps.length, (i) { + return Destination.fromMap(maps[i]); + }); + } + return []; + } + + Future> getRecent() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from recent order by id desc"); // most recent first + return List.generate(maps.length, (i) { + return Destination.fromMap(maps[i]); + }); + } + return []; + } + + Future deleteRecent(Destination destination) async { + final db = await database; + if (db != null) { + await db.rawQuery("delete from recent where LocationID=" + "'${destination.locationID}' and Type='${destination.type}'"); + } + } + + Future addPlan(String name, PlanRoute route) async { + final db = await database; + + if (db != null) { // do not add empty plans + await db.insert("plan", route.toMap(name)); + } + } + + Future deletePlan(String name) async { + final db = await database; + + if (db != null) { + await db.rawQuery("delete from plan where name='$name'"); + } + } + + Future> getPlans() async { + List> maps = []; + List ret = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select name from plan order by id desc"); // most recent first + } + + for(Map map in maps) { + ret.add(map['name']); + } + return ret; + } + + Future getPlan(String name, bool reverse) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from plan where name='$name'"); // most recent first + } + + PlanRoute route = await PlanRoute.fromMap(maps[0], reverse); + return route; + } + + static Future insertSetting(Database? db, String key, String? value) { + Completer completer = Completer(); + Map map = {}; + map[key] = value; + + if(db != null) { + db.rawQuery("insert into settings (key, value) values ('$key', '$value')").then((value) => completer.complete()); + } + return completer.future; + } + + static Future deleteSetting(Database? db, String key) { + Completer completer = Completer(); + + if(db != null) { + db.rawQuery("delete from settings where key=$key;").then((value) => completer.complete()); + } + return completer.future; + } + + static Future deleteAllSettings(Database? db) { + Completer completer = Completer(); + + if(db != null) { + db.rawQuery("delete * settings;").then((value) => completer.complete()); + } + return completer.future; + } + + static Future>> getAllSettings(Database? db) async { + if(db != null) { + List> maps = await db.rawQuery("select * from settings;"); + return maps; + } + return []; + } + +} diff --git a/lib/data/weather_airep.dart b/lib/data/weather_airep.dart deleted file mode 100644 index 369a4e7..0000000 --- a/lib/data/weather_airep.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_airep.realm.dart'; - -@RealmModel() -class _WeatherAirep { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String raw; - late int utcMs; - late String coordinates; -} - diff --git a/lib/data/weather_airep.realm.dart b/lib/data/weather_airep.realm.dart deleted file mode 100644 index dee9cfe..0000000 --- a/lib/data/weather_airep.realm.dart +++ /dev/null @@ -1,108 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_airep.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherAirep extends _WeatherAirep - with RealmEntity, RealmObjectBase, RealmObject { - WeatherAirep( - ObjectId id, - String station, - String raw, - int utcMs, - String coordinates, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'raw', raw); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'coordinates', coordinates); - } - - WeatherAirep._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get raw => RealmObjectBase.get(this, 'raw') as String; - @override - set raw(String value) => RealmObjectBase.set(this, 'raw', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - String get coordinates => - RealmObjectBase.get(this, 'coordinates') as String; - @override - set coordinates(String value) => - RealmObjectBase.set(this, 'coordinates', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherAirep freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'raw': raw.toEJson(), - 'utcMs': utcMs.toEJson(), - 'coordinates': coordinates.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherAirep value) => value.toEJson(); - static WeatherAirep _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'raw': EJsonValue raw, - 'utcMs': EJsonValue utcMs, - 'coordinates': EJsonValue coordinates, - } => - WeatherAirep( - fromEJson(id), - fromEJson(station), - fromEJson(raw), - fromEJson(utcMs), - fromEJson(coordinates), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherAirep._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherAirep, 'WeatherAirep', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('raw', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('coordinates', RealmPropertyType.string), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_airsigmet.dart b/lib/data/weather_airsigmet.dart deleted file mode 100644 index 3ae9d57..0000000 --- a/lib/data/weather_airsigmet.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_airsigmet.realm.dart'; - -@RealmModel() -class _WeatherAirSigmet { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String text; - late int utcMs; - late String raw; - late String coordinates; - late String hazard; - late String severity; - late String type; -} - diff --git a/lib/data/weather_airsigmet.realm.dart b/lib/data/weather_airsigmet.realm.dart deleted file mode 100644 index 6f306d5..0000000 --- a/lib/data/weather_airsigmet.realm.dart +++ /dev/null @@ -1,155 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_airsigmet.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherAirSigmet extends _WeatherAirSigmet - with RealmEntity, RealmObjectBase, RealmObject { - WeatherAirSigmet( - ObjectId id, - String station, - String text, - int utcMs, - String raw, - String coordinates, - String hazard, - String severity, - String type, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'text', text); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'raw', raw); - RealmObjectBase.set(this, 'coordinates', coordinates); - RealmObjectBase.set(this, 'hazard', hazard); - RealmObjectBase.set(this, 'severity', severity); - RealmObjectBase.set(this, 'type', type); - } - - WeatherAirSigmet._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get text => RealmObjectBase.get(this, 'text') as String; - @override - set text(String value) => RealmObjectBase.set(this, 'text', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - String get raw => RealmObjectBase.get(this, 'raw') as String; - @override - set raw(String value) => RealmObjectBase.set(this, 'raw', value); - - @override - String get coordinates => - RealmObjectBase.get(this, 'coordinates') as String; - @override - set coordinates(String value) => - RealmObjectBase.set(this, 'coordinates', value); - - @override - String get hazard => RealmObjectBase.get(this, 'hazard') as String; - @override - set hazard(String value) => RealmObjectBase.set(this, 'hazard', value); - - @override - String get severity => - RealmObjectBase.get(this, 'severity') as String; - @override - set severity(String value) => RealmObjectBase.set(this, 'severity', value); - - @override - String get type => RealmObjectBase.get(this, 'type') as String; - @override - set type(String value) => RealmObjectBase.set(this, 'type', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherAirSigmet freeze() => - RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'text': text.toEJson(), - 'utcMs': utcMs.toEJson(), - 'raw': raw.toEJson(), - 'coordinates': coordinates.toEJson(), - 'hazard': hazard.toEJson(), - 'severity': severity.toEJson(), - 'type': type.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherAirSigmet value) => value.toEJson(); - static WeatherAirSigmet _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'text': EJsonValue text, - 'utcMs': EJsonValue utcMs, - 'raw': EJsonValue raw, - 'coordinates': EJsonValue coordinates, - 'hazard': EJsonValue hazard, - 'severity': EJsonValue severity, - 'type': EJsonValue type, - } => - WeatherAirSigmet( - fromEJson(id), - fromEJson(station), - fromEJson(text), - fromEJson(utcMs), - fromEJson(raw), - fromEJson(coordinates), - fromEJson(hazard), - fromEJson(severity), - fromEJson(type), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherAirSigmet._); - register(_toEJson, _fromEJson); - return SchemaObject( - ObjectType.realmObject, WeatherAirSigmet, 'WeatherAirSigmet', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('text', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('raw', RealmPropertyType.string), - SchemaProperty('coordinates', RealmPropertyType.string), - SchemaProperty('hazard', RealmPropertyType.string), - SchemaProperty('severity', RealmPropertyType.string), - SchemaProperty('type', RealmPropertyType.string), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_database_helper.dart b/lib/data/weather_database_helper.dart new file mode 100644 index 0000000..79602cc --- /dev/null +++ b/lib/data/weather_database_helper.dart @@ -0,0 +1,390 @@ +import 'dart:async'; +import 'dart:io'; +import 'package:avaremp/storage.dart'; +import 'package:avaremp/weather/airep.dart'; +import 'package:avaremp/weather/airsigmet.dart'; +import 'package:avaremp/weather/metar.dart'; +import 'package:avaremp/weather/notam.dart'; +import 'package:avaremp/weather/taf.dart'; +import 'package:avaremp/weather/tfr.dart'; +import 'package:avaremp/weather/winds_aloft.dart'; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; + +class WeatherDatabaseHelper { + WeatherDatabaseHelper._(); + + static final WeatherDatabaseHelper _db = WeatherDatabaseHelper._(); + + static WeatherDatabaseHelper get db => _db; + static Database? _database; + + Future get database async { + if (_database != null) { + return _database; + } + _database = await _initDB(); + return _database; + } + + _initDB() async { + Directory documentsDirectory = Directory(Storage().dataDir); + String path = join(documentsDirectory.path, "weather.db"); // this is cache and can be versioned without fear of losing data + return + await openDatabase( + path, + version: 1, + onCreate: (Database db, int version) async { + await db.execute("create table windsAloft (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "w0k text, " + "w3k text, " + "w6k text, " + "w9k text, " + "w12k text, " + "w18k text, " + "w24k text, " + "w30k text, " + "w34k text, " + "w39k text, " + "unique(station) on conflict replace);"); + await db.execute("create table metar (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "raw text, " + "category text, " + "ARPLatitude float, " + "ARPLongitude float, " + "unique(station) on conflict replace);"); + await db.execute("create table taf (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "raw text, " + "ARPLatitude float, " + "ARPLongitude float, " + "unique(station) on conflict replace);"); + await db.execute("create table tfr (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "coordinates text, " + "upperAltitude text, " + "lowerAltitude text, " + "msEffective int, " + "msExpires int, " + "labelCoordinate int, " + "unique(station) on conflict replace);"); + await db.execute("create table airep (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "raw text, " + "coordinates text, " + "unique(station) on conflict replace);"); + await db.execute("create table airsigmet (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "raw text, " + "coordinates text, " + "hazard text, " + "severity text, " + "type text, " + "unique(station) on conflict replace);"); + await db.execute("create table notam (" + "id integer primary key autoincrement, " + "station text, " + "utcMs int, " + "raw text, " + "unique(station) on conflict replace);"); + }, + onOpen: (db) {}); + } + + Future addWindsAloft(WindsAloft wa) async { + final db = await database; + + if (db != null) { + await db.insert("windsAloft", wa.toMap()); + } + } + + Future addWindsAlofts(List wa) async { + final db = await database; + + if (db != null && wa.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("windsAloft"); + for(WindsAloft w in wa) { + batch.insert("windsAloft", w.toMap()); + } + await batch.commit(); + }); + } + } + + Future getWindsAloft(String station) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from windsAloft where station='$station'"); + return WindsAloft.fromMap(maps[0]); + } + return null; + } + + Future> getAllWindsAloft() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from windsAloft"); + return List.generate(maps.length, (index) => WindsAloft.fromMap(maps[index])); + } + return []; + } + + Future deleteWindsAloft(String station) async { + final db = await database; + if (db != null) { + await db.rawQuery("delete from windsAloft where station='$station'"); + } + } + + Future addMetar(Metar metar) async { + final db = await database; + + if (db != null) { + await db.insert("metar", metar.toMap()); + } + } + + Future addMetars(List metar) async { + final db = await database; + + if (db != null && metar.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("metar"); + for(Metar m in metar) { + batch.insert("metar", m.toMap()); + } + await batch.commit(); + }); + } + } + + + Future getMetar(String station) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from metar where station='$station'"); + return Metar.fromMap(maps[0]); + } + return null; + } + + Future> getAllMetar() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from metar"); + return List.generate(maps.length, (index) => Metar.fromMap(maps[index])); + } + return []; + } + + Future deleteMetar(String station) async { + final db = await database; + if (db != null) { + await db.rawQuery("delete from metar where station='$station'"); + } + } + + + Future addTaf(Taf taf) async { + final db = await database; + + if (db != null) { + await db.insert("taf", taf.toMap()); + } + } + + Future addTafs(List taf) async { + final db = await database; + + if (db != null && taf.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("taf"); + for(Taf t in taf) { + batch.insert("taf", t.toMap()); + } + await batch.commit(); + }); + } + } + + + Future getTaf(String station) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from taf where station='$station'"); + return Taf.fromMap(maps[0]); + } + return null; + } + + Future> getAllTaf() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from taf"); + return List.generate(maps.length, (index) => Taf.fromMap(maps[index])); + } + return []; + } + + Future deleteTaf(String station) async { + final db = await database; + if (db != null) { + await db.rawQuery("delete from taf where station='$station'"); + } + } + + Future addTfr(Tfr tfr) async { + final db = await database; + + if (db != null) { + await db.insert("tfr", tfr.toMap()); + } + } + + Future addTfrs(List tfr) async { + final db = await database; + + if (db != null && tfr.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("tfr"); + for(Tfr t in tfr) { + batch.insert("tfr", t.toMap()); + } + await batch.commit(); + }); + } + } + + Future getTfr(String station) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from tfr where station='$station'"); + return Tfr.fromMap(maps[0]); + } + return null; + } + + Future> getAllTfr() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from tfr"); + return List.generate(maps.length, (index) => Tfr.fromMap(maps[index])); + } + return []; + } + + Future deleteTfr(String station) async { + final db = await database; + if (db != null) { + await db.rawQuery("delete from tfr where station='$station'"); + } + } + + Future> getAllAirep() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from airep"); + return List.generate(maps.length, (index) => Airep.fromMap(maps[index])); + } + return []; + } + + Future addAireps(List aireps) async { + final db = await database; + + if (db != null && aireps.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("airep"); + for(Airep a in aireps) { + batch.insert("airep", a.toMap()); + } + await batch.commit(); + }); + } + } + + Future> getAllAirSigmet() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from airsigmet"); + return List.generate(maps.length, (index) => AirSigmet.fromMap(maps[index])); + } + return []; + } + + Future addAirSigmets(List airSigmet) async { + final db = await database; + + if (db != null && airSigmet.isNotEmpty) { + await db.transaction((txn) async { + Batch batch = txn.batch(); + batch.delete("airsigmet"); + for(AirSigmet a in airSigmet) { + batch.insert("airsigmet", a.toMap()); + } + await batch.commit(); + }); + } + } + + Future> getAllNotams() async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from notam"); + return List.generate(maps.length, (index) => Notam.fromMap(maps[index])); + } + return []; + } + + Future getNotam(String station) async { + List> maps = []; + final db = await database; + if (db != null) { + maps = await db.rawQuery("select * from notam where station='$station'"); + return Notam.fromMap(maps[0]); + } + return null; + } + + Future addNotam(Notam notam) async { + final db = await database; + + if (db != null) { + await db.insert("notam", notam.toMap()); + } + } + +} + diff --git a/lib/data/weather_metar.dart b/lib/data/weather_metar.dart deleted file mode 100644 index b614397..0000000 --- a/lib/data/weather_metar.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_metar.realm.dart'; - -@RealmModel() -class _WeatherMetar { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String raw; - late int utcMs; - late String category; - late double ARPLatitude; - late double ARPLongitude; -} diff --git a/lib/data/weather_metar.realm.dart b/lib/data/weather_metar.realm.dart deleted file mode 100644 index db379fa..0000000 --- a/lib/data/weather_metar.realm.dart +++ /dev/null @@ -1,133 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_metar.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherMetar extends _WeatherMetar - with RealmEntity, RealmObjectBase, RealmObject { - WeatherMetar( - ObjectId id, - String station, - String raw, - int utcMs, - String category, - double ARPLatitude, - double ARPLongitude, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'raw', raw); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'category', category); - RealmObjectBase.set(this, 'ARPLatitude', ARPLatitude); - RealmObjectBase.set(this, 'ARPLongitude', ARPLongitude); - } - - WeatherMetar._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get raw => RealmObjectBase.get(this, 'raw') as String; - @override - set raw(String value) => RealmObjectBase.set(this, 'raw', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - String get category => - RealmObjectBase.get(this, 'category') as String; - @override - set category(String value) => RealmObjectBase.set(this, 'category', value); - - @override - double get ARPLatitude => - RealmObjectBase.get(this, 'ARPLatitude') as double; - @override - set ARPLatitude(double value) => - RealmObjectBase.set(this, 'ARPLatitude', value); - - @override - double get ARPLongitude => - RealmObjectBase.get(this, 'ARPLongitude') as double; - @override - set ARPLongitude(double value) => - RealmObjectBase.set(this, 'ARPLongitude', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherMetar freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'raw': raw.toEJson(), - 'utcMs': utcMs.toEJson(), - 'category': category.toEJson(), - 'ARPLatitude': ARPLatitude.toEJson(), - 'ARPLongitude': ARPLongitude.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherMetar value) => value.toEJson(); - static WeatherMetar _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'raw': EJsonValue raw, - 'utcMs': EJsonValue utcMs, - 'category': EJsonValue category, - 'ARPLatitude': EJsonValue ARPLatitude, - 'ARPLongitude': EJsonValue ARPLongitude, - } => - WeatherMetar( - fromEJson(id), - fromEJson(station), - fromEJson(raw), - fromEJson(utcMs), - fromEJson(category), - fromEJson(ARPLatitude), - fromEJson(ARPLongitude), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherMetar._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherMetar, 'WeatherMetar', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('raw', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('category', RealmPropertyType.string), - SchemaProperty('ARPLatitude', RealmPropertyType.double), - SchemaProperty('ARPLongitude', RealmPropertyType.double), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_notam.dart b/lib/data/weather_notam.dart deleted file mode 100644 index 4f6f1bd..0000000 --- a/lib/data/weather_notam.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_notam.realm.dart'; - -@RealmModel() -class _WeatherNotam { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String text; - late int utcMs; -} - diff --git a/lib/data/weather_notam.realm.dart b/lib/data/weather_notam.realm.dart deleted file mode 100644 index a49c9e7..0000000 --- a/lib/data/weather_notam.realm.dart +++ /dev/null @@ -1,95 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_notam.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherNotam extends _WeatherNotam - with RealmEntity, RealmObjectBase, RealmObject { - WeatherNotam( - ObjectId id, - String station, - String text, - int utcMs, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'text', text); - RealmObjectBase.set(this, 'utcMs', utcMs); - } - - WeatherNotam._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get text => RealmObjectBase.get(this, 'text') as String; - @override - set text(String value) => RealmObjectBase.set(this, 'text', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherNotam freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'text': text.toEJson(), - 'utcMs': utcMs.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherNotam value) => value.toEJson(); - static WeatherNotam _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'text': EJsonValue text, - 'utcMs': EJsonValue utcMs, - } => - WeatherNotam( - fromEJson(id), - fromEJson(station), - fromEJson(text), - fromEJson(utcMs), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherNotam._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherNotam, 'WeatherNotam', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('text', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_taf.dart b/lib/data/weather_taf.dart deleted file mode 100644 index 8547f93..0000000 --- a/lib/data/weather_taf.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_taf.realm.dart'; - -@RealmModel() -class _WeatherTaf { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String raw; - late int utcMs; - late double ARPLatitude; - late double ARPLongitude; -} diff --git a/lib/data/weather_taf.realm.dart b/lib/data/weather_taf.realm.dart deleted file mode 100644 index c76ae84..0000000 --- a/lib/data/weather_taf.realm.dart +++ /dev/null @@ -1,121 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_taf.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherTaf extends _WeatherTaf - with RealmEntity, RealmObjectBase, RealmObject { - WeatherTaf( - ObjectId id, - String station, - String raw, - int utcMs, - double ARPLatitude, - double ARPLongitude, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'raw', raw); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'ARPLatitude', ARPLatitude); - RealmObjectBase.set(this, 'ARPLongitude', ARPLongitude); - } - - WeatherTaf._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get raw => RealmObjectBase.get(this, 'raw') as String; - @override - set raw(String value) => RealmObjectBase.set(this, 'raw', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - double get ARPLatitude => - RealmObjectBase.get(this, 'ARPLatitude') as double; - @override - set ARPLatitude(double value) => - RealmObjectBase.set(this, 'ARPLatitude', value); - - @override - double get ARPLongitude => - RealmObjectBase.get(this, 'ARPLongitude') as double; - @override - set ARPLongitude(double value) => - RealmObjectBase.set(this, 'ARPLongitude', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherTaf freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'raw': raw.toEJson(), - 'utcMs': utcMs.toEJson(), - 'ARPLatitude': ARPLatitude.toEJson(), - 'ARPLongitude': ARPLongitude.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherTaf value) => value.toEJson(); - static WeatherTaf _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'raw': EJsonValue raw, - 'utcMs': EJsonValue utcMs, - 'ARPLatitude': EJsonValue ARPLatitude, - 'ARPLongitude': EJsonValue ARPLongitude, - } => - WeatherTaf( - fromEJson(id), - fromEJson(station), - fromEJson(raw), - fromEJson(utcMs), - fromEJson(ARPLatitude), - fromEJson(ARPLongitude), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherTaf._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherTaf, 'WeatherTaf', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('raw', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('ARPLatitude', RealmPropertyType.double), - SchemaProperty('ARPLongitude', RealmPropertyType.double), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_tfr.dart b/lib/data/weather_tfr.dart deleted file mode 100644 index cc944e4..0000000 --- a/lib/data/weather_tfr.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:realm/realm.dart'; - -part 'weather_tfr.realm.dart'; - -@RealmModel() -class _WeatherTfr { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late String coordinates; - late int utcMs; - late String upperAltitude; - late String lowerAltitude; - late int msEffective; - late int msExpires; - late int labelCoordinate; -} - diff --git a/lib/data/weather_tfr.realm.dart b/lib/data/weather_tfr.realm.dart deleted file mode 100644 index 350a18c..0000000 --- a/lib/data/weather_tfr.realm.dart +++ /dev/null @@ -1,162 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_tfr.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherTfr extends _WeatherTfr - with RealmEntity, RealmObjectBase, RealmObject { - WeatherTfr( - ObjectId id, - String station, - String coordinates, - int utcMs, - String upperAltitude, - String lowerAltitude, - int msEffective, - int msExpires, - int labelCoordinate, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'coordinates', coordinates); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'upperAltitude', upperAltitude); - RealmObjectBase.set(this, 'lowerAltitude', lowerAltitude); - RealmObjectBase.set(this, 'msEffective', msEffective); - RealmObjectBase.set(this, 'msExpires', msExpires); - RealmObjectBase.set(this, 'labelCoordinate', labelCoordinate); - } - - WeatherTfr._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - String get coordinates => - RealmObjectBase.get(this, 'coordinates') as String; - @override - set coordinates(String value) => - RealmObjectBase.set(this, 'coordinates', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - String get upperAltitude => - RealmObjectBase.get(this, 'upperAltitude') as String; - @override - set upperAltitude(String value) => - RealmObjectBase.set(this, 'upperAltitude', value); - - @override - String get lowerAltitude => - RealmObjectBase.get(this, 'lowerAltitude') as String; - @override - set lowerAltitude(String value) => - RealmObjectBase.set(this, 'lowerAltitude', value); - - @override - int get msEffective => RealmObjectBase.get(this, 'msEffective') as int; - @override - set msEffective(int value) => RealmObjectBase.set(this, 'msEffective', value); - - @override - int get msExpires => RealmObjectBase.get(this, 'msExpires') as int; - @override - set msExpires(int value) => RealmObjectBase.set(this, 'msExpires', value); - - @override - int get labelCoordinate => - RealmObjectBase.get(this, 'labelCoordinate') as int; - @override - set labelCoordinate(int value) => - RealmObjectBase.set(this, 'labelCoordinate', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - Stream> changesFor([List? keyPaths]) => - RealmObjectBase.getChangesFor(this, keyPaths); - - @override - WeatherTfr freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'coordinates': coordinates.toEJson(), - 'utcMs': utcMs.toEJson(), - 'upperAltitude': upperAltitude.toEJson(), - 'lowerAltitude': lowerAltitude.toEJson(), - 'msEffective': msEffective.toEJson(), - 'msExpires': msExpires.toEJson(), - 'labelCoordinate': labelCoordinate.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherTfr value) => value.toEJson(); - static WeatherTfr _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'coordinates': EJsonValue coordinates, - 'utcMs': EJsonValue utcMs, - 'upperAltitude': EJsonValue upperAltitude, - 'lowerAltitude': EJsonValue lowerAltitude, - 'msEffective': EJsonValue msEffective, - 'msExpires': EJsonValue msExpires, - 'labelCoordinate': EJsonValue labelCoordinate, - } => - WeatherTfr( - fromEJson(id), - fromEJson(station), - fromEJson(coordinates), - fromEJson(utcMs), - fromEJson(upperAltitude), - fromEJson(lowerAltitude), - fromEJson(msEffective), - fromEJson(msExpires), - fromEJson(labelCoordinate), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherTfr._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherTfr, 'WeatherTfr', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('coordinates', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('upperAltitude', RealmPropertyType.string), - SchemaProperty('lowerAltitude', RealmPropertyType.string), - SchemaProperty('msEffective', RealmPropertyType.int), - SchemaProperty('msExpires', RealmPropertyType.int), - SchemaProperty('labelCoordinate', RealmPropertyType.int), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/data/weather_winds.dart b/lib/data/weather_winds.dart deleted file mode 100644 index 0d5129b..0000000 --- a/lib/data/weather_winds.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:realm/realm.dart'; - - -part 'weather_winds.realm.dart'; - -@RealmModel() -class _WeatherWinds { - @PrimaryKey() - @MapTo('_id') - late ObjectId id; - - late String station; - late int utcMs; - late String w0k; - late String w3k; - late String w6k; - late String w9k; - late String w12k; - late String w18k; - late String w24k; - late String w30k; - late String w34k; - late String w39k; - -} diff --git a/lib/data/weather_winds.realm.dart b/lib/data/weather_winds.realm.dart deleted file mode 100644 index f74ac84..0000000 --- a/lib/data/weather_winds.realm.dart +++ /dev/null @@ -1,194 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'weather_winds.dart'; - -// ************************************************************************** -// RealmObjectGenerator -// ************************************************************************** - -// ignore_for_file: type=lint -class WeatherWinds extends _WeatherWinds - with RealmEntity, RealmObjectBase, RealmObject { - WeatherWinds( - ObjectId id, - String station, - int utcMs, - String w0k, - String w3k, - String w6k, - String w9k, - String w12k, - String w18k, - String w24k, - String w30k, - String w34k, - String w39k, - ) { - RealmObjectBase.set(this, '_id', id); - RealmObjectBase.set(this, 'station', station); - RealmObjectBase.set(this, 'utcMs', utcMs); - RealmObjectBase.set(this, 'w0k', w0k); - RealmObjectBase.set(this, 'w3k', w3k); - RealmObjectBase.set(this, 'w6k', w6k); - RealmObjectBase.set(this, 'w9k', w9k); - RealmObjectBase.set(this, 'w12k', w12k); - RealmObjectBase.set(this, 'w18k', w18k); - RealmObjectBase.set(this, 'w24k', w24k); - RealmObjectBase.set(this, 'w30k', w30k); - RealmObjectBase.set(this, 'w34k', w34k); - RealmObjectBase.set(this, 'w39k', w39k); - } - - WeatherWinds._(); - - @override - ObjectId get id => RealmObjectBase.get(this, '_id') as ObjectId; - @override - set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); - - @override - String get station => RealmObjectBase.get(this, 'station') as String; - @override - set station(String value) => RealmObjectBase.set(this, 'station', value); - - @override - int get utcMs => RealmObjectBase.get(this, 'utcMs') as int; - @override - set utcMs(int value) => RealmObjectBase.set(this, 'utcMs', value); - - @override - String get w0k => RealmObjectBase.get(this, 'w0k') as String; - @override - set w0k(String value) => RealmObjectBase.set(this, 'w0k', value); - - @override - String get w3k => RealmObjectBase.get(this, 'w3k') as String; - @override - set w3k(String value) => RealmObjectBase.set(this, 'w3k', value); - - @override - String get w6k => RealmObjectBase.get(this, 'w6k') as String; - @override - set w6k(String value) => RealmObjectBase.set(this, 'w6k', value); - - @override - String get w9k => RealmObjectBase.get(this, 'w9k') as String; - @override - set w9k(String value) => RealmObjectBase.set(this, 'w9k', value); - - @override - String get w12k => RealmObjectBase.get(this, 'w12k') as String; - @override - set w12k(String value) => RealmObjectBase.set(this, 'w12k', value); - - @override - String get w18k => RealmObjectBase.get(this, 'w18k') as String; - @override - set w18k(String value) => RealmObjectBase.set(this, 'w18k', value); - - @override - String get w24k => RealmObjectBase.get(this, 'w24k') as String; - @override - set w24k(String value) => RealmObjectBase.set(this, 'w24k', value); - - @override - String get w30k => RealmObjectBase.get(this, 'w30k') as String; - @override - set w30k(String value) => RealmObjectBase.set(this, 'w30k', value); - - @override - String get w34k => RealmObjectBase.get(this, 'w34k') as String; - @override - set w34k(String value) => RealmObjectBase.set(this, 'w34k', value); - - @override - String get w39k => RealmObjectBase.get(this, 'w39k') as String; - @override - set w39k(String value) => RealmObjectBase.set(this, 'w39k', value); - - @override - Stream> get changes => - RealmObjectBase.getChanges(this); - - @override - WeatherWinds freeze() => RealmObjectBase.freezeObject(this); - - EJsonValue toEJson() { - return { - '_id': id.toEJson(), - 'station': station.toEJson(), - 'utcMs': utcMs.toEJson(), - 'w0k': w0k.toEJson(), - 'w3k': w3k.toEJson(), - 'w6k': w6k.toEJson(), - 'w9k': w9k.toEJson(), - 'w12k': w12k.toEJson(), - 'w18k': w18k.toEJson(), - 'w24k': w24k.toEJson(), - 'w30k': w30k.toEJson(), - 'w34k': w34k.toEJson(), - 'w39k': w39k.toEJson(), - }; - } - - static EJsonValue _toEJson(WeatherWinds value) => value.toEJson(); - static WeatherWinds _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - '_id': EJsonValue id, - 'station': EJsonValue station, - 'utcMs': EJsonValue utcMs, - 'w0k': EJsonValue w0k, - 'w3k': EJsonValue w3k, - 'w6k': EJsonValue w6k, - 'w9k': EJsonValue w9k, - 'w12k': EJsonValue w12k, - 'w18k': EJsonValue w18k, - 'w24k': EJsonValue w24k, - 'w30k': EJsonValue w30k, - 'w34k': EJsonValue w34k, - 'w39k': EJsonValue w39k, - } => - WeatherWinds( - fromEJson(id), - fromEJson(station), - fromEJson(utcMs), - fromEJson(w0k), - fromEJson(w3k), - fromEJson(w6k), - fromEJson(w9k), - fromEJson(w12k), - fromEJson(w18k), - fromEJson(w24k), - fromEJson(w30k), - fromEJson(w34k), - fromEJson(w39k), - ), - _ => raiseInvalidEJson(ejson), - }; - } - - static final schema = () { - RealmObjectBase.registerFactory(WeatherWinds._); - register(_toEJson, _fromEJson); - return SchemaObject(ObjectType.realmObject, WeatherWinds, 'WeatherWinds', [ - SchemaProperty('id', RealmPropertyType.objectid, - mapTo: '_id', primaryKey: true), - SchemaProperty('station', RealmPropertyType.string), - SchemaProperty('utcMs', RealmPropertyType.int), - SchemaProperty('w0k', RealmPropertyType.string), - SchemaProperty('w3k', RealmPropertyType.string), - SchemaProperty('w6k', RealmPropertyType.string), - SchemaProperty('w9k', RealmPropertyType.string), - SchemaProperty('w12k', RealmPropertyType.string), - SchemaProperty('w18k', RealmPropertyType.string), - SchemaProperty('w24k', RealmPropertyType.string), - SchemaProperty('w30k', RealmPropertyType.string), - SchemaProperty('w34k', RealmPropertyType.string), - SchemaProperty('w39k', RealmPropertyType.string), - ]); - }(); - - @override - SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; -} diff --git a/lib/destination/airport.dart b/lib/destination/airport.dart index 409d869..4025445 100644 --- a/lib/destination/airport.dart +++ b/lib/destination/airport.dart @@ -193,7 +193,7 @@ class Airport { // calculate best runways based on wind direction double? windDirection; - Metar? metar = Storage().realmHelper.getMetar(destination.locationID); + Metar? metar = Storage().metar.get(destination.locationID) as Metar?; double minWind = 0; int index = -1; if(metar != null) { diff --git a/lib/plan/plan_route.dart b/lib/plan/plan_route.dart index e6fb689..1cd6c7d 100644 --- a/lib/plan/plan_route.dart +++ b/lib/plan/plan_route.dart @@ -709,4 +709,35 @@ class PlanRoute { _current = w; _passage = null; } + + // convert route to json + Map toMap(String name) { + + // put all destinations in json + List> maps = _waypoints.map((e) => e.destination.toMap()).toList(); + String json = jsonEncode(maps); + + Map jsonMap = {'name' : name, 'route' : json}; + + return jsonMap; + } + + // convert json to Route + static Future fromMap(Map maps, bool reverse) async { + PlanRoute route = PlanRoute(maps['name'] as String); + String json = maps['route'] as String; + List decoded = jsonDecode(json); + List destinations = decoded.map((e) => Destination.fromMap(e)).toList(); + + if(reverse) { + destinations = destinations.reversed.toList(); + } + for (Destination d in destinations) { + Destination expanded = await DestinationFactory.make(d); + Waypoint w = Waypoint(expanded); + route.addWaypoint(w); + } + return route; + } + } diff --git a/lib/weather/airep_cache.dart b/lib/weather/airep_cache.dart index d12694e..36bd905 100644 --- a/lib/weather/airep_cache.dart +++ b/lib/weather/airep_cache.dart @@ -1,12 +1,12 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:csv/csv.dart'; import 'package:latlong2/latlong.dart'; import '../constants.dart'; -import '../storage.dart'; import 'airep.dart'; class AirepCache extends WeatherCache { @@ -34,7 +34,7 @@ class AirepCache extends WeatherCache { continue; } } - Storage().realmHelper.addAireps(aireps); + await WeatherDatabaseHelper.db.addAireps(aireps); } } diff --git a/lib/weather/airsigmet_cache.dart b/lib/weather/airsigmet_cache.dart index 9ad1144..a8e413c 100644 --- a/lib/weather/airsigmet_cache.dart +++ b/lib/weather/airsigmet_cache.dart @@ -1,12 +1,12 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:avaremp/constants.dart'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:csv/csv.dart'; import 'package:latlong2/latlong.dart'; -import '../constants.dart'; -import '../storage.dart'; import 'airsigmet.dart'; class AirSigmetCache extends WeatherCache { @@ -41,8 +41,8 @@ class AirSigmetCache extends WeatherCache { continue; } } - Storage().realmHelper.addAirSigmets(airSigmet); + await WeatherDatabaseHelper.db.addAirSigmets(airSigmet); } } diff --git a/lib/weather/metar_cache.dart b/lib/weather/metar_cache.dart index 59d9ea3..fb07da5 100644 --- a/lib/weather/metar_cache.dart +++ b/lib/weather/metar_cache.dart @@ -1,12 +1,13 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'package:avaremp/constants.dart'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/geo_calculations.dart'; +import 'package:avaremp/storage.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:csv/csv.dart'; import 'package:latlong2/latlong.dart'; -import '../constants.dart'; -import '../storage.dart'; import 'metar.dart'; @@ -36,8 +37,8 @@ class MetarCache extends WeatherCache { continue; } } - Storage().realmHelper.addMetars(metars); - } + await WeatherDatabaseHelper.db.addMetars(metars); + } // Get Closets Metar of this coordinate Metar? getClosestMetar(LatLng coordinate) { diff --git a/lib/weather/notam_cache.dart b/lib/weather/notam_cache.dart index ea7561d..a133316 100644 --- a/lib/weather/notam_cache.dart +++ b/lib/weather/notam_cache.dart @@ -1,15 +1,14 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:avaremp/constants.dart'; import 'package:avaremp/data/main_database_helper.dart'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/destination/destination.dart'; import 'package:avaremp/weather/weather.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:html/parser.dart' as html_parser; import 'package:http/http.dart' as http; - -import '../constants.dart'; -import '../storage.dart'; import 'notam.dart'; class NotamCache extends WeatherCache { @@ -75,7 +74,7 @@ class NotamCache extends WeatherCache { time = time.add(const Duration(minutes: Constants.weatherUpdateTimeMin)); // they update every minute but that's too fast Notam notam = Notam(argument, time, retVal); - Storage().realmHelper.addNotam(notam); + await WeatherDatabaseHelper.db.addNotam(notam); } // Download and parse, override because this is a POST diff --git a/lib/weather/taf_cache.dart b/lib/weather/taf_cache.dart index 5244588..01eff83 100644 --- a/lib/weather/taf_cache.dart +++ b/lib/weather/taf_cache.dart @@ -1,14 +1,13 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; -import 'package:avaremp/storage.dart'; +import 'package:avaremp/constants.dart'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/weather/taf.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:csv/csv.dart'; import 'package:latlong2/latlong.dart'; -import '../constants.dart'; - class TafCache extends WeatherCache { TafCache(super.url, super.dbCall); @@ -39,7 +38,7 @@ class TafCache extends WeatherCache { } } - Storage().realmHelper.addTafs(tafs); + await WeatherDatabaseHelper.db.addTafs(tafs); } } diff --git a/lib/weather/tfr.dart b/lib/weather/tfr.dart index a19f41e..db7b317 100644 --- a/lib/weather/tfr.dart +++ b/lib/weather/tfr.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:avaremp/weather/weather.dart'; import 'package:latlong2/latlong.dart'; @@ -33,5 +35,46 @@ class Tfr extends Weather { int getLabelCoordinate() { return labelCoordinate; } + + + Map toMap() { + + List> ll = []; + for(LatLng c in coordinates) { + ll.add([c.latitude, c.longitude]); + } + + Map map = { + "station": station, + "utcMs": expires.millisecondsSinceEpoch, + "coordinates": jsonEncode(ll), + "upperAltitude": upperAltitude, + "lowerAltitude": lowerAltitude, + "msEffective": msEffective, + "msExpires": msExpires + }; + return map; + } + + factory Tfr.fromMap(Map maps) { + + List ll = []; + List coordinates = jsonDecode(maps['coordinates'] as String); + for(dynamic coordinate in coordinates) { + ll.add(LatLng(coordinate[0], coordinate[1])); + } + + return Tfr( + maps['station'] as String, + DateTime.fromMillisecondsSinceEpoch(maps['utcMs'] as int), + ll, + maps['upperAltitude'] as String, + maps['lowerAltitude'] as String, + maps['msEffective'] as int, + maps['msExpires'] as int, + maps['labelCoordinate'] as int + ); + } + } diff --git a/lib/weather/tfr_cache.dart b/lib/weather/tfr_cache.dart index 6f30b18..1b405a0 100644 --- a/lib/weather/tfr_cache.dart +++ b/lib/weather/tfr_cache.dart @@ -1,14 +1,13 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:avaremp/constants.dart'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/weather/tfr.dart'; import 'package:avaremp/weather/weather_cache.dart'; import 'package:http/http.dart' as http; import 'package:latlong2/latlong.dart'; import 'package:xml/xml.dart'; -import '../constants.dart'; -import '../storage.dart'; - class TfrCache extends WeatherCache { TfrCache(super.url, super.dbCall); @@ -138,7 +137,8 @@ class TfrCache extends WeatherCache { } } } - Storage().realmHelper.addTfrs(tfrs); + + await WeatherDatabaseHelper.db.addTfrs(tfrs); } } diff --git a/lib/weather/weather_cache.dart b/lib/weather/weather_cache.dart index ed59f9f..7b62d89 100644 --- a/lib/weather/weather_cache.dart +++ b/lib/weather/weather_cache.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:typed_data'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/weather/metar_cache.dart'; import 'package:avaremp/weather/taf_cache.dart'; import 'package:avaremp/weather/tfr_cache.dart'; @@ -9,7 +10,6 @@ import 'package:avaremp/weather/winds_cache.dart'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; -import '../storage.dart'; import 'airep_cache.dart'; import 'airsigmet_cache.dart'; import 'notam_cache.dart'; @@ -98,47 +98,47 @@ class WeatherCache { if(type == MetarCache) { MetarCache cache = MetarCache("https://aviationweather.gov/data/cache/metars.cache.csv.gz", - Storage().realmHelper.getAllMetar); + WeatherDatabaseHelper.db.getAllMetar); return cache; } else if(type == TafCache) { TafCache cache = TafCache("https://aviationweather.gov/data/cache/tafs.cache.csv.gz", - Storage().realmHelper.getAllTaf); + WeatherDatabaseHelper.db.getAllTaf); return cache; } else if(type == WindsCache) { // default WeatherCache cache = WindsCache( "https://aviationweather.gov/cgi-bin/data/windtemp.php?region=all&fcst=06&level=low", - Storage().realmHelper.getAllWindsAloft); + WeatherDatabaseHelper.db.getAllWindsAloft); return cache; } else if(type == TfrCache) { // default WeatherCache cache = TfrCache( "https://tfr.faa.gov/tfr2/list.html", - Storage().realmHelper.getAllTfr); + WeatherDatabaseHelper.db.getAllTfr); return cache; } else if(type == AirepCache) { // default WeatherCache cache = AirepCache( "https://aviationweather.gov/data/cache/aircraftreports.cache.csv.gz", - Storage().realmHelper.getAllAirep); + WeatherDatabaseHelper.db.getAllAirep); return cache; } else if(type == AirSigmetCache) { // default WeatherCache cache = AirSigmetCache( "https://aviationweather.gov/data/cache/airsigmets.cache.csv.gz", - Storage().realmHelper.getAllAirSigmet); + WeatherDatabaseHelper.db.getAllAirSigmet); return cache; } else if(type == NotamCache) { // default WeatherCache cache = NotamCache( "https://www.notams.faa.gov/dinsQueryWeb/latLongRadiusSearchMapAction.do", - Storage().realmHelper.getAllNotams); + WeatherDatabaseHelper.db.getAllNotams); return cache; } else { diff --git a/lib/weather/winds_cache.dart b/lib/weather/winds_cache.dart index c64a703..9b63bd4 100644 --- a/lib/weather/winds_cache.dart +++ b/lib/weather/winds_cache.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:avaremp/data/weather_database_helper.dart'; import 'package:avaremp/geo_calculations.dart'; import 'package:avaremp/storage.dart'; import 'package:avaremp/weather/weather_cache.dart'; @@ -90,7 +91,7 @@ class WindsCache extends WeatherCache { winds.add(w); } catch (e) {} - Storage().realmHelper.addWindsAlofts(winds); // add to database + await WeatherDatabaseHelper.db.addWindsAlofts(winds); } }