Skip to content

Commit

Permalink
Remove persistence of sg selector and map data settings
Browse files Browse the repository at this point in the history
  • Loading branch information
adeveloper-wq committed Jun 19, 2024
1 parent 2fb5f94 commit 0e0c67d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
40 changes: 5 additions & 35 deletions lib/settings/services/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,11 @@ class Settings with ChangeNotifier {
return success;
}

static const routingEndpointKey = "priobike.settings.routingEndpoint";
static const defaultRoutingEndpoint = RoutingEndpoint.graphhopperDRN;

Future<bool> 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";
Expand Down Expand Up @@ -341,21 +331,11 @@ class Settings with ChangeNotifier {
return success;
}

static const sgSelectorKey = "priobike.settings.sgSelector";
static const defaultSGSelector = SGSelector.ml;

Future<bool> 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";
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/settings/views/internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ class InternalSettingsViewState extends State<InternalSettingsView> {
/// A callback that is executed when a routing endpoint is selected.
Future<void> 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);
}

/// A callback that is executed when a sg-selector is selected.
Future<void> 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);
}
Expand Down

0 comments on commit 0e0c67d

Please sign in to comment.