From 25c548c96f4818036430606f97b0f83afcb08210 Mon Sep 17 00:00:00 2001 From: "S. Kozyr" Date: Sun, 17 Mar 2024 23:12:55 +0200 Subject: [PATCH] [ios] Added new alert for OSM re-auth action Signed-off-by: S. Kozyr --- .../AlertController/MWMAlertViewController.h | 1 + .../AlertController/MWMAlertViewController.mm | 4 + .../Classes/CustomAlert/BaseAlert/MWMAlert.h | 1 + .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 4 + .../Classes/CustomAlert/MWMOsmReauthAlert.h | 7 + .../Classes/CustomAlert/MWMOsmReauthAlert.mm | 31 ++++ .../Classes/CustomAlert/MWMOsmReauthAlert.xib | 141 ++++++++++++++++++ .../Login/MWMAuthorizationCommon.h | 3 + .../Login/MWMAuthorizationCommon.mm | 29 +++- iphone/Maps/Classes/MapViewController.h | 2 + iphone/Maps/Classes/MapViewController.mm | 12 ++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 20 ++- 12 files changed, 252 insertions(+), 3 deletions(-) create mode 100644 iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.h create mode 100644 iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.mm create mode 100644 iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.xib diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index 3f304a4f1e..833a5110b9 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -37,6 +37,7 @@ - (void)presentDeleteFeatureAlertWithBlock:(nonnull MWMVoidBlock)block; - (void)presentEditorViralAlert; - (void)presentOsmAuthAlert; +- (void)presentOsmReauthAlert; - (void)presentPersonalInfoWarningAlertWithBlock:(nonnull MWMVoidBlock)block; - (void)presentTrackWarningAlertWithCancelBlock:(nonnull MWMVoidBlock)block; - (void)presentMobileInternetAlertWithBlock:(nonnull MWMMobileInternetAlertCompletionBlock)block; diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index c29c6e9d12..51fa923cdf 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -179,6 +179,10 @@ static NSString *const kAlertControllerNibIdentifier = @"MWMAlertViewController" [self displayAlert:[MWMAlert osmAuthAlert]]; } +- (void)presentOsmReauthAlert { + [self displayAlert:[MWMAlert osmReauthAlert]]; +} + - (void)presentCreateBookmarkCategoryAlertWithMaxCharacterNum:(NSUInteger)max minCharacterNum:(NSUInteger)min callback:(nonnull MWMCheckStringBlock)callback { diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h index a4083b48eb..ec68985145 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h @@ -29,6 +29,7 @@ + (MWMAlert *)deleteFeatureAlertWithBlock:(MWMVoidBlock)block; + (MWMAlert *)editorViralAlert; + (MWMAlert *)osmAuthAlert; ++ (MWMAlert *)osmReauthAlert; + (MWMAlert *)personalInfoWarningAlertWithBlock:(MWMVoidBlock)block; + (MWMAlert *)trackWarningAlertWithCancelBlock:(MWMVoidBlock)block; + (MWMAlert *)infoAlert:(NSString *)title text:(NSString *)text; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 6dc21cd450..a38b3aebf4 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -5,6 +5,7 @@ #import "MWMEditorViralAlert.h" #import "MWMLocationAlert.h" #import "MWMOsmAuthAlert.h" +#import "MWMOsmReauthAlert.h" #import "MWMPlaceDoesntExistAlert.h" #import "MWMRoutingDisclaimerAlert.h" @@ -158,6 +159,9 @@ + (MWMAlert *)osmAuthAlert { return [MWMOsmAuthAlert alert]; } ++ (MWMAlert *)osmReauthAlert { + return [MWMOsmReauthAlert alert]; +} + (MWMAlert *)personalInfoWarningAlertWithBlock:(MWMVoidBlock)block { return [MWMDefaultAlert personalInfoWarningAlertWithBlock:block]; } diff --git a/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.h b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.h new file mode 100644 index 0000000000..b536064bb7 --- /dev/null +++ b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.h @@ -0,0 +1,7 @@ +#import "MWMAlert.h" + +@interface MWMOsmReauthAlert : MWMAlert + ++ (instancetype)alert; + +@end diff --git a/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.mm b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.mm new file mode 100644 index 0000000000..be92af76d6 --- /dev/null +++ b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.mm @@ -0,0 +1,31 @@ +#import "MWMAlertViewController.h" +#import "MWMOsmReauthAlert.h" +#import "MWMAuthorizationCommon.h" + +#include "editor/osm_auth.hpp" + +static NSString * const kMap2OsmLoginSegue = @"Map2OsmLogin"; + +@implementation MWMOsmReauthAlert + ++ (instancetype)alert +{ + MWMOsmReauthAlert * alert = + [NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil].firstObject; + return alert; +} + +- (IBAction)osmTap +{ + [self close:^{ + [self.alertController.ownerViewController performSegueWithIdentifier:kMap2OsmLoginSegue + sender:nil]; + }]; +} + +- (IBAction)closeTap +{ + [self close:nil]; +} + +@end diff --git a/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.xib b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.xib new file mode 100644 index 0000000000..1640d53d80 --- /dev/null +++ b/iphone/Maps/Classes/CustomAlert/MWMOsmReauthAlert.xib @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h index a5b9c57726..98ed4f37a9 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.h @@ -12,6 +12,9 @@ enum class AuthorizationButtonType // Deletes any stored credentials if called with empty key or secret. void AuthorizationStoreCredentials(std::string const & oauthToken); +BOOL AuthorizationHaveOAuth1Credentials(); +void AuthorizationClearOAuth1Credentials(); +void AuthorizationCreateOAuth1Credentials(); BOOL AuthorizationHaveCredentials(); void AuthorizationClearCredentials(); // Returns empty key and secret if user has not beed authorized. diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm index 006e3a7b4f..1c0d0a9eb2 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationCommon.mm @@ -8,8 +8,8 @@ namespace osm_auth_ios { -NSString * const kOSMRequestToken = @"OSMRequestToken"; -NSString * const kOSMRequestSecret = @"OSMRequestSecret"; +NSString * const kOSMRequestToken = @"OSMRequestToken"; // Unused after migration from OAuth1 to OAuth2 +NSString * const kOSMRequestSecret = @"OSMRequestSecret"; // Unused after migration from OAuth1 to OAuth2 NSString * const kAuthNeedCheck = @"AuthNeedCheck"; NSString * const kOSMAuthToken = @"OSMAuthToken"; NSString * const kOSMUserName = @"UDOsmUserName"; @@ -47,6 +47,31 @@ void AuthorizationStoreCredentials(std::string const & oauthToken) [ud synchronize]; } +BOOL AuthorizationHaveOAuth1Credentials() +{ + NSUserDefaults * ud = NSUserDefaults.standardUserDefaults; + NSString * requestToken = [ud stringForKey:kOSMRequestToken]; + NSString * requestSecret = [ud stringForKey:kOSMRequestSecret]; + return requestToken.length && requestSecret.length; +} + +void AuthorizationClearOAuth1Credentials() +{ + NSUserDefaults * ud = NSUserDefaults.standardUserDefaults; + [ud removeObjectForKey:kOSMRequestToken]; + [ud removeObjectForKey:kOSMRequestSecret]; + [ud synchronize]; +} + +void AuthorizationCreateOAuth1Credentials() +{ + NSUserDefaults * ud = NSUserDefaults.standardUserDefaults; + [ud setObject:@"kOSMRequestToken" forKey:kOSMRequestToken]; + [ud setObject:@"kOSMRequestSecret" forKey:kOSMRequestSecret]; + + [ud synchronize]; +} + BOOL AuthorizationHaveCredentials() { NSUserDefaults * ud = NSUserDefaults.standardUserDefaults; diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 94865f1f11..3657a6e340 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -20,6 +20,8 @@ - (void)updateStatusBarStyle; +- (void)migrateOAuthCredentials; + - (void)performAction:(NSString *_Nonnull)action; - (void)openMapsDownloader:(MWMMapDownloaderMode)mode; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 729ca9c52f..5531911ccb 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -363,6 +363,8 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing"; // Otherwise PP container view is nil, or there is no animation/selection of the point. if (DeepLinkHandler.shared.isLaunchedByDeeplink) (void)[DeepLinkHandler.shared handleDeepLinkAndReset]; + else + [self migrateOAuthCredentials]; } - (void)viewDidLayoutSubviews { @@ -417,6 +419,16 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing"; - (void)updateStatusBarStyle { [self setNeedsStatusBarAppearanceUpdate]; } + +- (void)migrateOAuthCredentials { + if (osm_auth_ios::AuthorizationHaveOAuth1Credentials()) + { + //osm_auth_ios::AuthorizationClearOAuth1Credentials(); + // TODO + [self.alertController presentOsmReauthAlert]; + } +} + - (id)initWithCoder:(NSCoder *)coder { NSLog(@"MapViewController initWithCoder Started"); self = [super initWithCoder:coder]; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 2ca8e0a177..210beccec0 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -184,6 +184,8 @@ 408645FC21495EB1000A4A1D /* categories_cuisines.txt in Resources */ = {isa = PBXBuildFile; fileRef = 408645FB21495EB1000A4A1D /* categories_cuisines.txt */; }; 44360A0D2A7D34990016F412 /* TransportRuler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44360A0C2A7D34990016F412 /* TransportRuler.swift */; }; 44360A112A7D35440016F412 /* TransportRuler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 44360A102A7D35440016F412 /* TransportRuler.xib */; }; + 447DB4BC2BA78282000DF4C2 /* MWMOsmReauthAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 447DB4BB2BA78282000DF4C2 /* MWMOsmReauthAlert.mm */; }; + 447DB4C42BA78665000DF4C2 /* MWMOsmReauthAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 447DB4C12BA78665000DF4C2 /* MWMOsmReauthAlert.xib */; }; 4501B1942077C35A001B9173 /* resources-xxxhdpi_clear in Resources */ = {isa = PBXBuildFile; fileRef = 4501B1922077C35A001B9173 /* resources-xxxhdpi_clear */; }; 4501B1952077C35A001B9173 /* resources-xxxhdpi_dark in Resources */ = {isa = PBXBuildFile; fileRef = 4501B1932077C35A001B9173 /* resources-xxxhdpi_dark */; }; 4554B6EC1E55F0EF0084017F /* drules_proto_vehicle_clear.bin in Resources */ = {isa = PBXBuildFile; fileRef = 4554B6E81E55F02B0084017F /* drules_proto_vehicle_clear.bin */; }; @@ -1042,6 +1044,9 @@ 408645FB21495EB1000A4A1D /* categories_cuisines.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = categories_cuisines.txt; path = ../../data/categories_cuisines.txt; sourceTree = ""; }; 44360A0C2A7D34990016F412 /* TransportRuler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransportRuler.swift; sourceTree = ""; }; 44360A102A7D35440016F412 /* TransportRuler.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TransportRuler.xib; sourceTree = ""; }; + 447DB4BA2BA78282000DF4C2 /* MWMOsmReauthAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MWMOsmReauthAlert.h; path = Classes/CustomAlert/MWMOsmReauthAlert.h; sourceTree = SOURCE_ROOT; }; + 447DB4BB2BA78282000DF4C2 /* MWMOsmReauthAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MWMOsmReauthAlert.mm; path = Classes/CustomAlert/MWMOsmReauthAlert.mm; sourceTree = SOURCE_ROOT; }; + 447DB4C12BA78665000DF4C2 /* MWMOsmReauthAlert.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MWMOsmReauthAlert.xib; path = Classes/CustomAlert/MWMOsmReauthAlert.xib; sourceTree = SOURCE_ROOT; }; 4501B1922077C35A001B9173 /* resources-xxxhdpi_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_clear"; path = "../../data/resources-xxxhdpi_clear"; sourceTree = ""; }; 4501B1932077C35A001B9173 /* resources-xxxhdpi_dark */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_dark"; path = "../../data/resources-xxxhdpi_dark"; sourceTree = ""; }; 451950391B7A3E070085DA05 /* patterns.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = patterns.txt; path = ../../data/patterns.txt; sourceTree = ""; }; @@ -2469,6 +2474,16 @@ path = Widgets; sourceTree = ""; }; + 447DB4B72BA7826D000DF4C2 /* ReauthAlert */ = { + isa = PBXGroup; + children = ( + 447DB4C12BA78665000DF4C2 /* MWMOsmReauthAlert.xib */, + 447DB4BA2BA78282000DF4C2 /* MWMOsmReauthAlert.h */, + 447DB4BB2BA78282000DF4C2 /* MWMOsmReauthAlert.mm */, + ); + path = ReauthAlert; + sourceTree = ""; + }; 470F0B7B238842AD006AEC94 /* Views */ = { isa = PBXGroup; children = ( @@ -3016,6 +3031,7 @@ F64F195F1AB8125C006EAF7E /* CustomAlert */ = { isa = PBXGroup; children = ( + 447DB4B72BA7826D000DF4C2 /* ReauthAlert */, F62607FB207B78E300176C5A /* SpinnerAlert */, F6D67CDA2062B9810032FD38 /* CreateBookmarkCategory */, 349B92691DF0516C007779DD /* Toast */, @@ -3126,9 +3142,9 @@ F6BD1D1D1CA412700047B8E8 /* AuthAlert */ = { isa = PBXGroup; children = ( + F6BD1D221CA412E30047B8E8 /* MWMOsmAuthAlert.xib */, F6BD1D1E1CA412920047B8E8 /* MWMOsmAuthAlert.h */, F6BD1D1F1CA412920047B8E8 /* MWMOsmAuthAlert.mm */, - F6BD1D221CA412E30047B8E8 /* MWMOsmAuthAlert.xib */, ); name = AuthAlert; sourceTree = ""; @@ -3899,6 +3915,7 @@ F6E2FE2E1E097BA00083EBEC /* MWMStreetEditorEditTableViewCell.xib in Resources */, 3463BA691DE81DB90082417F /* MWMTrafficButtonViewController.xib in Resources */, F623DA6C1C9C2731006A3436 /* opening_hours_how_to_edit.html in Resources */, + 447DB4C42BA78665000DF4C2 /* MWMOsmReauthAlert.xib in Resources */, 6741A9761BF340DE002C974C /* packed_polygons.bin in Resources */, 676507601C10559800830BB3 /* patterns.txt in Resources */, 6B15907226623AE500944BBA /* 00_NotoSansThai-Regular.ttf in Resources */, @@ -4301,6 +4318,7 @@ 993DF10523F6BDB100AC231A /* UINavigationItem+styleName.swift in Sources */, 9977E69C247BFB510073780C /* SearchTextField.swift in Sources */, 4726254921C27D4B00C7BAAD /* PlacePageDescriptionViewController.swift in Sources */, + 447DB4BC2BA78282000DF4C2 /* MWMOsmReauthAlert.mm in Sources */, 340475711E081A4600C92850 /* MWMSettings.mm in Sources */, 33046832219C57180041F3A8 /* CategorySettingsViewController.swift in Sources */, 3404756E1E081A4600C92850 /* MWMSearch.mm in Sources */,