71 lines
2.1 KiB
Dart
71 lines
2.1 KiB
Dart
import 'package:drift/drift.dart';
|
|
|
|
import 'app_database.dart';
|
|
|
|
/// Zugriff auf die Einzeilen-Einstellungstabelle (Doku 7.5): welches
|
|
/// Drohnenprofil zuletzt aktiv war und welche Mission zuletzt bearbeitet
|
|
/// wurde, um beide nach einem Neustart wiederherzustellen.
|
|
class AppSettingsRepository {
|
|
AppSettingsRepository(this._db);
|
|
|
|
final AppDatabase _db;
|
|
|
|
static const _rowId = 0;
|
|
|
|
Future<
|
|
({
|
|
int? activeDroneProfileId,
|
|
int? currentMissionId,
|
|
String? connectionDeviceAddress,
|
|
bool connectionAutoConnect,
|
|
})> load() async {
|
|
final row = await (_db.select(_db.appSettingsTable)
|
|
..where((s) => s.id.equals(_rowId)))
|
|
.getSingleOrNull();
|
|
return (
|
|
activeDroneProfileId: row?.activeDroneProfileId,
|
|
currentMissionId: row?.currentMissionId,
|
|
connectionDeviceAddress: row?.connectionDeviceAddress,
|
|
connectionAutoConnect: row?.connectionAutoConnect ?? true,
|
|
);
|
|
}
|
|
|
|
Future<void> setActiveDroneProfileId(int? id) async {
|
|
await _upsert(AppSettingsTableCompanion(
|
|
id: const Value(_rowId),
|
|
activeDroneProfileId: Value(id),
|
|
));
|
|
}
|
|
|
|
Future<void> setCurrentMissionId(int? id) async {
|
|
await _upsert(AppSettingsTableCompanion(
|
|
id: const Value(_rowId),
|
|
currentMissionId: Value(id),
|
|
));
|
|
}
|
|
|
|
/// Gemerkte Bluetooth-MAC-Adresse (Doku Kommunikationsschicht 3.2a), oder
|
|
/// null um die Erinnerung zu loeschen (z.B. nach "Geraet entkoppeln").
|
|
Future<String?> loadConnectionDeviceAddress() async =>
|
|
(await load()).connectionDeviceAddress;
|
|
|
|
Future<void> setConnectionDeviceAddress(String? address) async {
|
|
await _upsert(AppSettingsTableCompanion(
|
|
id: const Value(_rowId),
|
|
connectionDeviceAddress: Value(address),
|
|
));
|
|
}
|
|
|
|
/// "Beim Wechsel in Fly automatisch verbinden" (Doku 7), Standard an.
|
|
Future<void> setConnectionAutoConnect(bool value) async {
|
|
await _upsert(AppSettingsTableCompanion(
|
|
id: const Value(_rowId),
|
|
connectionAutoConnect: Value(value),
|
|
));
|
|
}
|
|
|
|
Future<void> _upsert(AppSettingsTableCompanion companion) async {
|
|
await _db.into(_db.appSettingsTable).insertOnConflictUpdate(companion);
|
|
}
|
|
}
|