From 988ad879a7829972f84bcfc42d9edca1e1a52045 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Mon, 26 Feb 2018 15:20:05 +0300 Subject: [PATCH] [MAPSME-6942] [ios] Added bookmark deletion observation. --- iphone/Maps/Bookmarks/BookmarksVC.mm | 12 ++------- .../Maps/Bookmarks/Categories/BMCModels.swift | 3 +-- .../BMCViewModel/BMCDefaultViewModel.swift | 4 +++ iphone/Maps/Classes/MapViewController.mm | 4 --- iphone/Maps/Classes/MapsAppDelegate.mm | 5 ---- .../Maps/Core/Bookmarks/MWMBookmarksManager.h | 2 ++ .../Core/Bookmarks/MWMBookmarksManager.mm | 9 +++++++ .../Core/Bookmarks/MWMBookmarksObserver.h | 1 + .../BottomMenu/MWMBottomMenuViewController.mm | 1 - iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 4 +-- .../Maps/UI/PlacePage/MWMPlacePageManager.mm | 27 +++++-------------- 11 files changed, 28 insertions(+), 44 deletions(-) diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index ffb630dbf4..fe40a7022c 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -2,6 +2,7 @@ #import "CircleView.h" #import "ColorPickerView.h" #import "MWMBookmarkNameCell.h" +#import "MWMBookmarksManager.h" #import "MWMLocationHelpers.h" #import "MWMLocationObserver.h" #import "MWMMailViewController.h" @@ -19,9 +20,6 @@ #define EMPTY_SECTION -666 -extern NSString * const kBookmarksChangedNotification = @"BookmarksChangedNotification"; -extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotification"; - @interface BookmarksVC() { int m_trackSection; @@ -312,13 +310,7 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica else { df::MarkID const bmId = [self getBookmarkIdByRow:indexPath.row]; - NSValue * value = [NSValue valueWithBytes:&bmId objCType:@encode(df::MarkID*)]; - [NSNotificationCenter.defaultCenter postNotificationName:kBookmarkDeletedNotification - object:value]; - bmManager.GetEditSession().DeleteBookmark(bmId); - [NSNotificationCenter.defaultCenter postNotificationName:kBookmarksChangedNotification - object:nil - userInfo:nil]; + [MWMBookmarksManager deleteBookmark:bmId]; } } size_t previousNumberOfSections = m_numberOfSections; diff --git a/iphone/Maps/Bookmarks/Categories/BMCModels.swift b/iphone/Maps/Bookmarks/Categories/BMCModels.swift index 0f36479ffd..2b54333abd 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCModels.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCModels.swift @@ -5,8 +5,7 @@ enum BMCSection { case notifications } -protocol BMCModel { -} +protocol BMCModel {} enum BMCPermission: BMCModel { case signup diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index d1ca90eb2d..5bec5065a2 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -174,4 +174,8 @@ extension BMCDefaultViewModel: MWMBookmarksObserver { func onBookmarksLoadFinished() { loadData() } + + func onBookmarkDeleted(_: MWMMarkID) { + loadData() + } } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 32bfabb7d5..bf019c4e96 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -215,7 +215,6 @@ BOOL gIsFirstMyPositionMode = YES; #pragma mark - ViewController lifecycle -- (void)dealloc { [NSNotificationCenter.defaultCenter removeObserver:self]; } - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { @@ -236,9 +235,6 @@ BOOL gIsFirstMyPositionMode = YES; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [NSNotificationCenter.defaultCenter removeObserver:self - name:UIDeviceOrientationDidChangeNotification - object:nil]; if ([MWMNavigationDashboardManager manager].state == MWMNavigationDashboardStateHidden) self.controlsManager.menuState = self.controlsManager.menuRestoreState; diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 187a29929c..82f05ec318 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -554,11 +554,6 @@ using namespace osm_auth_ios; return YES; } -- (void)dealloc -{ - [NSNotificationCenter.defaultCenter removeObserver:self]; -} - - (BOOL)initStatistics:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h index 87acd63b4d..9063f7fc40 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h @@ -21,6 +21,8 @@ + (void)setAllCategoriesVisible:(BOOL)isVisible; + (void)deleteCategory:(MWMMarkGroupID)groupId; ++ (void)deleteBookmark:(MWMMarkID)bookmarkId; + + (NSURL *)beginShareCategory:(MWMMarkGroupID)groupId; + (void)endShareCategory:(MWMMarkGroupID)groupId; diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm index 1593dec724..796aacd42e 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm @@ -173,6 +173,15 @@ using TLoopBlock = void (^)(Observer observer); }]; } ++ (void)deleteBookmark:(MWMMarkID)bookmarkId +{ + GetFramework().GetBookmarkManager().GetEditSession().DeleteBookmark(bookmarkId); + [[self manager] loopObservers:^(Observer observer) { + if ([observer respondsToSelector:@selector(onBookmarkDeleted:)]) + [observer onBookmarkDeleted:bookmarkId]; + }]; +} + + (NSURL *)beginShareCategory:(MWMMarkGroupID)groupId { auto const sharingResult = GetFramework().GetBookmarkManager().BeginSharing(groupId); diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksObserver.h b/iphone/Maps/Core/Bookmarks/MWMBookmarksObserver.h index 0c908dab02..8a8040de99 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksObserver.h +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksObserver.h @@ -6,5 +6,6 @@ - (void)onBookmarksLoadFinished; - (void)onBookmarksFileLoadSuccess; - (void)onBookmarksCategoryDeleted:(MWMMarkGroupID)groupId; +- (void)onBookmarkDeleted:(MWMMarkID)bookmarkId; @end diff --git a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm index ae1dd74da1..fd190274e4 100644 --- a/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/UI/BottomMenu/MWMBottomMenuViewController.mm @@ -82,7 +82,6 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { return self; } -- (void)dealloc { [NSNotificationCenter.defaultCenter removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index e635f0ad6f..7bfbd78bca 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -2,6 +2,7 @@ #import "AppInfo.h" #import "LocaleTranslator.h" #import "MWMBannerHelpers.h" +#import "MWMBookmarksManager.h" #import "MWMNetworkPolicy.h" #import "MWMUGCViewModel.h" #import "SwiftBridge.h" @@ -447,8 +448,7 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; if (bookmark) { f.ResetBookmarkInfo(*bookmark, m_info); - auto const categoryId = bookmark->GetGroupId(); - bmManager.GetEditSession().DeleteBookmark(bookmarkId); + [MWMBookmarksManager deleteBookmark:bookmarkId]; } m_sections.erase(remove(m_sections.begin(), m_sections.end(), Sections::Bookmark)); diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index bb4a46163e..f44defa293 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -2,7 +2,7 @@ #import "CLLocation+Mercator.h" #import "MWMAPIBar.h" #import "MWMActivityViewController.h" -#import "MWMBookmarksObserver.h" +#import "MWMBookmarksManager.h" #import "MWMFrameworkListener.h" #import "MWMFrameworkObservers.h" #import "MWMLocationHelpers.h" @@ -24,8 +24,6 @@ #include "geometry/distance_on_sphere.hpp" -extern NSString * const kBookmarkDeletedNotification; - namespace { void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) @@ -94,10 +92,7 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) } [MWMLocationManager addObserver:self]; - [NSNotificationCenter.defaultCenter addObserver:self - selector:@selector(handleBookmarkDeleting:) - name:kBookmarkDeletedNotification - object:nil]; + [MWMBookmarksManager addObserver:self]; [self setupSpeedAndDistance]; @@ -111,31 +106,23 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) { [self.layout close]; self.data = nil; + [MWMBookmarksManager removeObserver:self]; [MWMLocationManager removeObserver:self]; [MWMFrameworkListener removeObserver:self]; - [NSNotificationCenter.defaultCenter removeObserver:self]; } -- (void)handleBookmarkDeleting:(NSNotification *)notification +#pragma mark - MWMBookmarksObserver + +- (void)onBookmarkDeleted:(MWMMarkID)bookmarkId { auto data = self.data; NSAssert(data && self.layout, @"It must be openned place page!"); - if (!data.isBookmark) - return; - - auto value = static_cast(notification.object); - df::MarkID deletedBookmarkId = df::kInvalidMarkId; - [value getValue:&deletedBookmarkId]; - if (data.bookmarkId != deletedBookmarkId) + if (!data.isBookmark || data.bookmarkId != bookmarkId) return; [self closePlacePage]; } -- (void)handleBookmarkCategoryDeleting:(NSNotification *)notification {} - -#pragma mark - MWMBookmarksObserver - - (void)onBookmarksCategoryDeleted:(MWMMarkGroupID)groupId { auto data = self.data;