Add highest accuracy
This commit is contained in:
parent
19a2828444
commit
00599d7b1e
3 changed files with 21 additions and 6 deletions
|
|
@ -13,12 +13,14 @@
|
||||||
"idLabel": "Device identifier",
|
"idLabel": "Device identifier",
|
||||||
"urlLabel": "Server URL",
|
"urlLabel": "Server URL",
|
||||||
"accuracyLabel": "Location accuracy",
|
"accuracyLabel": "Location accuracy",
|
||||||
|
"highestAccuracyLabel": "Highest",
|
||||||
"highAccuracyLabel": "High",
|
"highAccuracyLabel": "High",
|
||||||
"mediumAccuracyLabel": "Medium",
|
"mediumAccuracyLabel": "Medium",
|
||||||
"lowAccuracyLabel": "Low",
|
"lowAccuracyLabel": "Low",
|
||||||
"intervalLabel": "Interval (seconds)",
|
"intervalLabel": "Interval (seconds)",
|
||||||
"fastestIntervalLabel": "Fastest interval (seconds)",
|
"fastestIntervalLabel": "Fastest interval (seconds)",
|
||||||
"distanceLabel": "Distance (meters)",
|
"distanceLabel": "Distance (meters)",
|
||||||
|
"angleLabel": "Angle (degrees)",
|
||||||
"heartbeatLabel": "Stationary heartbeat (seconds)",
|
"heartbeatLabel": "Stationary heartbeat (seconds)",
|
||||||
"bufferLabel": "Offline buffering",
|
"bufferLabel": "Offline buffering",
|
||||||
"wakelockLabel": "Wake lock",
|
"wakelockLabel": "Wake lock",
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@ class Preferences {
|
||||||
static const String id = 'id';
|
static const String id = 'id';
|
||||||
static const String url = 'url';
|
static const String url = 'url';
|
||||||
static const String accuracy = 'accuracy';
|
static const String accuracy = 'accuracy';
|
||||||
static const String interval = 'interval';
|
|
||||||
static const String distance = 'distance';
|
static const String distance = 'distance';
|
||||||
|
static const String interval = 'interval';
|
||||||
|
static const String angle = 'angle';
|
||||||
static const String heartbeat = 'heartbeat';
|
static const String heartbeat = 'heartbeat';
|
||||||
|
static const String fastestInterval = 'fastest_interval';
|
||||||
static const String buffer = 'buffer';
|
static const String buffer = 'buffer';
|
||||||
static const String wakelock = 'wakelock';
|
static const String wakelock = 'wakelock';
|
||||||
static const String stopDetection = 'stop_detection';
|
static const String stopDetection = 'stop_detection';
|
||||||
static const String fastestInterval = 'fastest_interval';
|
|
||||||
|
|
||||||
static Future<void> init() async {
|
static Future<void> init() async {
|
||||||
instance = await SharedPreferencesWithCache.create(
|
instance = await SharedPreferencesWithCache.create(
|
||||||
|
|
@ -26,7 +27,8 @@ class Preferences {
|
||||||
: SharedPreferencesOptions(),
|
: SharedPreferencesOptions(),
|
||||||
cacheOptions: SharedPreferencesWithCacheOptions(
|
cacheOptions: SharedPreferencesWithCacheOptions(
|
||||||
allowList: {
|
allowList: {
|
||||||
id, url, accuracy, interval, distance, buffer, heartbeat, wakelock, stopDetection, fastestInterval,
|
id, url, accuracy, distance, interval, angle, heartbeat,
|
||||||
|
fastestInterval, buffer, wakelock, stopDetection,
|
||||||
'device_id_preference', 'server_url_preference', 'accuracy_preference',
|
'device_id_preference', 'server_url_preference', 'accuracy_preference',
|
||||||
'frequency_preference', 'distance_preference', 'buffer_preference',
|
'frequency_preference', 'distance_preference', 'buffer_preference',
|
||||||
},
|
},
|
||||||
|
|
@ -45,6 +47,11 @@ class Preferences {
|
||||||
final intValue = int.tryParse(stringValue ?? '') ?? 75;
|
final intValue = int.tryParse(stringValue ?? '') ?? 75;
|
||||||
await instance.setInt(distance, intValue > 0 ? intValue : 75);
|
await instance.setInt(distance, intValue > 0 ? intValue : 75);
|
||||||
}
|
}
|
||||||
|
if (instance.get(angle) is String) {
|
||||||
|
final stringValue = instance.getString(angle);
|
||||||
|
final intValue = int.tryParse(stringValue ?? '') ?? 0;
|
||||||
|
await instance.setInt(angle, intValue);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await _migrate();
|
await _migrate();
|
||||||
}
|
}
|
||||||
|
|
@ -67,6 +74,7 @@ class Preferences {
|
||||||
stopOnTerminate: false,
|
stopOnTerminate: false,
|
||||||
startOnBoot: true,
|
startOnBoot: true,
|
||||||
desiredAccuracy: switch (instance.getString(accuracy)) {
|
desiredAccuracy: switch (instance.getString(accuracy)) {
|
||||||
|
'highest' => Platform.isIOS ? bg.Config.DESIRED_ACCURACY_NAVIGATION : bg.Config.DESIRED_ACCURACY_HIGH,
|
||||||
'high' => bg.Config.DESIRED_ACCURACY_HIGH,
|
'high' => bg.Config.DESIRED_ACCURACY_HIGH,
|
||||||
'low' => bg.Config.DESIRED_ACCURACY_LOW,
|
'low' => bg.Config.DESIRED_ACCURACY_LOW,
|
||||||
_ => bg.Config.DESIRED_ACCURACY_MEDIUM,
|
_ => bg.Config.DESIRED_ACCURACY_MEDIUM,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
|
|
||||||
String _getAccuracyLabel(String? key) {
|
String _getAccuracyLabel(String? key) {
|
||||||
return switch (key) {
|
return switch (key) {
|
||||||
|
'highest' => AppLocalizations.of(context)!.highestAccuracyLabel,
|
||||||
'high' => AppLocalizations.of(context)!.highAccuracyLabel,
|
'high' => AppLocalizations.of(context)!.highAccuracyLabel,
|
||||||
'low' => AppLocalizations.of(context)!.lowAccuracyLabel,
|
'low' => AppLocalizations.of(context)!.lowAccuracyLabel,
|
||||||
_ => AppLocalizations.of(context)!.mediumAccuracyLabel,
|
_ => AppLocalizations.of(context)!.mediumAccuracyLabel,
|
||||||
|
|
@ -118,7 +119,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAccuracyListTile() {
|
Widget _buildAccuracyListTile() {
|
||||||
final accuracyOptions = ['high', 'medium', 'low'];
|
final accuracyOptions = ['highest', 'high', 'medium', 'low'];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(AppLocalizations.of(context)!.accuracyLabel),
|
title: Text(AppLocalizations.of(context)!.accuracyLabel),
|
||||||
subtitle: Text(_getAccuracyLabel(Preferences.instance.getString(Preferences.accuracy))),
|
subtitle: Text(_getAccuracyLabel(Preferences.instance.getString(Preferences.accuracy))),
|
||||||
|
|
@ -144,6 +145,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isHighestAccuracy = Preferences.instance.getString(Preferences.accuracy) == 'highest';
|
||||||
|
final distance = Preferences.instance.getInt(Preferences.distance);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settingsTitle)),
|
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settingsTitle)),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
|
|
@ -152,8 +155,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
_buildListTile(AppLocalizations.of(context)!.urlLabel, Preferences.url, false),
|
_buildListTile(AppLocalizations.of(context)!.urlLabel, Preferences.url, false),
|
||||||
_buildAccuracyListTile(),
|
_buildAccuracyListTile(),
|
||||||
_buildListTile(AppLocalizations.of(context)!.distanceLabel, Preferences.distance, true),
|
_buildListTile(AppLocalizations.of(context)!.distanceLabel, Preferences.distance, true),
|
||||||
if (Platform.isAndroid && Preferences.instance.getInt(Preferences.distance) == 0)
|
if (isHighestAccuracy || Platform.isAndroid && distance == 0)
|
||||||
_buildListTile(AppLocalizations.of(context)!.intervalLabel, Preferences.interval, true),
|
_buildListTile(AppLocalizations.of(context)!.intervalLabel, Preferences.interval, true),
|
||||||
|
if (isHighestAccuracy)
|
||||||
|
_buildListTile(AppLocalizations.of(context)!.angleLabel, Preferences.angle, true),
|
||||||
_buildListTile(AppLocalizations.of(context)!.heartbeatLabel, Preferences.heartbeat, true),
|
_buildListTile(AppLocalizations.of(context)!.heartbeatLabel, Preferences.heartbeat, true),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(AppLocalizations.of(context)!.advancedLabel),
|
title: Text(AppLocalizations.of(context)!.advancedLabel),
|
||||||
|
|
@ -162,7 +167,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
setState(() => advanced = value);
|
setState(() => advanced = value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (Platform.isAndroid && advanced)
|
if (advanced)
|
||||||
_buildListTile(AppLocalizations.of(context)!.fastestIntervalLabel, Preferences.fastestInterval, true),
|
_buildListTile(AppLocalizations.of(context)!.fastestIntervalLabel, Preferences.fastestInterval, true),
|
||||||
if (advanced)
|
if (advanced)
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue