Additional configuration
This commit is contained in:
parent
48df696256
commit
b8e53175c9
3 changed files with 47 additions and 2 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<void> 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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ class SettingsScreen extends StatefulWidget {
|
|||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool buffering = true;
|
||||
bool preventSuspend = false;
|
||||
bool disableElasticity = false;
|
||||
bool stopDetection = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -26,6 +29,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
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<SettingsScreen> {
|
|||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue