From b8e53175c9f8f753598756f7ee8120b3642222f1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 11 Jun 2025 22:21:50 -0700 Subject: [PATCH] Additional configuration --- lib/l10n/app_en.arb | 3 +++ lib/preferences.dart | 12 ++++++++++-- lib/settings_screen.dart | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 37f7f11..7a397dd 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -18,6 +18,9 @@ "distanceLabel": "Distance (meters)", "heartbeatLabel": "Heartbeat (seconds)", "bufferLabel": "Offline buffering", + "preventSuspendLabel": "Prevent suspend", + "disableElasticityLabel": "Disable elasticity", + "stopDetectionLabel": "Stop detection", "trackingLabel": "Continuous tracking", "startAction": "Start service", "stopAction": "Stop service", diff --git a/lib/preferences.dart b/lib/preferences.dart index be3cfcc..c3e63c3 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -15,6 +15,9 @@ class Preferences { static const String distance = 'distance'; static const String heartbeat = 'heartbeat'; static const String buffer = 'buffer'; + static const String preventSuspend = 'prevent_suspend'; + static const String disableElasticity = 'disable_elasticity'; + static const String stopDetection = 'stop_detection'; static Future init() async { instance = await SharedPreferencesWithCache.create( @@ -24,6 +27,7 @@ class Preferences { cacheOptions: SharedPreferencesWithCacheOptions( allowList: { id, url, accuracy, interval, distance, buffer, heartbeat, + preventSuspend, disableElasticity, stopDetection, 'device_id_preference', 'server_url_preference', 'accuracy_preference', 'frequency_preference', 'distance_preference', 'buffer_preference', }, @@ -47,12 +51,12 @@ class Preferences { await instance.setString(accuracy, instance.getString(accuracy) ?? 'medium'); await instance.setInt(interval, instance.getInt(interval) ?? 300); await instance.setInt(distance, instance.getInt(distance) ?? 75); - await instance.setInt(heartbeat, instance.getInt(heartbeat) ?? 0); await instance.setBool(buffer, instance.getBool(buffer) ?? true); + await instance.setBool(stopDetection, instance.getBool(stopDetection) ?? true); } static bg.Config geolocationConfig() { - final heartbeatInterval = instance.getInt(interval) ?? 0; + final heartbeatInterval = instance.getInt(heartbeat) ?? 0; return bg.Config( stopOnTerminate: false, startOnBoot: true, @@ -73,6 +77,10 @@ class Preferences { logMaxDays: 1, locationTemplate: _locationTemplate(), showsBackgroundLocationIndicator: false, + preventSuspend: instance.getBool(preventSuspend), + disableElasticity: instance.getBool(disableElasticity), + disableStopDetection: instance.getBool(stopDetection) == false, + pausesLocationUpdatesAutomatically: instance.getBool(stopDetection) == false, ); } diff --git a/lib/settings_screen.dart b/lib/settings_screen.dart index 1e96135..236b82e 100644 --- a/lib/settings_screen.dart +++ b/lib/settings_screen.dart @@ -16,6 +16,9 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { bool buffering = true; + bool preventSuspend = false; + bool disableElasticity = false; + bool stopDetection = false; @override void initState() { @@ -26,6 +29,9 @@ class _SettingsScreenState extends State { void _initState() async { setState(() { buffering = Preferences.instance.getBool(Preferences.buffer) ?? true; + preventSuspend = Preferences.instance.getBool(Preferences.preventSuspend) ?? false; + disableElasticity = Preferences.instance.getBool(Preferences.disableElasticity) ?? false; + stopDetection = Preferences.instance.getBool(Preferences.stopDetection) ?? true; }); } @@ -145,6 +151,34 @@ class _SettingsScreenState extends State { setState(() => buffering = value); }, ), + SwitchListTile( + title: Text(AppLocalizations.of(context)!.disableElasticityLabel), + value: disableElasticity, + onChanged: (value) async { + await Preferences.instance.setBool(Preferences.disableElasticity, value); + await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig()); + setState(() => disableElasticity = value); + }, + ), + SwitchListTile( + title: Text(AppLocalizations.of(context)!.stopDetectionLabel), + value: stopDetection, + onChanged: (value) async { + await Preferences.instance.setBool(Preferences.stopDetection, value); + await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig()); + setState(() => stopDetection = value); + }, + ), + if (Platform.isIOS) + SwitchListTile( + title: Text(AppLocalizations.of(context)!.preventSuspendLabel), + value: preventSuspend, + onChanged: (value) async { + await Preferences.instance.setBool(Preferences.preventSuspend, value); + await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig()); + setState(() => preventSuspend = value); + }, + ), ], ), );