Skip to content

Commit

Permalink
removed weather realm
Browse files Browse the repository at this point in the history
  • Loading branch information
apps4av committed Nov 2, 2024
1 parent ceef908 commit 0755a29
Show file tree
Hide file tree
Showing 28 changed files with 677 additions and 1,697 deletions.
565 changes: 1 addition & 564 deletions lib/data/realm_helper.dart

Large diffs are not rendered by default.

181 changes: 181 additions & 0 deletions lib/data/user_database_helper.dart
Original file line number Diff line number Diff line change
@@ -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<Database?> 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<void> addRecent(Destination recent) async {
final db = await database;

if (db != null) {
await db.insert("recent", recent.toMap());
}
}

Future<List<Destination>> getRecentAirports() async {
List<Map<String, dynamic>> 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<List<Destination>> getRecent() async {
List<Map<String, dynamic>> 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<void> 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<void> 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<void> deletePlan(String name) async {
final db = await database;

if (db != null) {
await db.rawQuery("delete from plan where name='$name'");
}
}

Future<List<String>> getPlans() async {
List<Map<String, dynamic>> maps = [];
List<String> 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<String, dynamic> map in maps) {
ret.add(map['name']);
}
return ret;
}

Future<PlanRoute> getPlan(String name, bool reverse) async {
List<Map<String, dynamic>> 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<void> insertSetting(Database? db, String key, String? value) {
Completer<void> completer = Completer();
Map<String, String?> 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<void> deleteSetting(Database? db, String key) {
Completer<void> completer = Completer();

if(db != null) {
db.rawQuery("delete from settings where key=$key;").then((value) => completer.complete());
}
return completer.future;
}

static Future<void> deleteAllSettings(Database? db) {
Completer<void> completer = Completer();

if(db != null) {
db.rawQuery("delete * settings;").then((value) => completer.complete());
}
return completer.future;
}

static Future<List<Map<String, dynamic>>> getAllSettings(Database? db) async {
if(db != null) {
List<Map<String, dynamic>> maps = await db.rawQuery("select * from settings;");
return maps;
}
return [];
}

}
17 changes: 0 additions & 17 deletions lib/data/weather_airep.dart

This file was deleted.

108 changes: 0 additions & 108 deletions lib/data/weather_airep.realm.dart

This file was deleted.

21 changes: 0 additions & 21 deletions lib/data/weather_airsigmet.dart

This file was deleted.

Loading

0 comments on commit 0755a29

Please sign in to comment.