[ios] Fixed crash while deleting bookmark.

This commit is contained in:
VladiMihaylenko 2017-05-11 16:55:28 +03:00 committed by r.kuznetsov
parent 0eff2d316d
commit 8c0557d8f1
4 changed files with 53 additions and 9 deletions

View file

@ -9,6 +9,10 @@
#define TEXTFIELD_TAG 999
extern NSString * const kBookmarkCategoryDeletedNotification =
@"BookmarkCategoryDeletedNotification";
@implementation BookmarksRootVC
- (id)init
@ -235,7 +239,7 @@
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[Statistics logEvent:kStatEventName(kStatPlacePage, kStatRemove)];
[[NSNotificationCenter defaultCenter] postNotificationName:BOOKMARK_CATEGORY_DELETED_NOTIFICATION object:@(indexPath.row)];
[[NSNotificationCenter defaultCenter] postNotificationName:kBookmarkCategoryDeletedNotification object:@(indexPath.row)];
Framework & f = GetFramework();
f.DeleteBmCategory(indexPath.row);
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

View file

@ -27,6 +27,7 @@
#define EMPTY_SECTION -666
extern NSString * const kBookmarksChangedNotification = @"BookmarksChangedNotification";
extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotification";
@interface BookmarksVC() <MFMailComposeViewControllerDelegate, MWMLocationObserver>
{
@ -295,9 +296,9 @@ extern NSString * const kBookmarksChangedNotification = @"BookmarksChangedNotifi
}
else
{
BookmarkAndCategory bookmarkAndCategory{static_cast<size_t>(indexPath.row), m_categoryIndex};
NSValue * value = [NSValue valueWithBytes:&bookmarkAndCategory objCType:@encode(BookmarkAndCategory)];
[[NSNotificationCenter defaultCenter] postNotificationName:BOOKMARK_DELETED_NOTIFICATION object:value];
auto bac = BookmarkAndCategory(static_cast<size_t>(indexPath.row), m_categoryIndex);
NSValue * value = [NSValue valueWithBytes:&bac objCType:@encode(BookmarkAndCategory)];
[[NSNotificationCenter defaultCenter] postNotificationName:kBookmarkDeletedNotification object:value];
BookmarkCategory::Guard guard(*cat);
guard.m_controller.DeleteUserMark(indexPath.row);
[NSNotificationCenter.defaultCenter postNotificationName:kBookmarksChangedNotification

View file

@ -1,8 +1,3 @@
static NSString * const BOOKMARK_CATEGORY_DELETED_NOTIFICATION =
@"BookmarkCategoryDeletedNotification";
static NSString * const BOOKMARK_DELETED_NOTIFICATION = @"BookmarkDeletedNotification";
static NSString * const kMapsmeErrorDomain = @"com.mapsme.error";
static NSTimeInterval const kDefaultAnimationDuration = .2;

View file

@ -26,6 +26,9 @@
#include "platform/measurement_utils.hpp"
extern NSString * const kBookmarkDeletedNotification;
extern NSString * const kBookmarkCategoryDeletedNotification;
namespace
{
void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
@ -83,6 +86,15 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
}
[MWMLocationManager addObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleBookmarkDeleting:)
name:kBookmarkDeletedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleBookmarkCategoryDeleting:)
name:kBookmarkCategoryDeletedNotification
object:nil];
[self setupSpeedAndDistance];
[self.layout showWithData:self.data];
@ -97,6 +109,38 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName)
self.data = nil;
[MWMLocationManager removeObserver:self];
[MWMFrameworkListener removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)handleBookmarkDeleting:(NSNotification *)notification
{
NSAssert(self.data && self.layout, @"It must be openned place page!");
if (!self.data.isBookmark)
return;
auto value = static_cast<NSValue *>(notification.object);
auto deletedBac = BookmarkAndCategory();
[value getValue:&deletedBac];
NSAssert(deletedBac.IsValid(), @"Place page must have valid bookmark and category.");
auto bac = self.data.bac;
if (bac.m_bookmarkIndex != deletedBac.m_bookmarkIndex || bac.m_categoryIndex != deletedBac.m_categoryIndex)
return;
[self shouldClose];
}
- (void)handleBookmarkCategoryDeleting:(NSNotification *)notification
{
NSAssert(self.data && self.layout, @"It must be openned place page!");
if (!self.data.isBookmark)
return;
auto deletedIndex = static_cast<NSNumber *>(notification.object).integerValue;
auto index = self.data.bac.m_categoryIndex;
if (index != deletedIndex)
return;
[self shouldClose];
}
#pragma mark - MWMPlacePageLayoutDataSource