Commit cd8ba37a authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

removed print statements, added loi prefs, added db deprec

parent 7513fe06
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"app_settings","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\app_settings-4.0.3\\\\","dependencies":[]},{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-0.4.9+2\\\\","dependencies":[]},{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.17\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"app_settings","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\app_settings-4.0.3\\\\","dependencies":[]},{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-0.4.9+2\\\\","dependencies":[]},{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.17\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_macos-0.1.0+4\\\\","dependencies":[]},{"name":"path_provider_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4+4\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+8\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+1\\\\","dependencies":[]}],"web":[{"name":"connectivity_for_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_for_web-0.3.1+2\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+5\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"app_settings","dependencies":[]},{"name":"connectivity","dependencies":["connectivity_macos","connectivity_for_web"]},{"name":"connectivity_for_web","dependencies":[]},{"name":"connectivity_macos","dependencies":[]},{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-09-22 23:59:42.093030","version":"1.21.0-10.0.pre.193"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"app_settings","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\app_settings-4.0.3\\\\","dependencies":[]},{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-0.4.9+2\\\\","dependencies":[]},{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.17\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"app_settings","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\app_settings-4.0.3\\\\","dependencies":[]},{"name":"connectivity","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity-0.4.9+2\\\\","dependencies":[]},{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.7.2\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.17\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.5.7+2\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_macos-0.1.0+4\\\\","dependencies":[]},{"name":"path_provider_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4+4\\\\","dependencies":[]},{"name":"shared_preferences_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_macos-0.0.1+8\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.4+1\\\\","dependencies":[]}],"web":[{"name":"connectivity_for_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_for_web-0.3.1+2\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences_web-0.1.2+5\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"app_settings","dependencies":[]},{"name":"connectivity","dependencies":["connectivity_macos","connectivity_for_web"]},{"name":"connectivity_for_web","dependencies":[]},{"name":"connectivity_macos","dependencies":[]},{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-09-27 02:00:26.008342","version":"1.21.0-10.0.pre.193"}
\ No newline at end of file
......@@ -74,8 +74,12 @@ class MapDisplayController {
/// @Getter for [_marker].
Marker get marker {
print('MARKER ${this._marker} OBSVAL ${this._positionObserver.value}');
return this._marker != null ? this._marker : _buildLocationMarker(this._positionObserver.value == null ? LatLng(0, 0) : LatLng(this._positionObserver.value.latitude, this._positionObserver.value.longitude));
if (this._marker == null) {
LatLng position = this._positionObserver.value == null ? LatLng(0, 0) : LatLng(this._positionObserver.value.latitude, this._positionObserver.value.longitude);
this._marker = _buildLocationMarker(position);
}
return this._marker;
}
/// Object used to calculate the real-life distance of two [Position]s
......@@ -174,7 +178,6 @@ class MapDisplayController {
new Timer.periodic(Duration(minutes: 1), (Timer t) {
if (this._controller != null && this._controller.bounds != null) {
//print('${this._controller.bounds.southWest}, ${this._controller.bounds.northEast}');
NetworkHandler().getProximityPoints(DataHeader().deviceId, this._controller.bounds);
}
});
......
......@@ -9,6 +9,7 @@ import 'package:logair_application/logic/handlers/preference_handler.dart';
import 'package:logair_application/utils/enums/bluetooth_connection_status.dart';
import 'package:logair_application/logic/handlers/data_handler.dart';
import 'package:logair_application/utils/enums/preference_keys.dart';
import 'package:logair_application/utils/utils.dart';
// TODO Attempt reacquiring device after 5 seconds inactivity.
......@@ -97,8 +98,6 @@ class BTLEHandler {
final String bluetoothLeCc254xServiceUUID = await PreferencesHandler().getPreferencesString(PreferenceKeys.BT__SERVICE_UUID.key);
final String bluetoothLeCc254xReadUUID = await PreferencesHandler().getPreferencesString(PreferenceKeys.BT__CHARACTERISTIC_UUID.key);
print('$bluetoothLeCc254xServiceUUID\n$bluetoothLeCc254xReadUUID');
/// Get the first round of [BluetoothService]s and apply filter to desired Service UUID.
services = await this._device.services.first;
services = services.where((s) => s.uuid.toString() == bluetoothLeCc254xServiceUUID).toList();
......@@ -140,7 +139,7 @@ class BTLEHandler {
/// Handoff the data to the [DataHandler].
DataHandler().addData(data)
);
print("RETURNS");
printDebug('BTHandler: Returned');
success = true;
} else {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
......
......@@ -3,6 +3,7 @@ import 'package:logair_application/logic/data_header.dart';
import 'package:logair_application/logic/data_packet.dart';
import 'package:logair_application/logic/handlers/main_database_handler.dart';
import 'package:logair_application/logic/handlers/network_handler.dart';
import 'package:logair_application/utils/utils.dart';
class DataHandler {
factory DataHandler() => _singleton;
......@@ -46,14 +47,13 @@ class DataHandler {
/// If a packet is ingrained within this packet (possibly because of BLE transmission issues),
/// this will attempt to fix it.
if (packet.sublist(1).contains((e) => e == 91 || e == 123)) {
print('True ${packet.sublist(1).indexWhere((e) => e == 91 || e == 123)}');
int startIndex = packet.sublist(1).indexWhere((e) => e == 91 || e == 123);
packet.removeRange(0, startIndex);
}
/// If it's a [DataHeader] instance.
if (packet[0] == 123) {
print('HEADER ${String.fromCharCodes(packet)}');
printDebug('DataHandler: HEADER ${String.fromCharCodes(packet)}');
bool wasSet = DataHeader().headerSet;
DataHeader().setHeader(packet);
/// Retroactively add all previous packets
......@@ -67,7 +67,7 @@ class DataHandler {
/// Or if it is a [DataPacket] instance.
} else if (packet[0] == 91) {
print('PACKET ${String.fromCharCodes(packet)}');
printDebug('DataHandler: PACKET ${String.fromCharCodes(packet)}');
DataPacket dataPacket = DataPacket(packet);
if (DataHeader().headerSet) {
dataPacket.deviceId = DataHeader().deviceId;
......
import 'package:jiffy/jiffy.dart';
import 'package:logair_application/logic/data_packet.dart';
import 'package:logair_application/logic/handlers/preference_handler.dart';
import 'package:logair_application/utils/enums/preference_keys.dart';
import 'package:logair_application/utils/utils.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:tuple/tuple.dart';
......@@ -30,12 +34,23 @@ class MainDatabaseHandler {
/// Retrieves the internal [Database] instance, and if not instantiated, instantiates it.
Future<Database> get _mainDatabase async {
if (_maindb == null)
if (_maindb == null) {
this._maindb = openDatabase(
join((await getDatabasesPath()), 'logair_data.db'),
version: 3,
onCreate: (db, version) => db.execute(this._createMainDBString)
);
// Delete data older than 15 days at boot.
int maxDays = await PreferencesHandler().getPreferencesInt(PreferenceKeys.DB__MAX_AGE.key);
int timeStampLastStored = Jiffy().subtract(days: maxDays).millisecondsSinceEpoch;
(await this._maindb).delete(
'data',
where: 'timestamp_nix < ?',
whereArgs: [timeStampLastStored]
);
}
return this._maindb;
}
......@@ -98,8 +113,7 @@ class MainDatabaseHandler {
final Database database = await this._mainDatabase;
int count = await database.rawUpdate('UPDATE data SET exported = 1 WHERE id IN (${ids.join(', ')})');
print('Exported $count');
printDebug('DBHandler: Exported $count to API');
}
/// Used to monitor the amount of unsent [DataPacket]s.
......
......@@ -140,7 +140,7 @@ class NetworkHandler {
);
/// On error, the error should be ignored and not hang/break the thread.
} catch (e) {
print("${e.toString()} COULDN'T CONNECT");
printDebug('NetworkHandler: ${e.toString()} COULDN\'T CONNECT');
response = null;
}
......@@ -149,7 +149,7 @@ class NetworkHandler {
/// If the transfer was successful ()
await MainDatabaseHandler().setExported(databaseData.map((x) => x.item1).toList());
print('RESPONSE ${response.statusCode}');
printDebug('NetworkHandler: RESPONSE ${response.statusCode}');
this._lastServerTransmission = DateTime.now();
}
}
......@@ -171,7 +171,7 @@ class NetworkHandler {
);
/// On error, the error should be ignored and not break the thread.
} catch (e) {
print("${e.toString()} COULDN'T CONNECT");
printDebug('NetworkHandler: ${e.toString()} COULDN\'T CONNECT');
response = null;
}
......@@ -207,7 +207,7 @@ class NetworkHandler {
);
/// On error, the error should be ignored and not break the thread.
} catch (e) {
print("${e.toString()} COULDN'T CONNECT");
printDebug('NetworkHandler: ${e.toString()} COULDN\'T CONNECT');
response = null;
}
......@@ -221,7 +221,7 @@ class NetworkHandler {
try {
response = await _getLocationOfInterestData(latitude: loi.latitude, longitude: loi.longitude);
} catch (e) {
print("${e.toString()} COULDN'T CONNECT");
printDebug('NetworkHandler: ${e.toString()} COULDN\'T CONNECT');
yield null;
}
......
......@@ -96,7 +96,6 @@ class PositionHandler {
Stream<Position> getCurrentOrLastPosition() async* {
while (true) {
print('requesting');
Position currentPosition;
if (!_permissionChecked) {
await this._getGeolocationPermission();
......
......@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:geolocator/geolocator.dart';
import 'package:logair_application/utils/enums/preference_keys.dart';
import 'package:logair_application/utils/utils.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Handler enabling the storage and use of preferences.
......@@ -31,7 +32,7 @@ class PreferencesHandler {
this._sharedPreferencesInternal = await SharedPreferences.getInstance();
/// Initial Setup
print('Setting up preferences');
printDebug('PreferencesHandler: Setting up preferences');
PreferenceKeys.list.forEach((PreferenceKeys prefs) {
Function setter;
switch (prefs.type) {
......@@ -44,6 +45,9 @@ class PreferencesHandler {
case String:
setter = this._sharedPreferencesInternal.setString;
break;
case double:
setter = this._sharedPreferencesInternal.setDouble;
break;
default:
throw ArgumentError('Unexpected property type');
}
......@@ -52,7 +56,7 @@ class PreferencesHandler {
setter(prefs.defaultKey, prefs.defaultValue);
}
});
//print('Setup preferences done\n ${List.generate(this._sharedPreferencesInternal.getKeys().length, (i) => this._sharedPreferencesInternal.getKeys().elementAt(i) + ' => ' + this._sharedPreferencesInternal.get(this._sharedPreferencesInternal.getKeys().elementAt(i)).toString()).join("\n")}');
printDebug('PreferencesHandler: Setup preferences done\n${List.generate(this._sharedPreferencesInternal.getKeys().length, (i) => this._sharedPreferencesInternal.getKeys().elementAt(i) + ' => ' + this._sharedPreferencesInternal.get(this._sharedPreferencesInternal.getKeys().elementAt(i)).toString()).join(", ")}');
this._setup = true;
}
......@@ -68,27 +72,36 @@ class PreferencesHandler {
/// Retrieves a [bool] from the [SharedPreferences].
Future<bool> getPreferencesBool(String key) async => (await this._sharedPreferences).getBool(key);
/// Retrieves a [double] from the [SharedPreferences].
Future<double> getPreferencesDouble(String key) async => (await this._sharedPreferences).getDouble(key);
/// Retrieves a [dynamic] from the [SharedPreferences].
Future<dynamic> getPreferences(String key) async => (await this._sharedPreferences).get(key);
/// Sets an [int] within the [SharedPreferences].
Future<void> setPreferencesInt(String key, int value) async {
//print('Setting $key to $value');
printDebug('PreferencesHandler: Setting $key to $value');
(await this._sharedPreferences).setInt(key, value);
}
/// Sets a [String] within the [SharedPreferences].
Future<void> setPreferencesString(String key, String value) async {
//print('Setting $key to $value');
printDebug('PreferencesHandler: Setting $key to $value');
(await this._sharedPreferences).setString(key, value);
}
/// Sets a [bool] within the [SharedPreferences].
Future<void> setPreferencesBool(String key, bool value) async {
// print('Setting $key to $value');
printDebug('PreferencesHandler: Setting $key to $value');
(await this._sharedPreferences).setBool(key, value);
}
/// Sets a [double] within the [SharedPreferences].
Future<void> setPreferencesDouble(String key, double value) async {
printDebug('PreferencesHandler: Setting $key to $value');
(await this._sharedPreferences).setDouble(key, value);
}
/// Resets a specific [SharedPreferences] value to it's default value.
Future<void> resetPreference(String key) async {
Function setter;
......@@ -103,6 +116,11 @@ class PreferencesHandler {
case String:
setter = setPreferencesString;
break;
case double:
setter = setPreferencesDouble;
break;
default:
throw ArgumentError('Unexpected property type');
}
await setter(pref.key, pref.defaultValue);
......
......@@ -7,8 +7,8 @@ import 'package:logair_application/ui/components/body/data/tiles/data_tile.dart'
import 'package:logair_application/utils/helpers/location_of_interest.dart';
class LocationsOfInterestWidget extends StatefulWidget {
LocationsOfInterestWidget({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() => _LocationsOfInterestWidgetState();
}
......
......@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:logair_application/logic/data_packet.dart';
import 'package:logair_application/utils/enums/pm_symbol.dart';
import 'package:logair_application/utils/helpers/location_of_interest.dart';
import 'package:logair_application/utils/utils.dart';
//TODO Add weather ? (Not feasible unless negotiate free API access)
/// Widget that displays the data specific to a specific place, depending on the stream provided.
......@@ -231,7 +232,7 @@ class _DataTileState extends State<DataTile> {
child: tile,
splashColor: Color.fromARGB(0xAA, 0xFF, 0x00, 0x00),
// Delete location function (Remove from db) TODO
onLongPress: () => print('LOI: ${loi.id}~>${loi.name}'),
onLongPress: () => printDebug('DataTile: Delete LOI: ${loi.id}~>${loi.name}'),
)
);
} else {
......
......@@ -3,8 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:logair_application/logic/controllers/map_display_controller.dart';
import 'package:logair_application/logic/handlers/position_handler.dart';
import 'package:rxdart/subjects.dart';
class MapWidget extends StatefulWidget {
@override
......@@ -15,7 +13,7 @@ class _MapWidgetState extends State<MapWidget> {
int time = 0;
_MapWidgetState() {
MapDisplayController().shouldRedraw.listen((value) { setState(() => time += 1 ); });
MapDisplayController().shouldRedraw.listen((value) { if (mounted) setState(() => time += 1 ); });
}
@override
......
......@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttericon/linecons_icons.dart';
import 'package:intersperse/intersperse.dart';
import 'package:line_awesome_flutter/line_awesome_flutter.dart';
import 'package:logair_application/logic/handlers/main_database_handler.dart';
import 'package:logair_application/logic/handlers/preference_handler.dart';
import 'package:logair_application/ui/components/body/preferences/tiles/action_tile.dart';
......@@ -13,7 +14,9 @@ import 'package:logair_application/ui/components/body/preferences/tiles/location
import 'package:logair_application/ui/components/body/preferences/tiles/text_input_tile.dart';
import 'package:logair_application/ui/components/body/preferences/tiles/toggle_tile.dart';
import 'package:logair_application/ui/components/common/custom_expansion_tile.dart';
import 'package:logair_application/utils/decorations.dart';
import 'package:logair_application/utils/enums/preference_keys.dart';
import 'package:logair_application/utils/utils.dart';
import 'package:rxdart/subjects.dart';
/// This [Widget] is a [Form] that enables users to change settings.
......@@ -53,6 +56,9 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
final BehaviorSubject<int> _gpsAccuracyController = BehaviorSubject<int>();
final TextEditingController _gpsIntervalController = TextEditingController();
final TextEditingController _loiFocusController = TextEditingController();
final TextEditingController _loiAgeController = TextEditingController();
final TextEditingController _bleServiceController = TextEditingController();
final TextEditingController _bleCharacteristicController = TextEditingController();
......@@ -196,6 +202,29 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
)
]
),
// LOI
_buildExpansionTile(
title: 'Locations of Interest',
icon: LineAwesomeIcons.search_location,
children: [
TextInputTile(
controller: _loiFocusController,
labelText: 'Precision of values',
defaultText: 'Unit: Meters | Suggested: 1',
prefsKey: PreferenceKeys.LOI__FOCUS.key,
inputFormatters: <TextInputFormatter>[ FilteringTextInputFormatter.allow('0-9') ],
validation: RegExp(r'\d+')
),
TextInputTile(
controller: _loiAgeController,
labelText: 'Age of values',
defaultText: 'Unit: Seconds | Suggested: 300',
prefsKey: PreferenceKeys.LOI__AGE.key,
inputFormatters: <TextInputFormatter>[ FilteringTextInputFormatter.allow('0-9') ],
validation: RegExp(r'\d+')
),
]
),
// BLUETOOTH
_buildExpansionTile(
title: 'Bluetooth',
......@@ -305,6 +334,7 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
)
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Spacer(flex: 10),
Container(
......@@ -328,15 +358,9 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
Spacer(flex: 1),
Expanded(
flex: 10,
child: RaisedButton(
color: Colors.blue[300],
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.blue[400]),
),
padding: EdgeInsets.symmetric(vertical: 12),
onPressed: () async {
//print('FormState validate : ${_formKey.currentState.validate()}');
child: GestureDetector(
onTap: () async {
printDebug('PreferencesForm: Validation status is ${_formKey.currentState.validate()}');
if (_formKey.currentState.validate()) {
await PreferencesHandler().setPreferencesBool(PreferenceKeys.GEN__SHARE.key, _generalShareController.value);
......@@ -359,24 +383,25 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
Navigator.of(context).pop();
}
},
child: Text(
'Confirm Changes',
style: TextStyle(
fontSize: 20
)
child: Container(
padding: EdgeInsets.symmetric(vertical: 10),
decoration: containerNeumorphicDecoration.copyWith(borderRadius: BorderRadius.circular(15)),
child: Text(
'Confirm Changes',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color: Colors.white
)
),
),
),
),
Spacer(flex: 1),
Expanded(
flex: 10,
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.black),
),
padding: EdgeInsets.symmetric(vertical: 12),
onPressed: () async {
child: GestureDetector(
onTap: () async {
await PreferencesHandler().resetAllPreferences();
_formKey.currentState.reset();
......@@ -385,11 +410,17 @@ class _PreferencesWidgetState extends State<PreferencesWidget> {
_gpsAccuracyController.value = await PreferencesHandler().getPreferencesInt(PreferenceKeys.GPS__ACCURACY.key);
},
child: Text(
'Reset values',
style: TextStyle(
fontSize: 20
)
child: Container(
decoration: errorContainerNeumorphicDecoration.copyWith(borderRadius: BorderRadius.circular(15)),
padding: EdgeInsets.symmetric(vertical: 10),
child: Text(
'Reset values',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color: Colors.white
)
),
),
),
),
......
......@@ -54,7 +54,6 @@ class TextInputTile extends StatelessWidget {
),
autovalidate: false,
validator: (value) {
//print('Validation: $value, ${validation.stringMatch(value)}');
if (value.isEmpty)
return 'The field cannot be empty';
else if (this.validation.stringMatch(value) != value)
......
......@@ -5,6 +5,7 @@ import 'package:logair_application/ui/animation/forward_animation.dart';
import 'package:logair_application/ui/components/body/bluetooth/bluetooth_selection.dart';
import 'package:logair_application/ui/components/common/base_widget.dart';
import 'package:logair_application/utils/enums/bluetooth_connection_status.dart';
import 'package:logair_application/utils/utils.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
/// [Widget] that acts as an interface for the user.
......@@ -93,10 +94,8 @@ class _BluetoothButtonState extends State<BluetoothButton> {
Widget build(BuildContext context) {
return InkWell(
onTap: () {
print('Status $_status');
print("onTap");
printDebug('BluetoothButton: Status $_status');
if (_status == BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING) {
print("Tap On");
Navigator.push(
context,
PopForwardRoute(
......@@ -106,7 +105,6 @@ class _BluetoothButtonState extends State<BluetoothButton> {
return true;
} else {
BTLEHandler().disconnect();
print('Tap off');
return true;
}
},
......
......@@ -53,6 +53,11 @@ class PreferenceKeys {
static const GPS__INTERVAL_SECONDS
= const PreferenceKeys._internal('GPS.INTERVAL_SECONDS', int, 1);
static const LOI__FOCUS
= const PreferenceKeys._internal('LOI.FOCUS', int, 1);
static const LOI__AGE
= const PreferenceKeys._internal('LOI.AGE', int, 300);
static const BT__FREQUENT
= const PreferenceKeys._internal('BT.FREQUENT', String, '[ ]');
static const BT__USING_ADVANCED
......@@ -79,6 +84,8 @@ class PreferenceKeys {
DB__MAX_AGE,
GPS__ACCURACY,
GPS__INTERVAL_SECONDS,
LOI__FOCUS,
LOI__AGE,
BT__FREQUENT,
BT__USING_ADVANCED,
BT__SERVICE_UUID,
......
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' as Foundation;
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
/// Retrieves the [int] or the [double] that is represented by a give [String] ([data]).
......@@ -43,4 +44,9 @@ IconData getBatteryLevelIcon({@required int level}) {
else icon = MdiIcons.battery;
return icon;
}
void printDebug(Object object) {
if (Foundation.kDebugMode)
print(object);
}
\ No newline at end of file
......@@ -364,6 +364,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
jiffy:
dependency: "direct main"
description:
name: jiffy
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
js:
dependency: transitive
description:
......@@ -385,6 +392,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1"
line_awesome_flutter:
dependency: "direct main"
description:
name: line_awesome_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
lists:
dependency: transitive
description:
......
......@@ -30,6 +30,7 @@ dependencies:
http: ^0.12.1
rxdart: ^0.24.0
fl_chart: ^0.9.4
jiffy: 3.0.1
sqflite:
path:
intersperse: any
......@@ -38,6 +39,7 @@ dependencies:
fluttericon: ^1.0.7
flutter_boxicons: ^2.0.0
material_design_icons_flutter: ^4.0.5345
line_awesome_flutter: 1.0.1
app_settings: 4.0.3
intl: ^0.16.1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment