Skip to content

Commit

Permalink
Merge pull request #3203 from osmandapp/plugins_reset_button
Browse files Browse the repository at this point in the history
add reset plugin to default button
  • Loading branch information
alex-osm authored Nov 7, 2023
2 parents daa073b + dc220f2 commit d79cca8
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Resources/Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"auto_split_recording_title" = "Auto-split recordings after gap";
"auto_split_gap_descr" = "Start a new segment after 6 min gap, new track after 2 h gap, or new file after a longer gap";
"trip_rec_actions_descr" = "You can find all your recorded tracks in %@";
"reset_plugin_to_default" = "Reset plugin settings to default";
"reset_plugin_to_default" = "Reset all plugin settings to installation defaults";
"save_heading" = "Include heading";
"save_heading_descr" = "Save heading to each track point while recording.";
"distance_circles" = "Distance circles";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,47 @@ - (BOOL) refreshOnAppear
return YES;
}

- (NSArray<UIBarButtonItem *> *)getRightNavbarButtons
{
UIBarButtonItem *rightButton = [self createRightNavbarButton:nil iconName:@"ic_navbar_reset" action:@selector(onRightNavbarButtonPressed) menu:nil];
rightButton.accessibilityLabel = OALocalizedString(@"reset_to_default");
return @[rightButton];
}

- (void)onRightNavbarButtonPressed
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:OALocalizedString(@"reset_to_default") message:OALocalizedString(@"reset_plugin_to_default") preferredStyle:UIAlertControllerStyleActionSheet];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.barButtonItem = self.navigationItem.rightBarButtonItem;
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionAny;

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_cancel") style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *resetAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_reset") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
{
[_settings.mapSettingSaveTrackIntervalApproved resetToDefault];
[_settings.mapSettingSaveTrackIntervalGlobal resetToDefault];
[_settings.mapSettingSaveTrackInterval resetToDefault];
[_settings.saveTrackMinDistance resetToDefault];
[_settings.saveTrackPrecision resetToDefault];
[_settings.saveTrackMinSpeed resetToDefault];
[_settings.saveHeadingToGpx resetToDefault];
[_settings.saveTrackToGPX resetToDefault];
[_settings.autoSplitRecording resetToDefault];
[_settings.mapSettingSaveTrackIntervalGlobal resetToDefault];
[_settings.mapSettingSaveTrackInterval resetToDefault];
[self generateData];
[self.tableView reloadData];
}];

[alert addAction:resetAction];
[alert addAction:cancelAction];
alert.preferredAction = resetAction;

[self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Table data

- (void)generateData
Expand Down
31 changes: 31 additions & 0 deletions Sources/Controllers/Settings/OAWikipediaSettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ - (NSString *)getSubtitle
return OALocalizedString(@"shared_string_settings");
}

- (NSArray<UIBarButtonItem *> *)getRightNavbarButtons
{
UIBarButtonItem *rightButton = [self createRightNavbarButton:nil iconName:@"ic_navbar_reset" action:@selector(onRightNavbarButtonPressed) menu:nil];
rightButton.accessibilityLabel = OALocalizedString(@"reset_to_default");
return @[rightButton];
}

- (void)onRightNavbarButtonPressed
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:OALocalizedString(@"reset_to_default") message:OALocalizedString(@"reset_plugin_to_default") preferredStyle:UIAlertControllerStyleActionSheet];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.barButtonItem = self.navigationItem.rightBarButtonItem;
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionAny;

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_cancel") style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *resetAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_reset") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
{
[_wikiPlugin resetToDefaults];
[self generateData];
[self.tableView reloadData];
}];

[alert addAction:resetAction];
[alert addAction:cancelAction];
alert.preferredAction = resetAction;

[self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Table data

- (void)generateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#import "OAIAPHelper.h"
#import "OsmAnd_Maps-Swift.h"

#define kAccountSectionIndex 0
#define kOfflineEditingSectionIndex 1

@interface OAOsmEditingSettingsViewController () <OAAccountSettingDelegate>

@end
Expand Down Expand Up @@ -63,6 +66,39 @@ - (NSString *)getTableHeaderDescription
return OALocalizedString(@"osm_editing_settings_descr");
}

- (NSArray<UIBarButtonItem *> *)getRightNavbarButtons
{
UIBarButtonItem *rightButton = [self createRightNavbarButton:nil iconName:@"ic_navbar_reset" action:@selector(onRightNavbarButtonPressed) menu:nil];
rightButton.accessibilityLabel = OALocalizedString(@"reset_to_default");
return @[rightButton];
}

- (void)onRightNavbarButtonPressed
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:OALocalizedString(@"reset_to_default") message:OALocalizedString(@"reset_plugin_to_default") preferredStyle:UIAlertControllerStyleActionSheet];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.barButtonItem = self.navigationItem.rightBarButtonItem;
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionAny;

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_cancel") style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *resetAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_reset") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
{
[OAOsmOAuthHelper logOut];
[_settings.offlineEditing resetToDefault];
[self generateData];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kAccountSectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kOfflineEditingSectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
}];

[alert addAction:resetAction];
[alert addAction:cancelAction];
alert.preferredAction = resetAction;

[self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Table data

- (void)generateData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#import "OAWeatherBand.h"
#import "OAWeatherHelper.h"

#define kBandsSectionIndex 0
#define kUseOfflineDataSectionIndex 1

@interface OAWeatherSettingsViewController () <OAWeatherBandSettingsDelegate, OAWeatherCacheSettingsDelegate>

@end
Expand Down Expand Up @@ -60,6 +63,38 @@ - (NSString *)getSubtitle
return OALocalizedString(@"shared_string_settings");
}

- (NSArray<UIBarButtonItem *> *)getRightNavbarButtons
{
UIBarButtonItem *rightButton = [self createRightNavbarButton:nil iconName:@"ic_navbar_reset" action:@selector(onRightNavbarButtonPressed) menu:nil];
rightButton.accessibilityLabel = OALocalizedString(@"reset_to_default");
return @[rightButton];
}

- (void)onRightNavbarButtonPressed
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:OALocalizedString(@"reset_to_default") message:OALocalizedString(@"reset_plugin_to_default") preferredStyle:UIAlertControllerStyleActionSheet];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.barButtonItem = self.navigationItem.rightBarButtonItem;
popPresenter.permittedArrowDirections = UIPopoverArrowDirectionAny;

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_cancel") style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *resetAction = [UIAlertAction actionWithTitle:OALocalizedString(@"shared_string_reset") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action)
{
[[OsmAndApp instance].data resetWeatherSettings];
[self generateData];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kBandsSectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kUseOfflineDataSectionIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
}];

[alert addAction:resetAction];
[alert addAction:cancelAction];
alert.preferredAction = resetAction;

[self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Table data

- (void)generateData
Expand Down
3 changes: 3 additions & 0 deletions Sources/Data/OAAppData.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,7 @@ static const NSInteger kSlopeDefMaxZoom = 16;
- (OADownloadMode *)getWikipediaImagesDownloadMode:(OAApplicationMode *)mode;
- (void)setWikipediaImagesDownloadMode:(OADownloadMode *)downloadMode mode:(OAApplicationMode *)mode;

- (void)resetWikipediaSettings;
- (void)resetWeatherSettings;

@end
60 changes: 60 additions & 0 deletions Sources/Data/OAAppData.m
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,56 @@ - (void) setWeatherPrecipAlpha:(double)weatherPrecipAlpha
}
}

- (void) resetWeatherSettings
{
@synchronized(_lock)
{
[_weatherUseOfflineDataProfile resetToDefault];

[_weatherTempProfile resetToDefault];
[_weatherTempUnitProfile resetToDefault];
[_weatherTempUnitAutoProfile resetToDefault];
[_weatherTempAlphaProfile resetToDefault];
[_weatherTempToolbarAlphaProfile resetToDefault];

[_weatherPressureProfile resetToDefault];
[_weatherPressureToolbarProfile resetToDefault];
[_weatherPressureUnitProfile resetToDefault];
[_weatherPressureToolbarUnitProfile resetToDefault];
[_weatherPressureUnitAutoProfile resetToDefault];
[_weatherPressureToolbarUnitAutoProfile resetToDefault];
[_weatherPressureAlphaProfile resetToDefault];
[_weatherPressureToolbarAlphaProfile resetToDefault];

[_weatherWindProfile resetToDefault];
[_weatherWindToolbarProfile resetToDefault];
[_weatherWindUnitProfile resetToDefault];
[_weatherWindToolbarUnitProfile resetToDefault];
[_weatherWindUnitAutoProfile resetToDefault];
[_weatherWindToolbarUnitAutoProfile resetToDefault];
[_weatherWindAlphaProfile resetToDefault];
[_weatherWindToolbarAlphaProfile resetToDefault];

[_weatherCloudProfile resetToDefault];
[_weatherCloudToolbarProfile resetToDefault];
[_weatherCloudUnitProfile resetToDefault];
[_weatherCloudToolbarUnitProfile resetToDefault];
[_weatherCloudUnitAutoProfile resetToDefault];
[_weatherCloudToolbarUnitAutoProfile resetToDefault];
[_weatherCloudAlphaProfile resetToDefault];
[_weatherCloudToolbarAlphaProfile resetToDefault];

[_weatherPrecipProfile resetToDefault];
[_weatherPrecipToolbarProfile resetToDefault];
[_weatherPrecipUnitProfile resetToDefault];
[_weatherPrecipToolbarUnitProfile resetToDefault];
[_weatherPrecipUnitAutoProfile resetToDefault];
[_weatherPrecipToolbarUnitAutoProfile resetToDefault];
[_weatherPrecipAlphaProfile resetToDefault];
[_weatherPrecipToolbarAlphaProfile resetToDefault];
}
}

- (OAMapSource*) overlayMapSource
{
@synchronized(_lock)
Expand Down Expand Up @@ -1565,6 +1615,16 @@ - (void)setWikipediaImagesDownloadMode:(OADownloadMode *)downloadMode mode:(OAAp
}
}

- (void)resetWikipediaSettings
{
@synchronized (_lock)
{
[_wikipediaGlobalProfile resetToDefault];
[_wikipediaLanguagesProfile resetToDefault];
[_wikipediaImagesDownloadModeProfile resetToDefault];
}
}

@synthesize mapLastViewedState = _mapLastViewedState;

- (void) backupTargetPoints
Expand Down
1 change: 1 addition & 0 deletions Sources/Plugins/Wikipedia/OAWikipediaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
- (NSString *)getLanguagesSummary;
- (NSString *)getLanguagesSummary:(OAApplicationMode *)mode;
- (NSString *)getWikiArticleLanguage:(NSSet<NSString *> *)availableArticleLangs preferredLanguage:(NSString *)preferredLanguage;
- (void)resetToDefaults;

@end
6 changes: 6 additions & 0 deletions Sources/Plugins/Wikipedia/OAWikipediaPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ - (void)setLanguagesToShow:(OAApplicationMode *)mode languagesToShow:(NSArray<NS
[_app.data setWikipediaLanguages:languagesToShow mode:mode];
}

- (void)resetToDefaults
{
[_app.data resetWikipediaSettings];
[_lastUsedWikipedia resetToDefault];
}

- (void)toggleWikipediaPoi:(BOOL)enable
{
if (enable)
Expand Down

0 comments on commit d79cca8

Please sign in to comment.