From 73004c77936b3d0f1a508fdebc23766dbab0b64e Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Thu, 3 Mar 2016 17:42:08 +0300 Subject: [PATCH] [ios] Added dialog for unsaved changes on delete. --- .../AlertController/MWMAlertViewController.h | 1 + .../AlertController/MWMAlertViewController.mm | 5 +++++ .../Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h | 1 + .../Classes/CustomAlert/BaseAlert/MWMAlert.mm | 5 +++++ .../CustomAlert/DefaultAlert/MWMDefaultAlert.h | 1 + .../CustomAlert/DefaultAlert/MWMDefaultAlert.mm | 10 ++++++++++ .../DataSources/MWMMapDownloaderDataSource.mm | 11 +++++++++++ .../MWMMapDownloaderDefaultDataSource.mm | 15 --------------- .../MWMBaseMapDownloaderViewController.mm | 2 +- iphone/Maps/Classes/Storage/MWMStorage.h | 2 +- iphone/Maps/Classes/Storage/MWMStorage.mm | 15 +++++++++++++-- 11 files changed, 49 insertions(+), 19 deletions(-) diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h index a453094c05..703297a397 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.h @@ -21,6 +21,7 @@ - (void)presentLocationAlert; - (void)presentLocationServiceNotSupportedAlert; - (void)presentNoConnectionAlert; +- (void)presentUnsavedEditsAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock; - (void)presentNoWiFiAlertWithName:(nonnull NSString *)name okBlock:(nullable TMWMVoidBlock)okBlock; - (void)presentPedestrianToastAlert:(BOOL)isFirstLaunch; - (void)presentInternalErrorAlert; diff --git a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm index 5b419425eb..0a4a001b47 100644 --- a/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm +++ b/iphone/Maps/Classes/CustomAlert/AlertController/MWMAlertViewController.mm @@ -81,6 +81,11 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController [self displayAlert:[MWMAlert noConnectionAlert]]; } +- (void)presentUnsavedEditsAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock +{ + [self displayAlert:[MWMAlert unsavedEditsAlertWithOkBlock:okBlock]]; +} + - (void)presentNoWiFiAlertWithName:(nonnull NSString *)name okBlock:(nullable TMWMVoidBlock)okBlock { [self displayAlert:[MWMAlert noWiFiAlertWithName:name okBlock:okBlock]]; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h index 1f8c98bde1..016e7a022c 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.h @@ -17,6 +17,7 @@ + (MWMAlert *)disabledLocationAlert; + (MWMAlert *)noWiFiAlertWithName:(NSString *)name okBlock:(TMWMVoidBlock)okBlock; + (MWMAlert *)noConnectionAlert; ++ (MWMAlert *)unsavedEditsAlertWithOkBlock:(TMWMVoidBlock)okBlock; + (MWMAlert *)locationServiceNotSupportedAlert; + (MWMAlert *)pedestrianToastShareAlert:(BOOL)isFirstLaunch; + (MWMAlert *)internalErrorAlert; diff --git a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm index 63756a39f5..1e1ee20b9e 100644 --- a/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/BaseAlert/MWMAlert.mm @@ -51,6 +51,11 @@ return [MWMDefaultAlert noConnectionAlert]; } ++ (MWMAlert *)unsavedEditsAlertWithOkBlock:(TMWMVoidBlock)okBlock +{ + return [MWMDefaultAlert unsavedEditsAlertWithOkBlock:okBlock]; +} + + (MWMAlert *)locationServiceNotSupportedAlert { return [MWMDefaultAlert locationServiceNotSupportedAlert]; diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h index 1ea4300768..8c2395cfe3 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.h @@ -14,6 +14,7 @@ + (instancetype)disabledLocationAlert; + (instancetype)noWiFiAlertWithName:(NSString *)name okBlock:(TMWMVoidBlock)okBlock; + (instancetype)noConnectionAlert; ++ (instancetype)unsavedEditsAlertWithOkBlock:(TMWMVoidBlock)okBlock; + (instancetype)locationServiceNotSupportedAlert; + (instancetype)point2PointAlertWithOkBlock:(TMWMVoidBlock)okBlock needToRebuild:(BOOL)needToRebuild; + (instancetype)downloaderNoConnectionAlertWithOkBlock:(TMWMVoidBlock)okBlock; diff --git a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm index aaf20209ba..d2e9136e2d 100644 --- a/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DefaultAlert/MWMDefaultAlert.mm @@ -74,6 +74,16 @@ static NSString * const kDefaultAlertNibName = @"MWMDefaultAlert"; return alert; } ++ (instancetype)unsavedEditsAlertWithOkBlock:(TMWMVoidBlock)okBlock +{ + kStatisticsEvent = @"Editor unsaved changes on delete"; + return [self defaultAlertWithTitle:@"editor_unsavde_changes" + message:nil + rightButtonTitle:@"delete" + leftButtonTitle:nil + rightButtonAction:okBlock]; +} + + (instancetype)noWiFiAlertWithName:(NSString *)name okBlock:(TMWMVoidBlock)okBlock { kStatisticsEvent = @"No WiFi Alert"; diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm index 74ca5b3c45..29c43cea03 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDataSource.mm @@ -56,6 +56,17 @@ using namespace storage; return cell; } +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath +{ + return NO; +} + +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (editingStyle == UITableViewCellEditingStyleDelete) + [self.delegate deleteNode:[self countryIdForIndexPath:indexPath]]; +} + #pragma mark - MWMMapDownloaderDataSource - (BOOL)isParentRoot diff --git a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm index cf37239838..ed4d328897 100644 --- a/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm +++ b/iphone/Maps/Classes/MapDownloader/DataSources/MWMMapDownloaderDefaultDataSource.mm @@ -196,21 +196,6 @@ using namespace storage; return (status == NodeStatus::OnDisk || status == NodeStatus::OnDiskOutOfDate || nodeAttrs.m_localMwmCounter != 0); } -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (editingStyle == UITableViewCellEditingStyleDelete) - { - [Statistics logEvent:kStatDownloaderMapAction - withParameters:@{ - kStatAction : kStatDelete, - kStatIsAuto : kStatNo, - kStatFrom : kStatDownloader, - kStatScenario : kStatDelete - }]; - [MWMStorage deleteNode:[self countryIdForIndexPath:indexPath]]; - } -} - #pragma mark - MWMMapDownloaderDataSource - (TCountryId)parentCountryId diff --git a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm index 9eacc17519..7ae757181b 100644 --- a/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm +++ b/iphone/Maps/Classes/MapDownloader/MWMBaseMapDownloaderViewController.mm @@ -486,7 +486,7 @@ using namespace storage; kStatFrom : kStatDownloader, kStatScenario : kStatDelete }]; - [MWMStorage deleteNode:countryId]; + [MWMStorage deleteNode:countryId alertController:self.alertController]; } - (void)cancelNode:(storage::TCountryId const &)countryId diff --git a/iphone/Maps/Classes/Storage/MWMStorage.h b/iphone/Maps/Classes/Storage/MWMStorage.h index 9ad8707977..f77c569569 100644 --- a/iphone/Maps/Classes/Storage/MWMStorage.h +++ b/iphone/Maps/Classes/Storage/MWMStorage.h @@ -7,7 +7,7 @@ + (void)downloadNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess; + (void)retryDownloadNode:(storage::TCountryId const &)countryId; + (void)updateNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController; -+ (void)deleteNode:(storage::TCountryId const &)countryId; ++ (void)deleteNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController; + (void)cancelDownloadNode:(storage::TCountryId const &)countryId; @end diff --git a/iphone/Maps/Classes/Storage/MWMStorage.mm b/iphone/Maps/Classes/Storage/MWMStorage.mm index 1f95f71eb7..b3f45a83e1 100644 --- a/iphone/Maps/Classes/Storage/MWMStorage.mm +++ b/iphone/Maps/Classes/Storage/MWMStorage.mm @@ -30,9 +30,20 @@ }]; } -+ (void)deleteNode:(storage::TCountryId const &)countryId ++ (void)deleteNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController { - GetFramework().Storage().DeleteNode(countryId); + auto & f = GetFramework(); + if (f.HasUnsavedEdits(countryId)) + { + [alertController presentUnsavedEditsAlertWithOkBlock:^ + { + f.Storage().DeleteNode(countryId); + }]; + } + else + { + f.Storage().DeleteNode(countryId); + } } + (void)cancelDownloadNode:(storage::TCountryId const &)countryId