diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 818e554..d445cfd 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -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", diff --git a/lib/preferences.dart b/lib/preferences.dart index f310624..689837a 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -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 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, diff --git a/lib/settings_screen.dart b/lib/settings_screen.dart index 70deef9..f8d22c7 100644 --- a/lib/settings_screen.dart +++ b/lib/settings_screen.dart @@ -37,6 +37,7 @@ class _SettingsScreenState extends State { 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 { } 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 { @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 { _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 { setState(() => advanced = value); }, ), - if (Platform.isAndroid && advanced) + if (advanced) _buildListTile(AppLocalizations.of(context)!.fastestIntervalLabel, Preferences.fastestInterval, true), if (advanced) SwitchListTile(