diff --git a/iphone/Maps/Bookmarks/BookmarksSection.h b/iphone/Maps/Bookmarks/BookmarksSection.h index fdfa08c679..89a6cd5c54 100644 --- a/iphone/Maps/Bookmarks/BookmarksSection.h +++ b/iphone/Maps/Bookmarks/BookmarksSection.h @@ -16,7 +16,7 @@ @interface BookmarksSection : NSObject -@property (nullable, nonatomic) NSNumber * blockIndex; +@property(nullable, nonatomic) NSNumber *blockIndex; - (instancetype)initWithDelegate:(id)delegate; - (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id)delegate; diff --git a/iphone/Maps/Bookmarks/BookmarksSection.mm b/iphone/Maps/Bookmarks/BookmarksSection.mm index 7f1a37f9f2..048ea39b8e 100644 --- a/iphone/Maps/Bookmarks/BookmarksSection.mm +++ b/iphone/Maps/Bookmarks/BookmarksSection.mm @@ -8,66 +8,59 @@ #include "geometry/distance_on_sphere.hpp" -namespace -{ +namespace { CGFloat const kPinDiameter = 22.0f; } // namespace -@interface BookmarksSection() +@interface BookmarksSection () -@property (weak, nonatomic) id delegate; +@property(weak, nonatomic) id delegate; @end @implementation BookmarksSection -- (instancetype)initWithDelegate: (id)delegate -{ +- (instancetype)initWithDelegate:(id)delegate { return [self initWithBlockIndex:nil delegate:delegate]; } -- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id)delegate -{ +- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id)delegate { self = [super init]; - if (self) - { + if (self) { _blockIndex = blockIndex; _delegate = delegate; } return self; } -- (NSInteger)numberOfRows -{ +- (NSInteger)numberOfRows { return [self.delegate numberOfBookmarksInSection:self]; } -- (NSString *)title -{ +- (NSString *)title { return [self.delegate titleOfBookmarksSection:self]; } -- (BOOL)canEdit -{ +- (BOOL)canEdit { return [self.delegate canEditBookmarksSection:self]; } -- (void)fillCell: (UITableViewCell *)cell withBookmarkDetails: (Bookmark const *)bookmark andLocation:(CLLocation *)location -{ +- (void)fillCell:(UITableViewCell *)cell + withBookmarkDetails:(Bookmark const *)bookmark + andLocation:(CLLocation *)location { std::vector details; - - if (location) - { + + if (location) { m2::PointD const pos = bookmark->GetPivot(); double const meters = ms::DistanceOnEarth(location.coordinate.latitude, location.coordinate.longitude, MercatorBounds::YToLat(pos.y), MercatorBounds::XToLon(pos.x)); details.push_back(location_helpers::formattedDistance(meters).UTF8String); } - - auto const & types = bookmark->GetData().m_featureTypes; + + auto const &types = bookmark->GetData().m_featureTypes; if (!types.empty()) details.push_back(kml::GetLocalizedFeatureType(types)); - + auto const detailText = strings::JoinStrings(details, " • "); if (!detailText.empty()) cell.detailTextLabel.text = @(detailText.c_str()); @@ -75,43 +68,39 @@ CGFloat const kPinDiameter = 22.0f; cell.detailTextLabel.text = nil; } -- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row -{ - UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCBookmarkItemCell"]; - if (!cell) - { +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)row { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BookmarksVCBookmarkItemCell"]; + if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"BookmarksVCBookmarkItemCell"]; } CHECK(cell, ("Invalid bookmark cell.")); - + kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row]; - auto const & bm = GetFramework().GetBookmarkManager(); - Bookmark const * bookmark = bm.GetBookmark(bmId); + auto const &bm = GetFramework().GetBookmarkManager(); + Bookmark const *bookmark = bm.GetBookmark(bmId); cell.textLabel.text = @(bookmark->GetPreferredName().c_str()); cell.imageView.image = [CircleView createCircleImageWith:kPinDiameter andColor:[ColorPickerView getUIColor:bookmark->GetColor()] andImageName:@(DebugPrint(bookmark->GetData().m_icon).c_str())]; - - CLLocation * lastLocation = [MWMLocationManager lastLocation]; - + + CLLocation *lastLocation = [MWMLocationManager lastLocation]; + [self fillCell:cell withBookmarkDetails:bookmark andLocation:lastLocation]; return cell; } -- (void)updateCell: (UITableViewCell *)cell forRow:(NSInteger)row withNewLocation: (location::GpsInfo const &)info -{ +- (void)updateCell:(UITableViewCell *)cell forRow:(NSInteger)row withNewLocation:(location::GpsInfo const &)info { kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row]; - auto const & bm = GetFramework().GetBookmarkManager(); - Bookmark const * bookmark = bm.GetBookmark(bmId); + auto const &bm = GetFramework().GetBookmarkManager(); + Bookmark const *bookmark = bm.GetBookmark(bmId); if (!bookmark) return; - CLLocation * location = [[CLLocation alloc] initWithLatitude:info.m_latitude longitude:info.m_longitude]; + CLLocation *location = [[CLLocation alloc] initWithLatitude:info.m_latitude longitude:info.m_longitude]; [self fillCell:cell withBookmarkDetails:bookmark andLocation:location]; } -- (BOOL)didSelectRow: (NSInteger)row -{ +- (BOOL)didSelectRow:(NSInteger)row { kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row]; [Statistics logEvent:kStatEventName(kStatBookmarks, kStatShowOnMap)]; // Same as "Close". @@ -120,8 +109,7 @@ CGFloat const kPinDiameter = 22.0f; return YES; } -- (BOOL)deleteRow: (NSInteger)row -{ +- (BOOL)deleteRow:(NSInteger)row { kml::MarkId const bmId = [self.delegate bookmarkSection:self getBookmarkIdByRow:row]; [[MWMBookmarksManager sharedManager] deleteBookmark:bmId]; return [self.delegate bookmarkSection:self onDeleteBookmarkInRow:row]; diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index b9e8e7f86c..bee1472eb6 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -1,11 +1,11 @@ #import "BookmarksVC.h" #import "BookmarksSection.h" #import "MWMBookmarksManager.h" +#import "MWMCategoryInfoCell.h" #import "MWMCommon.h" #import "MWMKeyboard.h" #import "MWMLocationObserver.h" #import "MWMSearchNoResults.h" -#import "MWMCategoryInfoCell.h" #import "SwiftBridge.h" #import "TracksSection.h" @@ -24,19 +24,18 @@ using namespace std; -@interface BookmarksVC() -{ - NSMutableArray> * m_sectionsCollection; +@interface BookmarksVC () { + NSMutableArray> *m_sectionsCollection; BookmarkManager::SortedBlocksCollection m_sortedBlocks; search::BookmarksSearchParams::Results m_searchResults; } @@ -46,16 +45,16 @@ using namespace std; @property(nonatomic) BOOL infoExpanded; -@property(weak, nonatomic) IBOutlet UIView * statusBarBackground; -@property(weak, nonatomic) IBOutlet UISearchBar * searchBar; -@property(weak, nonatomic) IBOutlet UIView * noResultsContainer; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * noResultsBottom; -@property(nonatomic) MWMSearchNoResults * noResultsView; +@property(weak, nonatomic) IBOutlet UIView *statusBarBackground; +@property(weak, nonatomic) IBOutlet UISearchBar *searchBar; +@property(weak, nonatomic) IBOutlet UIView *noResultsContainer; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *noResultsBottom; +@property(nonatomic) MWMSearchNoResults *noResultsView; -@property(nonatomic) UIActivityIndicatorView * spinner; -@property(nonatomic) UIImageView * searchIcon; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * hideSearchBar; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * showSearchBar; +@property(nonatomic) UIActivityIndicatorView *spinner; +@property(nonatomic) UIImageView *searchIcon; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *hideSearchBar; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *showSearchBar; @property(weak, nonatomic) IBOutlet UITableView * tableView; @@ -63,9 +62,9 @@ using namespace std; @property(weak, nonatomic) IBOutlet UIToolbar * downloadedCategoryToolbar; @property(weak, nonatomic) IBOutlet UIBarButtonItem * viewOnMapItem; -@property(nonatomic) UIActivityIndicatorView * sortSpinner; -@property(weak, nonatomic) IBOutlet UIBarButtonItem * sortItem; -@property(weak, nonatomic) IBOutlet UIBarButtonItem * sortSpinnerItem; +@property(nonatomic) UIActivityIndicatorView *sortSpinner; +@property(weak, nonatomic) IBOutlet UIBarButtonItem *sortItem; +@property(weak, nonatomic) IBOutlet UIBarButtonItem *sortSpinnerItem; @property(weak, nonatomic) IBOutlet UIBarButtonItem * moreItem; @@ -85,62 +84,51 @@ using namespace std; return self; } -- (BOOL)isSearchMode -{ +- (BOOL)isSearchMode { return !m_searchResults.empty(); } -- (BOOL)isSortMode -{ +- (BOOL)isSortMode { return ![self isSearchMode] && !m_sortedBlocks.empty(); } -- (void)calculateSections -{ +- (void)calculateSections { [m_sectionsCollection removeAllObjects]; - - if ([self isSearchMode]) - { + + if ([self isSearchMode]) { [m_sectionsCollection addObject:[[BookmarksSection alloc] initWithDelegate:self]]; return; } - - if ([self isSortMode]) - { + + if ([self isSortMode]) { NSInteger blockIndex = 0; - for (auto const & block : m_sortedBlocks) - { + for (auto const &block : m_sortedBlocks) { if (!block.m_markIds.empty()) [m_sectionsCollection addObject:[[BookmarksSection alloc] initWithBlockIndex:@(blockIndex++) delegate:self]]; } return; } - - auto const & bm = GetFramework().GetBookmarkManager(); + + auto const &bm = GetFramework().GetBookmarkManager(); if (bm.IsCategoryFromCatalog(m_categoryId)) - { [m_sectionsCollection addObject:[[InfoSection alloc] initWithDelegate:self]]; - } - + if (bm.GetTrackIds(m_categoryId).size() > 0) - { [m_sectionsCollection addObject:[[TracksSection alloc] initWithDelegate:self]]; - } - + if (bm.GetUserMarkIds(m_categoryId).size() > 0) [m_sectionsCollection addObject:[[BookmarksSection alloc] initWithDelegate:self]]; } -- (void)viewDidLoad -{ +- (void)viewDidLoad { [super viewDidLoad]; - - UIColor * searchBarColor = [UIColor primary]; + + UIColor *searchBarColor = [UIColor primary]; self.searchBar.delegate = self; self.statusBarBackground.backgroundColor = self.searchBar.barTintColor = searchBarColor; self.searchBar.backgroundImage = [UIImage imageWithColor:searchBarColor]; self.searchBar.placeholder = L(@"search"); - + auto const & bm = GetFramework().GetBookmarkManager(); auto const searchAllowed = !bm.IsCategoryFromCatalog(m_categoryId); @@ -148,7 +136,7 @@ using namespace std; self.hideSearchBar.priority = searchAllowed ? UILayoutPriorityDefaultLow : UILayoutPriorityRequired; [self.noResultsView setTranslatesAutoresizingMaskIntoConstraints:NO]; - + self.tableView.estimatedRowHeight = 44; [self.tableView registerWithCellClass:MWMCategoryInfoCell.class]; self.tableView.separatorColor = [UIColor blackDividers]; @@ -169,16 +157,15 @@ using namespace std; self.myCategoryToolbar.barTintColor = [UIColor white]; self.downloadedCategoryToolbar.barTintColor = [UIColor white]; - + [self showSpinner:NO]; } -- (void)viewWillAppear:(BOOL)animated -{ +- (void)viewWillAppear:(BOOL)animated { [MWMLocationManager addObserver:self]; - auto const & bm = GetFramework().GetBookmarkManager(); - + auto const &bm = GetFramework().GetBookmarkManager(); + // Display Edit button only if table is not empty if ([[MWMBookmarksManager sharedManager] isCategoryEditable:m_categoryId]) { @@ -188,15 +175,12 @@ using namespace std; { self.navigationItem.rightBarButtonItem = self.editButtonItem; self.sortItem.enabled = YES; - + BookmarkManager::SortingType type; - if (bm.GetLastSortingType(m_categoryId, type)) - { + if (bm.GetLastSortingType(m_categoryId, type)) { auto const availableSortingTypes = [self getAvailableSortingTypes]; - for (auto availableType : availableSortingTypes) - { - if (availableType == type) - { + for (auto availableType : availableSortingTypes) { + if (availableType == type) { [self sort:type]; break; } @@ -219,16 +203,14 @@ using namespace std; self.title = @(bm.GetCategoryName(m_categoryId).c_str()); } -- (void)viewWillDisappear:(BOOL)animated -{ +- (void)viewWillDisappear:(BOOL)animated { [MWMLocationManager removeObserver:self]; // Save possibly edited set name [super viewWillDisappear:animated]; } -- (void)viewDidAppear:(BOOL)animated -{ +- (void)viewDidAppear:(BOOL)animated { // Disable all notifications in BM on appearance of this view. // It allows to significantly improve performance in case of bookmarks // modification. All notifications will be sent on controller's disappearance. @@ -237,28 +219,26 @@ using namespace std; [super viewDidAppear:animated]; } -- (void)viewDidDisappear:(BOOL)animated -{ +- (void)viewDidDisappear:(BOOL)animated { // Allow to send all notifications in BM. [[MWMBookmarksManager sharedManager] setNotificationsEnabled: YES]; [super viewDidDisappear:animated]; } -- (IBAction)onMore:(UIBarButtonItem *)sender -{ +- (IBAction)onMore:(UIBarButtonItem *)sender { auto actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - + [actionSheet addAction:[UIAlertAction actionWithTitle:L(@"sharing_options") style:UIAlertActionStyleDefault - handler:^(UIAlertAction * _Nonnull action) - { - [self shareCategory]; - [Statistics logEvent:kStatBookmarksListItemSettings withParameters:@{kStatOption : kStatSharingOptions}]; - }]]; - + handler:^(UIAlertAction *_Nonnull action) { + [self shareCategory]; + [Statistics logEvent:kStatBookmarksListItemSettings + withParameters:@{kStatOption: kStatSharingOptions}]; + }]]; + [actionSheet addAction:[UIAlertAction actionWithTitle:L(@"search_show_on_map") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) @@ -305,13 +285,11 @@ using namespace std; [Statistics logEvent:kStatBookmarksListItemSettings withParameters:@{kStatOption : kStatMore}]; } -- (IBAction)onViewOnMap:(UIBarButtonItem *)sender -{ +- (IBAction)onViewOnMap:(UIBarButtonItem *)sender { [self viewOnMap]; } -- (void)openCategorySettings -{ +- (void)openCategorySettings { auto storyboard = [UIStoryboard instance:MWMStoryboardCategorySettings]; auto settingsController = (CategorySettingsViewController *)[storyboard instantiateInitialViewController]; settingsController.delegate = self; @@ -319,14 +297,12 @@ using namespace std; [self.navigationController pushViewController:settingsController animated:YES]; } -- (void)exportFile -{ +- (void)exportFile { [[MWMBookmarksManager sharedManager] addObserver:self]; [[MWMBookmarksManager sharedManager] shareCategory:m_categoryId]; } -- (void)shareCategory -{ +- (void)shareCategory { auto storyboard = [UIStoryboard instance:MWMStoryboardSharing]; auto shareController = (BookmarksSharingViewController *)[storyboard instantiateInitialViewController]; shareController.delegate = self; @@ -334,174 +310,157 @@ using namespace std; [self.navigationController pushViewController:shareController animated:YES]; } -- (void)viewOnMap -{ +- (void)viewOnMap { [self.navigationController popToRootViewControllerAnimated:YES]; GetFramework().ShowBookmarkCategory(m_categoryId); } -- (IBAction)onSort:(UIBarButtonItem *)sender -{ +- (IBAction)onSort:(UIBarButtonItem *)sender { auto actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - + auto const sortingTypes = [self getAvailableSortingTypes]; - - for (auto type : sortingTypes) - { + + for (auto type : sortingTypes) { [actionSheet addAction:[UIAlertAction actionWithTitle:[BookmarksVC getLocalizedSortingType:type] style:UIAlertActionStyleDefault - handler:^(UIAlertAction * _Nonnull action) - { - auto & bm = GetFramework().GetBookmarkManager(); - bm.SetLastSortingType(self->m_categoryId, type); - [self sort:type]; - }]]; + handler:^(UIAlertAction *_Nonnull action) { + auto &bm = GetFramework().GetBookmarkManager(); + bm.SetLastSortingType(self->m_categoryId, type); + [self sort:type]; + }]]; } - + [actionSheet addAction:[UIAlertAction actionWithTitle:L(@"sort_default") style:UIAlertActionStyleDefault - handler:^(UIAlertAction * _Nonnull action) - { - [self sortDefault]; - }]]; - - [actionSheet addAction:[UIAlertAction actionWithTitle:L(@"cancel") - style:UIAlertActionStyleCancel - handler:nil]]; - + handler:^(UIAlertAction *_Nonnull action) { + [self sortDefault]; + }]]; + + [actionSheet addAction:[UIAlertAction actionWithTitle:L(@"cancel") style:UIAlertActionStyleCancel handler:nil]]; + actionSheet.popoverPresentationController.barButtonItem = self.sortItem; - [self presentViewController:actionSheet animated:YES completion:^{ - actionSheet.popoverPresentationController.passthroughViews = nil; - }]; + [self presentViewController:actionSheet + animated:YES + completion:^{ + actionSheet.popoverPresentationController.passthroughViews = nil; + }]; } -+ (NSString *)getLocalizedSortingType:(BookmarkManager::SortingType)type -{ - switch (type) - { - case BookmarkManager::SortingType::ByTime: return L(@"sort_date"); - case BookmarkManager::SortingType::ByDistance: return L(@"sort_distance"); - case BookmarkManager::SortingType::ByType: return L(@"sort_type"); ++ (NSString *)getLocalizedSortingType:(BookmarkManager::SortingType)type { + switch (type) { + case BookmarkManager::SortingType::ByTime: + return L(@"sort_date"); + case BookmarkManager::SortingType::ByDistance: + return L(@"sort_distance"); + case BookmarkManager::SortingType::ByType: + return L(@"sort_type"); } UNREACHABLE(); } -- (std::vector)getAvailableSortingTypes -{ - CLLocation * lastLocation = [MWMLocationManager lastLocation]; +- (std::vector)getAvailableSortingTypes { + CLLocation *lastLocation = [MWMLocationManager lastLocation]; bool const hasMyPosition = lastLocation != nil; - auto const & bm = GetFramework().GetBookmarkManager(); + auto const &bm = GetFramework().GetBookmarkManager(); auto const sortingTypes = bm.GetAvailableSortingTypes(m_categoryId, hasMyPosition); return sortingTypes; } -- (void)sortDefault -{ - auto & bm = GetFramework().GetBookmarkManager(); +- (void)sortDefault { + auto &bm = GetFramework().GetBookmarkManager(); bm.ResetLastSortingType(self->m_categoryId); self->m_sortedBlocks.clear(); [self calculateSections]; [self.tableView reloadData]; } -- (void)sort:(BookmarkManager::SortingType)type -{ +- (void)sort:(BookmarkManager::SortingType)type { bool hasMyPosition = false; m2::PointD myPosition = m2::PointD::Zero(); - - if (type == BookmarkManager::SortingType::ByDistance) - { - CLLocation * lastLocation = [MWMLocationManager lastLocation]; + + if (type == BookmarkManager::SortingType::ByDistance) { + CLLocation *lastLocation = [MWMLocationManager lastLocation]; if (!lastLocation) return; hasMyPosition = true; myPosition = MercatorBounds::FromLatLon(lastLocation.coordinate.latitude, lastLocation.coordinate.longitude); } - + auto const sortId = ++self.lastSortId; __weak auto weakSelf = self; - - auto & bm = GetFramework().GetBookmarkManager(); + + auto &bm = GetFramework().GetBookmarkManager(); BookmarkManager::SortParams sortParams; sortParams.m_groupId = m_categoryId; sortParams.m_sortingType = type; sortParams.m_hasMyPosition = hasMyPosition; sortParams.m_myPosition = myPosition; - sortParams.m_onResults = [weakSelf, sortId](BookmarkManager::SortedBlocksCollection && sortedBlocks, + sortParams.m_onResults = [weakSelf, sortId](BookmarkManager::SortedBlocksCollection &&sortedBlocks, BookmarkManager::SortParams::Status status) { __strong auto self = weakSelf; if (!self || sortId != self.lastSortId) return; - + [self showSortSpinner:NO]; self.sortItem.enabled = YES; - - if (status == BookmarkManager::SortParams::Status::Completed) - { + + if (status == BookmarkManager::SortParams::Status::Completed) { m_sortedBlocks = std::move(sortedBlocks); [self calculateSections]; [self.tableView reloadData]; } }; - + [self showSortSpinner:YES]; self.sortItem.enabled = NO; - + bm.GetSortedBookmarks(sortParams); } -- (BookmarkManager::SortedBlock &)sortedBlockForIndex:(NSNumber *)blockIndex -{ +- (BookmarkManager::SortedBlock &)sortedBlockForIndex:(NSNumber *)blockIndex { CHECK(blockIndex != nil, ()); NSInteger index = blockIndex.integerValue; CHECK_LESS(index, m_sortedBlocks.size(), ()); return m_sortedBlocks[index]; } -- (void)deleteSortedBlockForIndex:(NSNumber *)blockIndex -{ +- (void)deleteSortedBlockForIndex:(NSNumber *)blockIndex { CHECK(blockIndex != nil, ()); NSInteger index = blockIndex.integerValue; CHECK_LESS(index, m_sortedBlocks.size(), ()); m_sortedBlocks.erase(m_sortedBlocks.begin() + index); } -- (UIActivityIndicatorView *)sortSpinner -{ - if (!_sortSpinner) - { +- (UIActivityIndicatorView *)sortSpinner { + if (!_sortSpinner) { _sortSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; _sortSpinner.hidesWhenStopped = YES; } return _sortSpinner; } -- (void)showSortSpinner:(BOOL)show -{ +- (void)showSortSpinner:(BOOL)show { if (show) [self.sortSpinner startAnimating]; else [self.sortSpinner stopAnimating]; } -- (void)cancelSearch -{ +- (void)cancelSearch { GetFramework().CancelSearch(search::Mode::Bookmarks); m_searchResults.clear(); - + [self showNoResultsView:NO]; [self showSpinner:NO]; - + [self calculateSections]; [self.tableView reloadData]; } -- (MWMSearchNoResults *)noResultsView -{ - if (!_noResultsView) - { +- (MWMSearchNoResults *)noResultsView { + if (!_noResultsView) { _noResultsView = [MWMSearchNoResults viewWithImage:[UIImage imageNamed:@"img_search_not_found"] title:L(@"search_not_found") text:L(@"search_not_found_query")]; @@ -509,34 +468,28 @@ using namespace std; return _noResultsView; } -- (void)showNoResultsView:(BOOL)show -{ - if (!show) - { +- (void)showNoResultsView:(BOOL)show { + if (!show) { self.tableView.hidden = NO; self.noResultsContainer.hidden = YES; [self.noResultsView removeFromSuperview]; - } - else - { + } else { self.tableView.hidden = YES; self.noResultsContainer.hidden = NO; [self.noResultsContainer addSubview:self.noResultsView]; self.noResultsView.translatesAutoresizingMaskIntoConstraints = NO; [NSLayoutConstraint activateConstraints:@[ - [self.noResultsView.topAnchor constraintEqualToAnchor:self.noResultsContainer.topAnchor], - [self.noResultsView.leftAnchor constraintEqualToAnchor:self.noResultsContainer.leftAnchor], - [self.noResultsView.bottomAnchor constraintEqualToAnchor:self.noResultsContainer.bottomAnchor], - [self.noResultsView.rightAnchor constraintEqualToAnchor:self.noResultsContainer.rightAnchor], - ]]; + [self.noResultsView.topAnchor constraintEqualToAnchor:self.noResultsContainer.topAnchor], + [self.noResultsView.leftAnchor constraintEqualToAnchor:self.noResultsContainer.leftAnchor], + [self.noResultsView.bottomAnchor constraintEqualToAnchor:self.noResultsContainer.bottomAnchor], + [self.noResultsView.rightAnchor constraintEqualToAnchor:self.noResultsContainer.rightAnchor], + ]]; [self onKeyboardAnimation]; } } -- (UIActivityIndicatorView *)spinner -{ - if (!_spinner) - { +- (UIActivityIndicatorView *)spinner { + if (!_spinner) { _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; _spinner.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; _spinner.hidesWhenStopped = YES; @@ -544,209 +497,183 @@ using namespace std; return _spinner; } -- (UIImageView *)searchIcon -{ - if (!_searchIcon) - { +- (UIImageView *)searchIcon { + if (!_searchIcon) { _searchIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_search"]]; _searchIcon.mwm_coloring = MWMImageColoringBlack; } return _searchIcon; } -- (void)showSpinner:(BOOL)show -{ - UITextField * textField = [self.searchBar valueForKey:@"searchField"]; - if (!show) - { +- (void)showSpinner:(BOOL)show { + UITextField *textField = [self.searchBar valueForKey:@"searchField"]; + if (!show) { textField.leftView = self.searchIcon; [self.spinner stopAnimating]; - } - else - { + } else { self.spinner.bounds = textField.leftView.bounds; textField.leftView = self.spinner; [self.spinner startAnimating]; } } -- (NSString *)categoryFileName -{ +- (NSString *)categoryFileName { return @(GetFramework().GetBookmarkManager().GetCategoryFileName(m_categoryId).c_str()); } -- (UIStatusBarStyle)preferredStatusBarStyle -{ +- (UIStatusBarStyle)preferredStatusBarStyle { setStatusBarBackgroundColor(UIColor.clearColor); return UIStatusBarStyleLightContent; } -- (void)setEditing:(BOOL)editing animated:(BOOL)animated -{ +- (void)setEditing:(BOOL)editing animated:(BOOL)animated { [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:animated]; } #pragma mark - UISearchBarDelegate -- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar -{ +- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { [self.searchBar setShowsCancelButton:YES animated:YES]; [self.navigationController setNavigationBarHidden:YES animated:YES]; self.tableView.contentInset = self.tableView.scrollIndicatorInsets = {}; - + // Allow to send all notifications in BM. - [[MWMBookmarksManager sharedManager] setNotificationsEnabled: YES]; - + [[MWMBookmarksManager sharedManager] setNotificationsEnabled:YES]; + return YES; } -- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar -{ +- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { [self.searchBar setShowsCancelButton:NO animated:YES]; [self.navigationController setNavigationBarHidden:NO animated:YES]; self.tableView.contentInset = self.tableView.scrollIndicatorInsets = {}; - + // Disable all notifications in BM. - [[MWMBookmarksManager sharedManager] setNotificationsEnabled: NO]; - + [[MWMBookmarksManager sharedManager] setNotificationsEnabled:NO]; + return YES; } -- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar -{ +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { self.searchBar.text = @""; [self.searchBar resignFirstResponder]; [self cancelSearch]; } -- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText -{ - if (!searchText || searchText.length == 0) - { +- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { + if (!searchText || searchText.length == 0) { [self cancelSearch]; return; } - + search::BookmarksSearchParams searchParams; searchParams.m_query = searchText.UTF8String; searchParams.m_groupId = m_categoryId; - + auto const searchId = ++self.lastSearchId; __weak auto weakSelf = self; searchParams.m_onStarted = [] {}; - searchParams.m_onResults = [weakSelf, searchId](search::BookmarksSearchParams::Results const & results, + searchParams.m_onResults = [weakSelf, searchId](search::BookmarksSearchParams::Results const &results, search::BookmarksSearchParams::Status status) { __strong auto self = weakSelf; if (!self || searchId != self.lastSearchId) return; - - auto const & bm = GetFramework().GetBookmarkManager(); + + auto const &bm = GetFramework().GetBookmarkManager(); auto filteredResults = results; bm.FilterInvalidBookmarks(filteredResults); self->m_searchResults = filteredResults; - - if (status == search::BookmarksSearchParams::Status::Cancelled) - { + + if (status == search::BookmarksSearchParams::Status::Cancelled) { [self showSpinner:NO]; - } - else if (status == search::BookmarksSearchParams::Status::Completed) - { + } else if (status == search::BookmarksSearchParams::Status::Completed) { [self showNoResultsView:results.empty()]; [self showSpinner:NO]; } - + [self calculateSections]; [self.tableView reloadData]; }; - + [self showSpinner:YES]; - + GetFramework().SearchInBookmarks(searchParams); } #pragma mark - UITableViewDataSource -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [m_sectionsCollection count]; } -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [m_sectionsCollection[section] numberOfRows]; } -- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section -{ +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [m_sectionsCollection[section] title]; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - UITableViewCell * cell = [m_sectionsCollection[indexPath.section] tableView:tableView cellForRow:indexPath.row]; - +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [m_sectionsCollection[indexPath.section] tableView:tableView cellForRow:indexPath.row]; + cell.backgroundColor = [UIColor white]; cell.textLabel.textColor = [UIColor blackPrimaryText]; cell.detailTextLabel.textColor = [UIColor blackSecondaryText]; return cell; } -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Remove cell selection [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; - + auto const close = [m_sectionsCollection[indexPath.section] didSelectRow:indexPath.row]; - + [self.searchBar resignFirstResponder]; - + if (close) [self.navigationController popToRootViewControllerAnimated:NO]; } -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return [m_sectionsCollection[indexPath.section] canEdit]; } -- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath { self.editing = YES; } -- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { self.editing = NO; } -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ +- (void)tableView:(UITableView *)tableView + commitEditingStyle:(UITableViewCellEditingStyle)editingStyle + forRowAtIndexPath:(NSIndexPath *)indexPath { if (![m_sectionsCollection[indexPath.section] canEdit]) return; - + BOOL emptySection = NO; if (editingStyle == UITableViewCellEditingStyleDelete) emptySection = [m_sectionsCollection[indexPath.section] deleteRow:indexPath.row]; - + [self calculateSections]; - + // We can delete the row with animation, if the sections stay the same. if (!emptySection) [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; else [self.tableView reloadData]; - - auto const & bm = GetFramework().GetBookmarkManager(); - if (bm.GetUserMarkIds(m_categoryId).size() + bm.GetTrackIds(m_categoryId).size() == 0) - { + + auto const &bm = GetFramework().GetBookmarkManager(); + if (bm.GetUserMarkIds(m_categoryId).size() + bm.GetTrackIds(m_categoryId).size() == 0) { self.navigationItem.rightBarButtonItem = nil; [self setEditing:NO animated:YES]; } } -- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section -{ +- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { auto header = (UITableViewHeaderFooterView *)view; header.textLabel.textColor = [UIColor blackSecondaryText]; header.textLabel.font = [UIFont medium14]; @@ -754,200 +681,175 @@ using namespace std; #pragma mark - BookmarksSectionDelegate -- (NSInteger)numberOfBookmarksInSection:(BookmarksSection *)bookmarkSection -{ - if ([self isSearchMode]) - { +- (NSInteger)numberOfBookmarksInSection:(BookmarksSection *)bookmarkSection { + if ([self isSearchMode]) { return m_searchResults.size(); } - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; return sortedBlock.m_markIds.size(); } - auto const & bm = GetFramework().GetBookmarkManager(); + auto const &bm = GetFramework().GetBookmarkManager(); return bm.GetUserMarkIds(m_categoryId).size(); } -- (NSString *)titleOfBookmarksSection:(BookmarksSection *)bookmarkSection -{ +- (NSString *)titleOfBookmarksSection:(BookmarksSection *)bookmarkSection { if ([self isSearchMode]) return nil; - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; return @(sortedBlock.m_blockName.c_str()); } - + return L(@"bookmarks"); } -- (BOOL)canEditBookmarksSection:(BookmarksSection *)bookmarkSection -{ +- (BOOL)canEditBookmarksSection:(BookmarksSection *)bookmarkSection { return [[MWMBookmarksManager sharedManager] isCategoryEditable:m_categoryId]; } -- (kml::MarkId)bookmarkSection:(BookmarksSection *)bookmarkSection getBookmarkIdByRow:(NSInteger)row -{ - if ([self isSearchMode]) - { +- (kml::MarkId)bookmarkSection:(BookmarksSection *)bookmarkSection getBookmarkIdByRow:(NSInteger)row { + if ([self isSearchMode]) { CHECK_LESS(row, m_searchResults.size(), ()); return m_searchResults[row]; } - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; CHECK_LESS(row, sortedBlock.m_markIds.size(), ()); return sortedBlock.m_markIds[row]; } - - auto const & bm = GetFramework().GetBookmarkManager(); - auto const & bookmarkIds = bm.GetUserMarkIds(m_categoryId); + + auto const &bm = GetFramework().GetBookmarkManager(); + auto const &bookmarkIds = bm.GetUserMarkIds(m_categoryId); CHECK_LESS(row, bookmarkIds.size(), ()); auto it = bookmarkIds.begin(); advance(it, row); return *it; } -- (BOOL)bookmarkSection:(BookmarksSection *)bookmarkSection onDeleteBookmarkInRow:(NSInteger)row -{ - if ([self isSearchMode]) - { +- (BOOL)bookmarkSection:(BookmarksSection *)bookmarkSection onDeleteBookmarkInRow:(NSInteger)row { + if ([self isSearchMode]) { CHECK_LESS(row, m_searchResults.size(), ()); m_searchResults.erase(m_searchResults.begin() + row); m_sortedBlocks.clear(); return m_searchResults.empty(); } - - if ([self isSortMode]) - { - auto & sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; - auto & marks = sortedBlock.m_markIds; + + if ([self isSortMode]) { + auto &sortedBlock = [self sortedBlockForIndex:bookmarkSection.blockIndex]; + auto &marks = sortedBlock.m_markIds; CHECK_LESS(row, marks.size(), ()); - + marks.erase(marks.begin() + row); - if (marks.empty()) - { + if (marks.empty()) { [self deleteSortedBlockForIndex:bookmarkSection.blockIndex]; return YES; } return NO; } - - auto const & bm = GetFramework().GetBookmarkManager(); - auto const & bookmarkIds = bm.GetUserMarkIds(m_categoryId); + + auto const &bm = GetFramework().GetBookmarkManager(); + auto const &bookmarkIds = bm.GetUserMarkIds(m_categoryId); return bookmarkIds.empty(); } #pragma mark - TracksSectionDelegate -- (NSInteger)numberOfTracksInSection:(TracksSection *)tracksSection -{ +- (NSInteger)numberOfTracksInSection:(TracksSection *)tracksSection { CHECK(![self isSearchMode], ()); - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; return sortedBlock.m_trackIds.size(); } - - auto const & bm = GetFramework().GetBookmarkManager(); + + auto const &bm = GetFramework().GetBookmarkManager(); return bm.GetTrackIds(m_categoryId).size(); } -- (NSString *)titleOfTracksSection:(TracksSection *)tracksSection -{ +- (NSString *)titleOfTracksSection:(TracksSection *)tracksSection { CHECK(![self isSearchMode], ()); - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; return @(sortedBlock.m_blockName.c_str()); } - + return L(@"tracks_title"); } -- (BOOL)canEditTracksSection:(TracksSection *)tracksSection -{ +- (BOOL)canEditTracksSection:(TracksSection *)tracksSection { CHECK(![self isSearchMode], ()); - + if ([self isSortMode]) return false; - + return [[MWMBookmarksManager sharedManager] isCategoryEditable:m_categoryId]; } -- (kml::TrackId)tracksSection:(TracksSection *)tracksSection getTrackIdByRow:(NSInteger)row -{ +- (kml::TrackId)tracksSection:(TracksSection *)tracksSection getTrackIdByRow:(NSInteger)row { CHECK(![self isSearchMode], ()); - - if ([self isSortMode]) - { - auto const & sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; + + if ([self isSortMode]) { + auto const &sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; CHECK_LESS(row, sortedBlock.m_trackIds.size(), ()); return sortedBlock.m_trackIds[row]; } - - auto const & bm = GetFramework().GetBookmarkManager(); - auto const & trackIds = bm.GetTrackIds(m_categoryId); + + auto const &bm = GetFramework().GetBookmarkManager(); + auto const &trackIds = bm.GetTrackIds(m_categoryId); CHECK_LESS(row, trackIds.size(), ()); auto it = trackIds.begin(); advance(it, row); return *it; } -- (BOOL)tracksSection:(TracksSection *)tracksSection onDeleteTrackInRow:(NSInteger)row -{ +- (BOOL)tracksSection:(TracksSection *)tracksSection onDeleteTrackInRow:(NSInteger)row { CHECK(![self isSearchMode], ()); - - if ([self isSortMode]) - { - auto & sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; + + if ([self isSortMode]) { + auto &sortedBlock = [self sortedBlockForIndex:tracksSection.blockIndex]; CHECK_LESS(row, sortedBlock.m_trackIds.size(), ()); - - auto & tracks = sortedBlock.m_trackIds; + + auto &tracks = sortedBlock.m_trackIds; tracks.erase(tracks.begin() + row); - if (tracks.empty()) - { + if (tracks.empty()) { [self deleteSortedBlockForIndex:tracksSection.blockIndex]; return YES; } return NO; } - - auto const & bm = GetFramework().GetBookmarkManager(); - auto const & trackIds = bm.GetTrackIds(m_categoryId); + + auto const &bm = GetFramework().GetBookmarkManager(); + auto const &trackIds = bm.GetTrackIds(m_categoryId); return trackIds.empty(); } #pragma mark - InfoSectionDelegate -- (UITableViewCell *)infoCellForTableView: (UITableView *)tableView -{ - UITableViewCell * cell = [tableView dequeueReusableCellWithCellClass:MWMCategoryInfoCell.class]; +- (UITableViewCell *)infoCellForTableView:(UITableView *)tableView { + UITableViewCell *cell = [tableView dequeueReusableCellWithCellClass:MWMCategoryInfoCell.class]; CHECK(cell, ("Invalid category info cell.")); - - auto & f = GetFramework(); - auto & bm = f.GetBookmarkManager(); + + auto &f = GetFramework(); + auto &bm = f.GetBookmarkManager(); bool const categoryExists = bm.HasBmCategory(m_categoryId); CHECK(categoryExists, ("Nonexistent category")); - + auto infoCell = (MWMCategoryInfoCell *)cell; - auto const & categoryData = bm.GetCategoryData(m_categoryId); + auto const &categoryData = bm.GetCategoryData(m_categoryId); [infoCell updateWithCategoryData:categoryData delegate:self]; infoCell.expanded = self.infoExpanded; - + return cell; } #pragma mark - MWMCategoryInfoCellDelegate -- (void)categoryInfoCellDidPressMore:(MWMCategoryInfoCell *)cell -{ +- (void)categoryInfoCellDidPressMore:(MWMCategoryInfoCell *)cell { [self.tableView beginUpdates]; cell.expanded = YES; [self.tableView endUpdates]; @@ -956,34 +858,27 @@ using namespace std; #pragma mark - MWMLocationObserver -- (void)onLocationUpdate:(location::GpsInfo const &)info -{ - [self.tableView.visibleCells enumerateObjectsUsingBlock:^(UITableViewCell * cell, NSUInteger idx, BOOL * stop) - { - auto const indexPath = [self.tableView indexPathForCell:cell]; - auto const & section = self->m_sectionsCollection[indexPath.section]; - if ([section respondsToSelector:@selector(updateCell:forRow:withNewLocation:)]) - [section updateCell:cell forRow:indexPath.row withNewLocation:info]; - }]; +- (void)onLocationUpdate:(location::GpsInfo const &)info { + [self.tableView.visibleCells enumerateObjectsUsingBlock:^(UITableViewCell *cell, NSUInteger idx, BOOL *stop) { + auto const indexPath = [self.tableView indexPathForCell:cell]; + auto const §ion = self->m_sectionsCollection[indexPath.section]; + if ([section respondsToSelector:@selector(updateCell:forRow:withNewLocation:)]) + [section updateCell:cell forRow:indexPath.row withNewLocation:info]; + }]; } #pragma mark - MWMBookmarksObserver -- (void)onBookmarksCategoryFilePrepared:(MWMBookmarksShareStatus)status -{ - switch (status) - { - case MWMBookmarksShareStatusSuccess: - { - auto shareController = - [MWMActivityViewController shareControllerForURL:[MWMBookmarksManager sharedManager].shareCategoryURL - message:L(@"share_bookmarks_email_body") - completionHandler:^(UIActivityType _Nullable activityType, - BOOL completed, - NSArray * _Nullable returnedItems, - NSError * _Nullable activityError) { - [[MWMBookmarksManager sharedManager] finishShareCategory]; - }]; +- (void)onBookmarksCategoryFilePrepared:(MWMBookmarksShareStatus)status { + switch (status) { + case MWMBookmarksShareStatusSuccess: { + auto shareController = [MWMActivityViewController + shareControllerForURL:[MWMBookmarksManager sharedManager].shareCategoryURL + message:L(@"share_bookmarks_email_body") + completionHandler:^(UIActivityType _Nullable activityType, BOOL completed, NSArray *_Nullable returnedItems, + NSError *_Nullable activityError) { + [[MWMBookmarksManager sharedManager] finishShareCategory]; + }]; [shareController presentInParentViewController:self anchorView:self.view]; break; } @@ -1002,20 +897,19 @@ using namespace std; #pragma mark - BookmarksSharingViewControllerDelegate -- (void)didShareCategory -{ +- (void)didShareCategory { [self.tableView reloadData]; } #pragma mark - CategorySettingsViewControllerDelegate -- (void)categorySettingsController:(CategorySettingsViewController *)viewController didDelete:(MWMMarkGroupID)categoryId -{ +- (void)categorySettingsController:(CategorySettingsViewController *)viewController + didDelete:(MWMMarkGroupID)categoryId { [self.delegate bookmarksVCdidDeleteCategory:self]; } -- (void)categorySettingsController:(CategorySettingsViewController *)viewController didEndEditing:(MWMMarkGroupID)categoryId -{ +- (void)categorySettingsController:(CategorySettingsViewController *)viewController + didEndEditing:(MWMMarkGroupID)categoryId { [self.navigationController popViewControllerAnimated:YES]; [self.delegate bookmarksVCdidUpdateCategory:self]; [self.tableView reloadData]; @@ -1023,13 +917,12 @@ using namespace std; #pragma mark - MWMKeyboard -- (void)onKeyboardAnimation -{ +- (void)onKeyboardAnimation { self.noResultsBottom.constant = 0; CGFloat const keyboardHeight = [MWMKeyboard keyboardHeight]; if (keyboardHeight >= self.noResultsContainer.height) return; - + self.noResultsBottom.constant = -keyboardHeight; } @end diff --git a/iphone/Maps/Bookmarks/InfoSection.h b/iphone/Maps/Bookmarks/InfoSection.h index ec0e1fb209..7d38537225 100644 --- a/iphone/Maps/Bookmarks/InfoSection.h +++ b/iphone/Maps/Bookmarks/InfoSection.h @@ -11,4 +11,3 @@ - (instancetype)initWithDelegate:(id)delegate; @end - diff --git a/iphone/Maps/Bookmarks/InfoSection.mm b/iphone/Maps/Bookmarks/InfoSection.mm index 5fadb7dcd0..e066bf68f5 100644 --- a/iphone/Maps/Bookmarks/InfoSection.mm +++ b/iphone/Maps/Bookmarks/InfoSection.mm @@ -1,50 +1,42 @@ #import "InfoSection.h" -@interface InfoSection() +@interface InfoSection () -@property (weak, nonatomic) id delegate; +@property(weak, nonatomic) id delegate; @end @implementation InfoSection -- (instancetype)initWithDelegate: (id)delegate -{ +- (instancetype)initWithDelegate:(id)delegate { self = [super init]; - if (self) - { + if (self) { _delegate = delegate; } return self; } -- (NSInteger)numberOfRows -{ +- (NSInteger)numberOfRows { return 1; } -- (NSString *)title -{ +- (NSString *)title { return L(@"placepage_place_description"); } -- (BOOL)canEdit -{ +- (BOOL)canEdit { return NO; } -- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row -{ +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)row { return [self.delegate infoCellForTableView:tableView]; } -- (BOOL)didSelectRow: (NSInteger)row -{ +- (BOOL)didSelectRow:(NSInteger)row { return NO; } -- (BOOL)deleteRow: (NSInteger)row -{ +- (BOOL)deleteRow:(NSInteger)row { return YES; } diff --git a/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h index c09cffeb72..ba4531a11d 100644 --- a/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h +++ b/iphone/Maps/Bookmarks/MWMCategoryInfoCell.h @@ -1,5 +1,5 @@ -#import "MWMTableViewCell.h" #import "InfoSection.h" +#import "MWMTableViewCell.h" namespace kml { diff --git a/iphone/Maps/Bookmarks/TableSectionDataSource.h b/iphone/Maps/Bookmarks/TableSectionDataSource.h index 679179fba4..9a0aac8f28 100644 --- a/iphone/Maps/Bookmarks/TableSectionDataSource.h +++ b/iphone/Maps/Bookmarks/TableSectionDataSource.h @@ -6,16 +6,13 @@ - (NSString *)title; - (BOOL)canEdit; -- (UITableViewCell *)tableView:(UITableView *)tableView - cellForRow:(NSInteger)row; +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)row; - (BOOL)didSelectRow:(NSInteger)row; - (BOOL)deleteRow:(NSInteger)row; @optional --(void)updateCell:(UITableViewCell *)cell - forRow:(NSInteger)row - withNewLocation:(location::GpsInfo const &)gpsInfo; +- (void)updateCell:(UITableViewCell *)cell forRow:(NSInteger)row withNewLocation:(location::GpsInfo const &)gpsInfo; @end diff --git a/iphone/Maps/Bookmarks/TracksSection.h b/iphone/Maps/Bookmarks/TracksSection.h index d00fffe31e..2ee6a63285 100644 --- a/iphone/Maps/Bookmarks/TracksSection.h +++ b/iphone/Maps/Bookmarks/TracksSection.h @@ -16,11 +16,10 @@ @interface TracksSection : NSObject -@property (nullable, nonatomic) NSNumber * blockIndex; +@property(nullable, nonatomic) NSNumber *blockIndex; - (instancetype)initWithDelegate:(id)delegate; -- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex - delegate:(id)delegate; +- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id)delegate; @end diff --git a/iphone/Maps/Bookmarks/TracksSection.mm b/iphone/Maps/Bookmarks/TracksSection.mm index a32b8119a6..2d16218c5b 100644 --- a/iphone/Maps/Bookmarks/TracksSection.mm +++ b/iphone/Maps/Bookmarks/TracksSection.mm @@ -2,61 +2,53 @@ #import "CircleView.h" #include "Framework.h" -namespace -{ - CGFloat const kPinDiameter = 22.0f; +namespace { +CGFloat const kPinDiameter = 22.0f; } // namespace -@interface TracksSection() +@interface TracksSection () -@property (weak, nonatomic) id delegate; +@property(weak, nonatomic) id delegate; @end @implementation TracksSection -- (instancetype)initWithDelegate:(id)delegate -{ +- (instancetype)initWithDelegate:(id)delegate { return [self initWithBlockIndex:nil delegate:delegate]; } -- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate: (id)delegate -{ +- (instancetype)initWithBlockIndex:(NSNumber *)blockIndex delegate:(id)delegate { self = [super init]; - if (self) - { + if (self) { _blockIndex = blockIndex; _delegate = delegate; } return self; } -- (NSInteger)numberOfRows -{ +- (NSInteger)numberOfRows { return [self.delegate numberOfTracksInSection:self]; } -- (NSString *)title -{ +- (NSString *)title { return [self.delegate titleOfTracksSection:self]; } -- (BOOL)canEdit -{ +- (BOOL)canEdit { return [self.delegate canEditTracksSection:self]; } -- (UITableViewCell *)tableView: (UITableView *)tableView cellForRow: (NSInteger)row -{ - UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"]; +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRow:(NSInteger)row { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TrackCell"]; if (!cell) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TrackCell"]; CHECK(cell, ("Invalid track cell.")); - - auto const & bm = GetFramework().GetBookmarkManager(); - + + auto const &bm = GetFramework().GetBookmarkManager(); + kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row]; - Track const * track = bm.GetTrack(trackId); + Track const *track = bm.GetTrack(trackId); cell.textLabel.text = @(track->GetName().c_str()); string dist; if (measurement_utils::FormatDistance(track->GetLengthMeters(), dist)) @@ -72,17 +64,15 @@ namespace return cell; } -- (BOOL)didSelectRow: (NSInteger)row -{ +- (BOOL)didSelectRow:(NSInteger)row { kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row]; GetFramework().ShowTrack(trackId); return YES; } -- (BOOL)deleteRow: (NSInteger)row -{ +- (BOOL)deleteRow:(NSInteger)row { kml::TrackId const trackId = [self.delegate tracksSection:self getTrackIdByRow:row]; - auto & bm = GetFramework().GetBookmarkManager(); + auto &bm = GetFramework().GetBookmarkManager(); bm.GetEditSession().DeleteTrack(trackId); return [self.delegate tracksSection:self onDeleteTrackInRow:row]; } diff --git a/iphone/Maps/Classes/CircleView.mm b/iphone/Maps/Classes/CircleView.mm index e6f6ea77a5..7b1fc44c9a 100644 --- a/iphone/Maps/Classes/CircleView.mm +++ b/iphone/Maps/Classes/CircleView.mm @@ -4,20 +4,18 @@ @interface CircleView() -@property (nonatomic) UIColor * circleColor; -@property (nonatomic) UIImage * image; +@property(nonatomic) UIColor *circleColor; +@property(nonatomic) UIImage *image; @end @implementation CircleView -- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color -{ +- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color { return [self initWithFrame:frame andColor:color andImageName:nil]; } -- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color andImageName:(NSString *)imageName -{ +- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color andImageName:(NSString *)imageName { self = [super initWithFrame:frame]; if (self) { @@ -29,53 +27,50 @@ return self; } -- (void)drawRect:(CGRect)rect -{ +- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextAddEllipseInRect(ctx, rect); CGContextSetFillColor(ctx, CGColorGetComponents(self.circleColor.CGColor)); CGContextFillPath(ctx); - + if (self.image) [self.image drawInRect:CGRectMake(3, 3, rect.size.width - 6, rect.size.height - 6)]; } -+ (UIView *)createViewWithCircleDiameter:(CGFloat)diameter andColor:(UIColor *)color andImageName:(NSString *)imageName -{ - UIView * circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, diameter, diameter)]; ++ (UIView *)createViewWithCircleDiameter:(CGFloat)diameter + andColor:(UIColor *)color + andImageName:(NSString *)imageName { + UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, diameter, diameter)]; circleView.backgroundColor = UIColor.clearColor; - CircleView * circle = [[self alloc] initWithFrame:CGRectMake(0.5, 0.5, diameter - 1, diameter - 1) andColor:color andImageName:imageName]; + CircleView *circle = [[self alloc] initWithFrame:CGRectMake(0.5, 0.5, diameter - 1, diameter - 1) + andColor:color + andImageName:imageName]; [circleView addSubview:circle]; return circleView; } -+ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color -{ - UIView * circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:nil]; ++ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color { + UIView *circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:nil]; return [self imageWithView:circle]; } -+ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color andImageName:(NSString *)imageName -{ - UIView * circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:imageName]; ++ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color andImageName:(NSString *)imageName { + UIView *circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:imageName]; return [self imageWithView:circle]; } -+ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color andSubview:(UIView *)view -{ - UIView * circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:nil]; ++ (UIImage *)createCircleImageWith:(CGFloat)diameter andColor:(UIColor *)color andSubview:(UIView *)view { + UIView *circle = [self createViewWithCircleDiameter:diameter andColor:color andImageName:nil]; [circle addSubview:view]; return [self imageWithView:circle]; } - -+ (UIImage *)imageWithView:(UIView *)view -{ ++ (UIImage *)imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; - UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); + UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); diff --git a/iphone/Maps/Classes/ColorPickerView.mm b/iphone/Maps/Classes/ColorPickerView.mm index 7186a76215..af2452d823 100644 --- a/iphone/Maps/Classes/ColorPickerView.mm +++ b/iphone/Maps/Classes/ColorPickerView.mm @@ -17,8 +17,7 @@ struct Tcolor float rgb[3]; }; -static Tcolor const g_color [] = -{ +static Tcolor const g_color[] = { {kml::PredefinedColor::Red, {229, 27, 35}}, {kml::PredefinedColor::Yellow, {255, 200, 0}}, {kml::PredefinedColor::Blue, {0, 110, 199}}, diff --git a/iphone/Maps/Common/MWMTypes.h b/iphone/Maps/Common/MWMTypes.h index cbc4629199..ab69fb656f 100644 --- a/iphone/Maps/Common/MWMTypes.h +++ b/iphone/Maps/Common/MWMTypes.h @@ -19,9 +19,9 @@ typedef NS_ENUM(NSUInteger, MWMTheme) { typedef uint64_t MWMMarkID; typedef uint64_t MWMTrackID; typedef uint64_t MWMMarkGroupID; -typedef NSArray * MWMMarkIDCollection; -typedef NSArray * MWMTrackIDCollection; -typedef NSArray * MWMGroupIDCollection; +typedef NSArray *MWMMarkIDCollection; +typedef NSArray *MWMTrackIDCollection; +typedef NSArray *MWMGroupIDCollection; typedef NS_ENUM(NSUInteger, MWMBookmarksShareStatus) { MWMBookmarksShareStatusSuccess,