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