[MAPSME-6942] [ios] Added bookmark deletion observation.

This commit is contained in:
Ilya Grechuhin 2018-02-26 15:20:05 +03:00 committed by Aleksandr Zatsepin
parent c93eacfd17
commit 988ad879a7
11 changed files with 28 additions and 44 deletions

View file

@ -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() <MFMailComposeViewControllerDelegate, MWMLocationObserver>
{
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;

View file

@ -5,8 +5,7 @@ enum BMCSection {
case notifications
}
protocol BMCModel {
}
protocol BMCModel {}
enum BMCPermission: BMCModel {
case signup

View file

@ -174,4 +174,8 @@ extension BMCDefaultViewModel: MWMBookmarksObserver {
func onBookmarksLoadFinished() {
loadData()
}
func onBookmarkDeleted(_: MWMMarkID) {
loadData()
}
}

View file

@ -215,7 +215,6 @@ BOOL gIsFirstMyPositionMode = YES;
#pragma mark - ViewController lifecycle
- (void)dealloc { [NSNotificationCenter.defaultCenter removeObserver:self]; }
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)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;

View file

@ -554,11 +554,6 @@ using namespace osm_auth_ios;
return YES;
}
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (BOOL)initStatistics:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

View file

@ -21,6 +21,8 @@
+ (void)setAllCategoriesVisible:(BOOL)isVisible;
+ (void)deleteCategory:(MWMMarkGroupID)groupId;
+ (void)deleteBookmark:(MWMMarkID)bookmarkId;
+ (NSURL *)beginShareCategory:(MWMMarkGroupID)groupId;
+ (void)endShareCategory:(MWMMarkGroupID)groupId;

View file

@ -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);

View file

@ -6,5 +6,6 @@
- (void)onBookmarksLoadFinished;
- (void)onBookmarksFileLoadSuccess;
- (void)onBookmarksCategoryDeleted:(MWMMarkGroupID)groupId;
- (void)onBookmarkDeleted:(MWMMarkID)bookmarkId;
@end

View file

@ -82,7 +82,6 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
return self;
}
- (void)dealloc { [NSNotificationCenter.defaultCenter removeObserver:self]; }
- (void)viewDidLoad
{
[super viewDidLoad];

View file

@ -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));

View file

@ -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<NSValue *>(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;