From 66b4f4e6a375f8ebbefacf4d29a4684aff94ca1e Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Tue, 26 Jan 2016 12:11:41 +0300 Subject: [PATCH] [ios] Added profile page. --- .../MWMAuthorizationLoginViewController.mm | 160 ++++++- iphone/Maps/Classes/MapViewController.h | 2 - iphone/Maps/Classes/MapViewController.mm | 4 +- iphone/Maps/Mapsme.storyboard | 401 ++++++++++-------- 4 files changed, 382 insertions(+), 185 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm index b51a731901..cade59ea83 100644 --- a/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm +++ b/iphone/Maps/Classes/CustomViews/Login/MWMAuthorizationLoginViewController.mm @@ -1,22 +1,44 @@ #import "Common.h" #import "MapsAppDelegate.h" #import "MWMAuthorizationCommon.h" +#import "MWMAuthorizationCommon.h" #import "MWMAuthorizationLoginViewController.h" #import "MWMAuthorizationWebViewLoginViewController.h" #import "UIColor+MapsMeColor.h" #include "editor/osm_auth.hpp" +#include "editor/server_api.hpp" using namespace osm; -@interface MWMAuthorizationLoginViewController () +@interface MWMAuthorizationLoginViewController () @property (weak, nonatomic) IBOutlet UIImageView * backgroundImage; @property (weak, nonatomic) IBOutlet UIButton * loginGoogleButton; @property (weak, nonatomic) IBOutlet UIButton * loginFacebookButton; @property (weak, nonatomic) IBOutlet UIButton * loginOSMButton; @property (weak, nonatomic) IBOutlet UIButton * signupButton; +@property (weak, nonatomic) IBOutlet UILabel * message; +@property (weak, nonatomic) IBOutlet UILabel * signupTitle; +@property (weak, nonatomic) IBOutlet UIButton * logoutButton; +@property (weak, nonatomic) IBOutlet UIImageView * googleImage; +@property (weak, nonatomic) IBOutlet UIImageView * facebookImage; +@property (weak, nonatomic) IBOutlet UIBarButtonItem * leftBarButton; + +@property (weak, nonatomic) IBOutlet UIView * profileView; +@property (weak, nonatomic) IBOutlet UILabel * localChangesLabel; +@property (weak, nonatomic) IBOutlet UILabel * localChangesNotUploadedLabel; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint * localChangesViewHeight; +@property (weak, nonatomic) IBOutlet UIButton * localChangesActionButton; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint * localChangesLabelCenter; + +@property (weak, nonatomic) IBOutlet UILabel * uploadedChangesLabel; +@property (weak, nonatomic) IBOutlet UILabel * lastUploadLabel; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint * uploadedChangesViewHeight; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint * uploadedChangesLabelCenter; + +@property (weak, nonatomic) IBOutlet NSLayoutConstraint * messageTopOffset; @end @implementation MWMAuthorizationLoginViewController @@ -31,7 +53,12 @@ using namespace osm; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - self.title = L(@"login"); + if (MWMAuthorizationHaveCredentials()) + [self configHaveAuth]; + else + [self configNoAuth:MWMAuthorizationIsNeedCheck() && !MWMAuthorizationIsUserSkip()]; + + [self configChanges]; UINavigationBar * navBar = self.navigationController.navigationBar; navBar.barStyle = UIBarStyleBlack; navBar.tintColor = [UIColor clearColor]; @@ -40,6 +67,7 @@ using namespace osm; navBar.shadowImage = [[UIImage alloc] init]; [navBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; navBar.translucent = YES; + MWMAuthorizationSetNeedCheck(NO); } - (void)viewWillDisappear:(BOOL)animated @@ -71,6 +99,94 @@ using namespace osm; } } +- (void)configHaveAuth +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ + { + OsmOAuth auth = OsmOAuth::ServerAuth(); + auth.SetToken(MWMAuthorizationGetCredentials()); + ServerApi06 api(auth); + UserPreferences prefs; + if (api.GetUserPreferences(prefs) != OsmOAuth::ResponseCode::OK) + return; + dispatch_async(dispatch_get_main_queue(), ^ + { + self.title = @(prefs.m_displayName.c_str()); + }); + }); + self.title = @""; + self.message.hidden = YES; + self.loginGoogleButton.hidden = YES; + self.loginFacebookButton.hidden = YES; + self.loginOSMButton.hidden = YES; + self.signupTitle.hidden = YES; + self.signupButton.hidden = YES; + self.googleImage.hidden = YES; + self.facebookImage.hidden = YES; + self.logoutButton.hidden = NO; + self.leftBarButton.image = [UIImage imageNamed:@"btn_back_arrow"]; +} + +- (void)configNoAuth:(BOOL)isAfterFirstEdit +{ + self.message.hidden = NO; + self.loginGoogleButton.hidden = NO; + self.loginFacebookButton.hidden = NO; + self.loginOSMButton.hidden = NO; + self.signupTitle.hidden = NO; + self.signupButton.hidden = NO; + self.googleImage.hidden = NO; + self.facebookImage.hidden = NO; + self.logoutButton.hidden = YES; + if (isAfterFirstEdit) + { + self.title = L(@"thank_you"); + self.message.text = L(@"thank_you_message"); + self.leftBarButton.image = [UIImage imageNamed:@"ic_nav_bar_close"]; + } + else + { + self.title = L(@"profile"); + self.message.text = L(@"profile_message"); + self.leftBarButton.image = [UIImage imageNamed:@"btn_back_arrow"]; + } +} + +- (void)configChanges +{ + auto const stats = Editor::Instance().GetStats(); + if (stats.m_edits.empty() && !MWMAuthorizationHaveCredentials()) + { + self.profileView.hidden = YES; + self.messageTopOffset.priority = UILayoutPriorityDefaultHigh; + } + else + { + size_t const totalChanges = stats.m_edits.size(); + size_t const uploadedChanges = stats.m_uploadedCount; + size_t const localChanges = totalChanges - uploadedChanges; + + self.localChangesLabel.text = [NSString stringWithFormat:@"%@: %@", L(@"changes"), @(localChanges).stringValue]; + BOOL const noLocalChanges = (localChanges == 0); + self.localChangesNotUploadedLabel.hidden = noLocalChanges; + self.localChangesActionButton.hidden = noLocalChanges; + self.localChangesViewHeight.constant = noLocalChanges ? 44.0 : 64.0; + self.localChangesLabelCenter.priority = noLocalChanges ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow; + + BOOL const noUploadedChanges = (uploadedChanges == 0); + self.uploadedChangesLabel.text = [NSString stringWithFormat:@"%@: %@", L(@"changes"), @(uploadedChanges).stringValue]; + self.lastUploadLabel.hidden = noUploadedChanges; + if (!noUploadedChanges) + self.lastUploadLabel.text = [NSDateFormatter + localizedStringFromDate:[NSDate dateWithTimeIntervalSince1970:stats.m_lastUploadTimestamp] + dateStyle:NSDateFormatterShortStyle + timeStyle:NSDateFormatterNoStyle]; + self.uploadedChangesViewHeight.constant = noUploadedChanges ? 44.0 : 64.0; + self.uploadedChangesLabelCenter.priority = noUploadedChanges ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow; + self.messageTopOffset.priority = UILayoutPriorityDefaultLow; + } +} + #pragma mark - Actions - (IBAction)loginGoogle @@ -90,6 +206,12 @@ using namespace osm; [[UIApplication sharedApplication] openURL:url]; } +- (IBAction)logout +{ + MWMAuthorizationStoreCredentials({}); + [self cancel]; +} + - (IBAction)cancel { if (!self.isCalledFromSettings) @@ -101,6 +223,40 @@ using namespace osm; [self dismissViewControllerAnimated:YES completion:nil]; } +- (IBAction)localChangesAction +{ + NSString * cancel = L(@"cancel"); + NSString * del = L(@"delete"); + if (isIOSVersionLessThan(8)) + { + UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:cancel destructiveButtonTitle:del otherButtonTitles:nil]; + [actionSheet showInView:self.view]; + } + else + { + UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction * openSettingsAction = [UIAlertAction actionWithTitle:del style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) + { + Editor::Instance().ClearAllLocalEdits(); + [self configChanges]; + }]; + [alertController addAction:cancelAction]; + [alertController addAction:openSettingsAction]; + [self presentViewController:alertController animated:YES completion:nil]; + } +} + +#pragma mark - UIActionSheetDelegate + +- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if (actionSheet.destructiveButtonIndex != buttonIndex) + return; + Editor::Instance().ClearAllLocalEdits(); + [self configChanges]; +} + #pragma mark - Segue - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 248d38ba09..a2c39feb39 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -10,7 +10,6 @@ namespace search { struct AddressInfo; } @class MWMMapViewControlsManager; -@class ShareActionSheet; @class MWMAPIBar; @interface MapViewController : ViewController @@ -45,7 +44,6 @@ namespace search { struct AddressInfo; } @property (nonatomic, readonly) BOOL isAppWallAdActive; @property (nonatomic) UIPopoverController * popoverVC; -@property (nonatomic) ShareActionSheet * shareActionSheet; @property (nonatomic, readonly) MWMMapViewControlsManager * controlsManager; @property (nonatomic) m2::PointD restoreRouteDestination; @property (nonatomic) MWMAPIBar * apiBar; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 6cb17b5365..acdb1d8d90 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -660,13 +660,13 @@ NSString * const kAuthorizationSegue = @"Map2AuthorizationSegue"; - (void)checkAuthorization { - if (MWMAuthorizationIsNeedCheck() && !MWMAuthorizationHaveCredentials() && !MWMAuthorizationIsUserSkip()) + BOOL const isAfterFirstEdit = MWMAuthorizationIsNeedCheck() && !MWMAuthorizationHaveCredentials() && !MWMAuthorizationIsUserSkip(); + if (isAfterFirstEdit) { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatEditTime) withParameters:@{kStatValue : kStatAuthorization}]; [self performSegueWithIdentifier:kAuthorizationSegue sender:nil]; } - MWMAuthorizationSetNeedCheck(NO); } #pragma mark - 3d touch diff --git a/iphone/Maps/Mapsme.storyboard b/iphone/Maps/Mapsme.storyboard index a9fd89bd5d..315a4e0bac 100644 --- a/iphone/Maps/Mapsme.storyboard +++ b/iphone/Maps/Mapsme.storyboard @@ -2,7 +2,7 @@ - + @@ -25,7 +25,6 @@ - @@ -47,7 +46,6 @@ - @@ -65,7 +63,6 @@ - @@ -77,7 +74,6 @@ - @@ -94,7 +89,6 @@ - @@ -111,7 +105,6 @@ - @@ -134,7 +126,6 @@ - @@ -144,7 +135,6 @@ - @@ -162,7 +152,6 @@ - @@ -179,7 +167,6 @@ - @@ -213,7 +200,6 @@ - @@ -227,7 +213,6 @@ - @@ -246,7 +230,6 @@ - @@ -263,7 +246,6 @@ - @@ -282,7 +263,6 @@ - @@ -299,7 +279,6 @@ - @@ -318,7 +296,6 @@ - @@ -351,8 +328,7 @@ - - + @@ -365,7 +341,6 @@ - @@ -384,7 +358,6 @@ - @@ -401,7 +374,6 @@ - @@ -420,7 +391,6 @@ - @@ -437,7 +407,6 @@ - @@ -456,7 +424,6 @@ - @@ -473,7 +440,6 @@ - @@ -492,7 +457,6 @@ - @@ -509,7 +473,6 @@ - @@ -528,7 +490,6 @@ - @@ -545,7 +506,6 @@ - @@ -564,7 +523,6 @@ - @@ -581,7 +539,6 @@ - @@ -599,7 +555,6 @@ - @@ -632,7 +587,6 @@ - @@ -644,7 +598,6 @@ - @@ -662,7 +614,6 @@ - @@ -679,7 +630,6 @@ - @@ -697,7 +646,6 @@ - @@ -728,7 +676,6 @@ - @@ -740,7 +687,6 @@ - @@ -758,7 +703,6 @@ - @@ -802,7 +746,6 @@ - @@ -810,7 +753,6 @@ - @@ -848,7 +790,6 @@ - @@ -861,7 +802,6 @@ - @@ -895,7 +835,6 @@ - @@ -913,7 +852,6 @@ - @@ -938,7 +876,6 @@ - @@ -958,7 +894,6 @@ - @@ -969,14 +904,12 @@ - @@ -995,7 +928,6 @@ - @@ -1012,7 +944,6 @@ - @@ -1027,7 +958,6 @@ - @@ -1038,7 +968,6 @@ - @@ -1049,7 +978,6 @@ - @@ -1060,7 +988,6 @@ - @@ -1070,7 +997,6 @@ - @@ -1098,7 +1024,6 @@ - @@ -1121,7 +1045,6 @@ - @@ -1131,7 +1054,6 @@ - @@ -1147,7 +1069,6 @@ - @@ -1206,7 +1127,6 @@ - @@ -1215,7 +1135,6 @@ - @@ -1254,7 +1171,6 @@ - @@ -1267,7 +1183,6 @@ - @@ -1309,7 +1223,6 @@ - @@ -1359,7 +1272,6 @@ - @@ -1368,7 +1280,6 @@ - @@ -1407,7 +1316,6 @@ - @@ -1420,7 +1328,6 @@ - @@ -1490,7 +1395,6 @@ - @@ -1536,7 +1440,6 @@ - @@ -1547,7 +1450,6 @@ - @@ -1562,7 +1464,6 @@ - @@ -1573,7 +1474,6 @@ - @@ -1588,7 +1488,6 @@ - @@ -1598,7 +1497,6 @@ - @@ -1626,7 +1524,6 @@ - @@ -1729,11 +1623,147 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - - + + + - + - + + @@ -1872,19 +1919,24 @@ the world. Join us! + + + + + - + - + @@ -1896,10 +1948,27 @@ the world. Join us! + + + + + + + + + + + + + + + + + @@ -1920,7 +1989,6 @@ the world. Join us! - @@ -1952,7 +2019,6 @@ the world. Join us! - @@ -1985,7 +2050,6 @@ the world. Join us! - @@ -1996,7 +2060,6 @@ the world. Join us! - @@ -2013,7 +2076,6 @@ the world. Join us! - @@ -2024,7 +2086,6 @@ the world. Join us! - @@ -2041,7 +2102,6 @@ the world. Join us! - @@ -2052,7 +2112,6 @@ the world. Join us! - @@ -2069,7 +2128,6 @@ the world. Join us! - @@ -2079,7 +2137,6 @@ the world. Join us! - @@ -2111,7 +2168,6 @@ the world. Join us! - @@ -2215,7 +2269,6 @@ the world. Join us! - @@ -2223,7 +2276,6 @@ the world. Join us! - @@ -2231,7 +2283,6 @@ the world. Join us! - @@ -2265,7 +2316,6 @@ the world. Join us! - @@ -2410,7 +2454,6 @@ the world. Join us! - @@ -2429,7 +2472,6 @@ the world. Join us! - @@ -2454,7 +2496,6 @@ the world. Join us! - @@ -2467,7 +2508,6 @@ the world. Join us! - @@ -2492,6 +2532,9 @@ the world. Join us! + + +