From 0e0c67d05c9f44cb1ded75b637d59d0a698c946b Mon Sep 17 00:00:00 2001 From: adeveloper-wq Date: Wed, 19 Jun 2024 13:46:00 +0200 Subject: [PATCH] Remove persistence of sg selector and map data settings --- lib/settings/services/settings.dart | 40 ++++------------------------- lib/settings/views/internal.dart | 4 +-- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/lib/settings/services/settings.dart b/lib/settings/services/settings.dart index 931313b87..41ad00fbe 100644 --- a/lib/settings/services/settings.dart +++ b/lib/settings/services/settings.dart @@ -208,21 +208,11 @@ class Settings with ChangeNotifier { return success; } - static const routingEndpointKey = "priobike.settings.routingEndpoint"; static const defaultRoutingEndpoint = RoutingEndpoint.graphhopperDRN; - Future setRoutingEndpoint(RoutingEndpoint routingEndpoint, [SharedPreferences? storage]) async { - storage ??= await SharedPreferences.getInstance(); - final prev = this.routingEndpoint; + void setRoutingEndpoint(RoutingEndpoint routingEndpoint) async { this.routingEndpoint = routingEndpoint; - final bool success = await storage.setString(routingEndpointKey, routingEndpoint.name); - if (!success) { - log.e("Failed to set routingEndpoint to $routingEndpoint"); - this.routingEndpoint = prev; - } else { - notifyListeners(); - } - return success; + notifyListeners(); } static const sgLabelsModeKey = "priobike.settings.sgLabelsMode"; @@ -341,21 +331,11 @@ class Settings with ChangeNotifier { return success; } - static const sgSelectorKey = "priobike.settings.sgSelector"; static const defaultSGSelector = SGSelector.ml; - Future setSGSelector(SGSelector sgSelector, [SharedPreferences? storage]) async { - storage ??= await SharedPreferences.getInstance(); - final prev = this.sgSelector; + void setSGSelector(SGSelector sgSelector) async { this.sgSelector = sgSelector; - final bool success = await storage.setString(sgSelectorKey, sgSelector.name); - if (!success) { - log.e("Failed to set sgSelector to $sgSelector"); - this.sgSelector = prev; - } else { - notifyListeners(); - } - return success; + notifyListeners(); } static const dismissedSurveyKey = "priobike.settings.dissmissedSurvey"; @@ -367,7 +347,7 @@ class Settings with ChangeNotifier { this.dismissedSurvey = dismissedSurvey; final bool success = await storage.setBool(dismissedSurveyKey, dismissedSurvey); if (!success) { - log.e("Failed to set sgSelector to $sgSelector"); + log.e("Failed to set dissmissedSurvey to $sgSelector"); this.dismissedSurvey = prev; } else { notifyListeners(); @@ -579,16 +559,6 @@ class Settings with ChangeNotifier { } catch (e) { /* Do nothing and use the default value given by the constructor. */ } - try { - sgSelector = SGSelector.values.byName(storage.getString(sgSelectorKey)!); - } catch (e) { - /* Do nothing and use the default value given by the constructor. */ - } - try { - routingEndpoint = RoutingEndpoint.values.byName(storage.getString(routingEndpointKey)!); - } catch (e) { - /* Do nothing and use the default value given by the constructor. */ - } try { isFreeRideFilterEnabled = storage.getBool(isFreeRideFilterEnabledKey) ?? defaultIsFreeRideFilterEnabled; } catch (e) { diff --git a/lib/settings/views/internal.dart b/lib/settings/views/internal.dart index b3a14065a..be672bd91 100644 --- a/lib/settings/views/internal.dart +++ b/lib/settings/views/internal.dart @@ -185,7 +185,7 @@ class InternalSettingsViewState extends State { /// A callback that is executed when a routing endpoint is selected. Future onSelectRoutingMode(RoutingEndpoint routingEndpoint) async { // Tell the settings service that we selected the new backend. - await settings.setRoutingEndpoint(routingEndpoint); + settings.setRoutingEndpoint(routingEndpoint); if (mounted) Navigator.pop(context); } @@ -193,7 +193,7 @@ class InternalSettingsViewState extends State { /// A callback that is executed when a sg-selector is selected. Future onSelectSGSelector(SGSelector sgSelector) async { // Tell the settings service that we selected the new sg-selector. - await settings.setSGSelector(sgSelector); + settings.setSGSelector(sgSelector); if (mounted) Navigator.pop(context); }