Add fastest interval

This commit is contained in:
Anton Tananaev 2025-06-13 15:36:07 -07:00
parent f3d0bdcefc
commit e6ac282afd
3 changed files with 8 additions and 1 deletions

View file

@ -15,6 +15,7 @@
"mediumAccuracyLabel": "Medium", "mediumAccuracyLabel": "Medium",
"lowAccuracyLabel": "Low", "lowAccuracyLabel": "Low",
"intervalLabel": "Interval (seconds)", "intervalLabel": "Interval (seconds)",
"fastestIntervalLabel": "Fastest interval (seconds)",
"distanceLabel": "Distance (meters)", "distanceLabel": "Distance (meters)",
"heartbeatLabel": "Heartbeat (seconds)", "heartbeatLabel": "Heartbeat (seconds)",
"bufferLabel": "Offline buffering", "bufferLabel": "Offline buffering",

View file

@ -16,6 +16,7 @@ class Preferences {
static const String heartbeat = 'heartbeat'; static const String heartbeat = 'heartbeat';
static const String buffer = 'buffer'; static const String buffer = 'buffer';
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(
@ -24,7 +25,7 @@ class Preferences {
: SharedPreferencesOptions(), : SharedPreferencesOptions(),
cacheOptions: SharedPreferencesWithCacheOptions( cacheOptions: SharedPreferencesWithCacheOptions(
allowList: { allowList: {
id, url, accuracy, interval, distance, buffer, heartbeat, stopDetection, id, url, accuracy, interval, distance, buffer, heartbeat, stopDetection, fastestInterval,
'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',
}, },
@ -50,10 +51,12 @@ class Preferences {
await instance.setInt(distance, instance.getInt(distance) ?? 75); await instance.setInt(distance, instance.getInt(distance) ?? 75);
await instance.setBool(buffer, instance.getBool(buffer) ?? true); await instance.setBool(buffer, instance.getBool(buffer) ?? true);
await instance.setBool(stopDetection, instance.getBool(stopDetection) ?? true); await instance.setBool(stopDetection, instance.getBool(stopDetection) ?? true);
await instance.setInt(fastestInterval, instance.getInt(fastestInterval) ?? 30);
} }
static bg.Config geolocationConfig() { static bg.Config geolocationConfig() {
final locationUpdateInterval = (instance.getInt(interval) ?? 0) * 1000; final locationUpdateInterval = (instance.getInt(interval) ?? 0) * 1000;
final fastestLocationUpdateInterval = (instance.getInt(fastestInterval) ?? 30) * 1000;
final heartbeatInterval = instance.getInt(heartbeat) ?? 0; final heartbeatInterval = instance.getInt(heartbeat) ?? 0;
return bg.Config( return bg.Config(
enableHeadless: true, enableHeadless: true,
@ -80,6 +83,7 @@ class Preferences {
disableElasticity: true, disableElasticity: true,
disableStopDetection: instance.getBool(stopDetection) == false, disableStopDetection: instance.getBool(stopDetection) == false,
pausesLocationUpdatesAutomatically: instance.getBool(stopDetection) == false, pausesLocationUpdatesAutomatically: instance.getBool(stopDetection) == false,
fastestLocationUpdateInterval: fastestLocationUpdateInterval > 0 ? fastestLocationUpdateInterval : null,
); );
} }

View file

@ -149,6 +149,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() => advanced = value); setState(() => advanced = value);
}, },
), ),
if (Platform.isAndroid && advanced)
_buildListTile(AppLocalizations.of(context)!.fastestIntervalLabel, Preferences.fastestInterval, true),
if (advanced) if (advanced)
SwitchListTile( SwitchListTile(
title: Text(AppLocalizations.of(context)!.bufferLabel), title: Text(AppLocalizations.of(context)!.bufferLabel),