From 02f8b2fe9d474eab0b940eaffb345609e53615d7 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 20 Feb 2016 23:42:59 +0100 Subject: [ios] Replaced UserMarks with new structures. --- iphone/Maps/Bookmarks/SelectSetVC.mm | 1 - .../MapViewControls/APIBar/MWMAPIBar.mm | 2 +- .../MapViewControls/MWMMapViewControlsManager.h | 3 +- .../MapViewControls/MWMMapViewControlsManager.mm | 9 +- .../MapViewControls/Search/MWMSearchManager.mm | 2 +- .../Maps/Classes/Editor/MWMEditorViewController.h | 8 +- .../Maps/Classes/Editor/MWMEditorViewController.mm | 167 ++++----- .../Maps/Classes/Framework/MWMFrameworkListener.h | 1 - .../Maps/Classes/Framework/MWMFrameworkListener.mm | 48 --- .../Maps/Classes/Framework/MWMFrameworkObservers.h | 6 - iphone/Maps/Classes/MWMBasePlacePageView.h | 1 - iphone/Maps/Classes/MWMBasePlacePageView.mm | 30 +- iphone/Maps/Classes/MWMPlacePage.mm | 2 - iphone/Maps/Classes/MWMPlacePageActionBar.mm | 77 ++--- .../Maps/Classes/MWMPlacePageDescriptionView.xib | 97 ------ iphone/Maps/Classes/MWMPlacePageEntity.h | 28 +- iphone/Maps/Classes/MWMPlacePageEntity.mm | 375 +++++++-------------- iphone/Maps/Classes/MWMPlacePageNavigationBar.mm | 2 +- iphone/Maps/Classes/MWMPlacePageTypeDescription.h | 16 - iphone/Maps/Classes/MWMPlacePageTypeDescription.mm | 73 ---- iphone/Maps/Classes/MWMPlacePageViewManager.h | 4 +- iphone/Maps/Classes/MWMPlacePageViewManager.mm | 115 ++----- iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm | 2 +- iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm | 2 +- iphone/Maps/Classes/MapViewController.h | 3 +- iphone/Maps/Classes/MapViewController.mm | 52 ++- iphone/Maps/Maps.xcodeproj/project.pbxproj | 14 - 27 files changed, 308 insertions(+), 832 deletions(-) delete mode 100644 iphone/Maps/Classes/MWMPlacePageDescriptionView.xib delete mode 100644 iphone/Maps/Classes/MWMPlacePageTypeDescription.h delete mode 100644 iphone/Maps/Classes/MWMPlacePageTypeDescription.mm diff --git a/iphone/Maps/Bookmarks/SelectSetVC.mm b/iphone/Maps/Bookmarks/SelectSetVC.mm index 0b1f12cfde..65064d9e4f 100644 --- a/iphone/Maps/Bookmarks/SelectSetVC.mm +++ b/iphone/Maps/Bookmarks/SelectSetVC.mm @@ -117,7 +117,6 @@ BookmarkCategory const * category = GetFramework().GetBookmarkManager().GetBmCategory(bac.first); entity.bookmarkCategory = @(category->GetName().c_str()); - [self.manager changeBookmarkCategory:bac]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm index 6d354f6c6a..4889a6a11d 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/APIBar/MWMAPIBar.mm @@ -54,7 +54,7 @@ static NSString * const kKeyPath = @"subviews"; { [[Statistics instance] logEvent:kStatEventName(kStatAPI, kStatBack)]; Framework & f = GetFramework(); - f.ActivateUserMark(nullptr, true); + f.DeactivateMapSelection(true); UserMarkControllerGuard guard(f.GetBookmarkManager(), UserMarkType::API_MARK); guard.m_controller.Clear(); self.isVisible = NO; diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.h b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.h index d4d89d4c08..438137d160 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.h +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.h @@ -35,8 +35,7 @@ @property (nonatomic, readonly) BOOL isDirectionViewShown; - (void)dismissPlacePage; -- (void)showPlacePage; -- (void)reloadPlacePage; +- (void)showPlacePage:(place_page::Info const &)info; #pragma mark - MWMNavigationDashboardManager diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index 6187ca26a0..53489beed0 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -153,17 +153,12 @@ extern NSString * const kAlohalyticsTapEventKey; [self.placePageManager hidePlacePage]; } -- (void)showPlacePage +- (void)showPlacePage:(place_page::Info const &)info { - [self.placePageManager showPlacePage]; + [self.placePageManager showPlacePage:info]; [self refreshHelperPanels:UIInterfaceOrientationIsLandscape(self.ownerController.interfaceOrientation)]; } -- (void)reloadPlacePage -{ - [self.placePageManager reloadPlacePage]; -} - - (void)apiBack { [self.ownerController.apiBar back]; diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm index dace846865..15abac4049 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm @@ -289,7 +289,7 @@ extern NSString * const kSearchStateKey = @"SearchStateKey"; textField.textInputMode.primaryLanguage.UTF8String : self.tableViewController.searchParams.m_inputLocale; f.SaveSearchQuery(make_pair(locale, textField.text.precomposedStringWithCompatibilityMapping.UTF8String)); - f.ActivateUserMark(nullptr, true); + f.DeactivateMapSelection(true); [self.searchTextField resignFirstResponder]; self.rootView.compact = YES; self.tableViewController.searchOnMap = YES; diff --git a/iphone/Maps/Classes/Editor/MWMEditorViewController.h b/iphone/Maps/Classes/Editor/MWMEditorViewController.h index e12939425f..92c2eccc85 100644 --- a/iphone/Maps/Classes/Editor/MWMEditorViewController.h +++ b/iphone/Maps/Classes/Editor/MWMEditorViewController.h @@ -1,11 +1,9 @@ -#import "MWMOpeningHoursEditorViewController.h" -#import "MWMPlacePageEntity.h" #import "MWMTableViewController.h" -@interface MWMEditorViewController : MWMTableViewController +struct FeatureID; -@property (nonatomic) MWMPlacePageEntity * entity; +@interface MWMEditorViewController : MWMTableViewController -- (void)setOpeningHours:(NSString *)openingHours; +- (void)setFeatureToEdit:(FeatureID const &)fid; @end diff --git a/iphone/Maps/Classes/Editor/MWMEditorViewController.mm b/iphone/Maps/Classes/Editor/MWMEditorViewController.mm index e7e39e5365..f1a86622f4 100644 --- a/iphone/Maps/Classes/Editor/MWMEditorViewController.mm +++ b/iphone/Maps/Classes/Editor/MWMEditorViewController.mm @@ -6,10 +6,12 @@ #import "MWMEditorTextTableViewCell.h" #import "MWMEditorViewController.h" #import "MWMOpeningHoursEditorViewController.h" +#import "MWMPlacePageEntity.h" #import "MWMPlacePageOpeningHoursCell.h" #import "MWMStreetEditorViewController.h" #import "Statistics.h" +#include "indexer/editable_map_object.hpp" #include "std/algorithm.hpp" namespace @@ -62,14 +64,12 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) } // namespace @interface MWMEditorViewController() @property (nonatomic) NSMutableDictionary * offscreenCells; -@property (weak, nonatomic) UITableViewCell * editCell; - -@property (nonatomic) BOOL needsReload; @end @@ -77,7 +77,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) { vector m_sections; map> m_cells; - MWMPlacePageCellTypeValueMap m_edited_cells; + osm::EditableMapObject m_mapObject; } - (void)viewDidLoad @@ -88,10 +88,16 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) [self configNavBar]; } +- (void)setFeatureToEdit:(FeatureID const &)fid +{ + if (!GetFramework().GetEditableMapObject(fid, m_mapObject)) + NSAssert(false, @"Incorrect featureID."); +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - [self reloadData]; + [self.tableView reloadData]; } #pragma mark - Configuration @@ -123,12 +129,17 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) - (void)onSave { - if (!m_edited_cells.empty()) + switch (GetFramework().SaveEditedMapObject(m_mapObject)) { - [[Statistics instance] logEvent:kStatEventName(kStatEdit, kStatSave)]; - osm_auth_ios::AuthorizationSetNeedCheck(YES); - self.entity.cuisines = self.cuisines; - [self.entity saveEditedCells:m_edited_cells]; + case osm::Editor::NothingWasChanged: + break; + case osm::Editor::SavedSuccessfully: + [[Statistics instance] logEvent:kStatEventName(kStatEdit, kStatSave)]; + osm_auth_ios::AuthorizationSetNeedCheck(YES); + break; + case osm::Editor::NoFreeSpaceError: + // TODO(Vlad): Show error dialog. + break; } [self onCancel]; } @@ -146,47 +157,46 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) return cell; } -#pragma mark - Data source - -- (NSString *)getCellValue:(MWMPlacePageCellType)cellType -{ - auto const it = m_edited_cells.find(cellType); - if (it != m_edited_cells.end()) - return @(it->second.c_str()); - return [self.entity getCellValue:cellType]; -} - -- (void)setCell:(MWMPlacePageCellType)cellType value:(NSString *)value +// TODO(Vlad): This code can be much better. +- (bool)hasField:(feature::Metadata::EType)field { - if ([value isEqualToString:[self getCellValue:cellType]]) - return; - self.needsReload = YES; - m_edited_cells[cellType] = value.UTF8String; + auto const & editable = m_mapObject.GetEditableFields(); + return editable.end() != find(editable.begin(), editable.end(), field); } - -#pragma mark - Table - -- (void)reloadData +// TODO(Vlad): This code can be much better. +- (bool)isEditable:(MWMPlacePageCellType)cellType { - if (self.needsReload) + switch (cellType) { - [self.tableView reloadData]; - self.needsReload = NO; + case MWMPlacePageCellTypePostcode: return [self hasField:feature::Metadata::FMD_POSTCODE]; + case MWMPlacePageCellTypePhoneNumber: return [self hasField:feature::Metadata::FMD_PHONE_NUMBER]; + case MWMPlacePageCellTypeWebsite: return [self hasField:feature::Metadata::FMD_WEBSITE]; + // TODO(Vlad): We should not have URL field in the UI. Website should always be used instead. + case MWMPlacePageCellTypeURL: return [self hasField:feature::Metadata::FMD_URL]; + case MWMPlacePageCellTypeEmail: return [self hasField:feature::Metadata::FMD_EMAIL]; + case MWMPlacePageCellTypeOpenHours: return [self hasField:feature::Metadata::FMD_OPEN_HOURS]; + case MWMPlacePageCellTypeWiFi: return [self hasField:feature::Metadata::FMD_INTERNET]; + case MWMPlacePageCellTypeCuisine: return [self hasField:feature::Metadata::FMD_CUISINE]; + // TODO(Vlad): return true when we allow coordinates editing. + case MWMPlacePageCellTypeCoordinate: return false; + case MWMPlacePageCellTypeName: return m_mapObject.IsNameEditable(); + case MWMPlacePageCellTypeStreet: return m_mapObject.IsAddressEditable(); + case MWMPlacePageCellTypeBuilding: return m_mapObject.IsAddressEditable(); + default: NSAssert(false, @"Invalid cell type %d", cellType); } + return false; } - (void)configTable { - NSAssert(self.entity, @"Entity must be set"); self.offscreenCells = [NSMutableDictionary dictionary]; m_sections.clear(); m_cells.clear(); - m_edited_cells.clear(); - for (auto cellsSection : gCellTypesSectionMap) + for (auto const & cellsSection : gCellTypesSectionMap) { for (auto cellType : cellsSection.first) { - if (![self.entity isCellEditable:cellType]) + if (![self isEditable:cellType]) continue; m_sections.emplace_back(cellsSection.second); m_cells[cellsSection.second].emplace_back(cellType); @@ -217,7 +227,6 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) - (void)fillCell:(UITableViewCell * _Nonnull)cell atIndexPath:(NSIndexPath * _Nonnull)indexPath { MWMPlacePageCellType const cellType = [self cellTypeForIndexPath:indexPath]; - NSString * entityValue = [self getCellValue:cellType]; switch (cellType) { case MWMPlacePageCellTypePhoneNumber: @@ -225,7 +234,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorTextTableViewCell * tCell = (MWMEditorTextTableViewCell *)cell; [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_phone_number"] - text:entityValue + text:@(m_mapObject.GetPhone().c_str()) placeholder:L(@"phone") keyboardType:UIKeyboardTypePhonePad]; break; @@ -235,7 +244,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorTextTableViewCell * tCell = (MWMEditorTextTableViewCell *)cell; [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_website"] - text:entityValue + text:@(m_mapObject.GetWebsite().c_str()) placeholder:L(@"website") keyboardType:UIKeyboardTypeURL]; break; @@ -245,7 +254,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorTextTableViewCell * tCell = (MWMEditorTextTableViewCell *)cell; [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_email"] - text:entityValue + text:@(m_mapObject.GetEmail().c_str()) placeholder:L(@"email") keyboardType:UIKeyboardTypeEmailAddress]; break; @@ -253,18 +262,18 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) case MWMPlacePageCellTypeOpenHours: { MWMPlacePageOpeningHoursCell * tCell = (MWMPlacePageOpeningHoursCell *)cell; - NSString * text = entityValue ? entityValue : L(@"add_opening_hours"); - [tCell configWithDelegate:self info:text]; + NSString * text = @(m_mapObject.GetOpeningHours().c_str()); + [tCell configWithDelegate:self info:(text.length ? text : L(@"add_opening_hours"))]; break; } case MWMPlacePageCellTypeWiFi: { MWMEditorSwitchTableViewCell * tCell = (MWMEditorSwitchTableViewCell *)cell; - BOOL const on = (entityValue != nil); + // TODO(Vlad, IgorTomko): Support all other possible Internet statuses. [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_wifi"] text:L(@"wifi") - on:on]; + on:m_mapObject.GetInternet() == osm::Internet::Wlan]; break; } case MWMPlacePageCellTypeName: @@ -272,7 +281,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorTextTableViewCell * tCell = (MWMEditorTextTableViewCell *)cell; [tCell configWithDelegate:self icon:nil - text:entityValue + text:@(m_mapObject.GetDefaultName().c_str()) placeholder:L(@"name") keyboardType:UIKeyboardTypeDefault]; break; @@ -282,7 +291,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorSelectTableViewCell * tCell = (MWMEditorSelectTableViewCell *)cell; [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_adress"] - text:entityValue + text:@(m_mapObject.GetStreet().c_str()) placeholder:L(@"add_street")]; break; } @@ -291,7 +300,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) MWMEditorTextTableViewCell * tCell = (MWMEditorTextTableViewCell *)cell; [tCell configWithDelegate:self icon:nil - text:entityValue + text:@(m_mapObject.GetHouseNumber().c_str()) placeholder:L(@"house") keyboardType:UIKeyboardTypeDefault]; break; @@ -299,10 +308,10 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) case MWMPlacePageCellTypeCuisine: { MWMEditorSelectTableViewCell * tCell = (MWMEditorSelectTableViewCell *)cell; - NSString * text = [entityValue capitalizedStringWithLocale:[NSLocale currentLocale]]; +// NSString * text = [entityValue capitalizedStringWithLocale:[NSLocale currentLocale]]; [tCell configWithDelegate:self icon:[UIImage imageNamed:@"ic_placepage_cuisine"] - text:text + text:@(m_mapObject.FormatCuisines().c_str()) placeholder:L(@"select_cuisine")]; break; } @@ -337,6 +346,8 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) { NSString * reuseIdentifier = [self cellIdentifierForIndexPath:indexPath]; UITableViewCell * cell = [self offscreenCellForIdentifier:reuseIdentifier]; + // TODO(Vlad, IGrechuhin): It's bad idea to fill cells here. + // heightForRowAtIndexPath is called way too often for the table. [self fillCell:cell atIndexPath:indexPath]; MWMPlacePageCellType const cellType = [self cellTypeForIndexPath:indexPath]; switch (cellType) @@ -395,7 +406,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) - (BOOL)isPlaceholder { - return [self getCellValue:MWMPlacePageCellTypeOpenHours] == nil; + return m_mapObject.GetOpeningHours().empty(); } - (BOOL)isEditor @@ -417,25 +428,22 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) - (void)cellBeginEditing:(UITableViewCell *)cell { - self.editCell = cell; } - (void)cell:(UITableViewCell *)cell changeText:(NSString *)changeText { NSIndexPath * indexPath = [self.tableView indexPathForCell:cell]; MWMPlacePageCellType const cellType = [self cellTypeForIndexPath:indexPath]; + string const val = changeText.UTF8String; switch (cellType) { - case MWMPlacePageCellTypeName: - case MWMPlacePageCellTypePhoneNumber: - case MWMPlacePageCellTypeWebsite: - case MWMPlacePageCellTypeEmail: - case MWMPlacePageCellTypeBuilding: - [self setCell:cellType value:changeText]; - break; - default: - NSAssert(false, @"Invalid field for changeText"); - break; + // TODO(Vlad): Support multilanguage names. + case MWMPlacePageCellTypeName: m_mapObject.SetName(val, StringUtf8Multilang::kDefaultCode); break; + case MWMPlacePageCellTypePhoneNumber: m_mapObject.SetPhone(val); break; + case MWMPlacePageCellTypeWebsite: m_mapObject.SetWebsite(val); break; + case MWMPlacePageCellTypeEmail: m_mapObject.SetEmail(val); break; + case MWMPlacePageCellTypeBuilding: m_mapObject.SetHouseNumber(val); break; + default: NSAssert(false, @"Invalid field for changeText"); } } @@ -446,12 +454,8 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) switch (cellType) { case MWMPlacePageCellTypeWiFi: - { - BOOL const on = ([self getCellValue:cellType] != nil); - if (changeSwitch != on) - [self setCell:cellType value:changeSwitch ? @"wlan" : @""]; + m_mapObject.SetInternet(changeSwitch ? osm::Internet::Wlan : osm::Internet::Unknown); break; - } default: NSAssert(false, @"Invalid field for changeSwitch"); break; @@ -480,43 +484,40 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) - (void)setOpeningHours:(NSString *)openingHours { - [self setCell:MWMPlacePageCellTypeOpenHours value:openingHours]; + m_mapObject.SetOpeningHours(openingHours.UTF8String); } #pragma mark - MWMCuisineEditorProtocol -@synthesize cuisines = _cuisines; -- (NSSet *)cuisines +- (vector)getSelectedCuisines { - if (_cuisines) - return _cuisines; - return self.entity.cuisines; + return m_mapObject.GetCuisines(); } -- (void)setCuisines:(NSSet *)cuisines +- (void)setSelectedCuisines:(vector const &)cuisines { - if ([self.cuisines isEqualToSet:cuisines]) - return; - _cuisines = cuisines; - self.needsReload = YES; - [self setCell:MWMPlacePageCellTypeCuisine value:[MWMPlacePageEntity makeMWMCuisineString:cuisines]]; + m_mapObject.SetCuisines(cuisines); } #pragma mark - MWMStreetEditorProtocol - (NSString *)getStreet { - return [self getCellValue:MWMPlacePageCellTypeStreet]; + return @(m_mapObject.GetStreet().c_str()); } - (void)setStreet:(NSString *)street { - [self setCell:MWMPlacePageCellTypeStreet value:street]; + m_mapObject.SetStreet(street.UTF8String); } - (NSArray *)getNearbyStreets { - return self.entity.nearbyStreets; + auto const & streets = m_mapObject.GetNearbyStreets(); + NSMutableArray * arr = [[NSMutableArray alloc] initWithCapacity:streets.size()]; + for (auto const & street : streets) + [arr addObject:@(street.c_str())]; + return arr; } #pragma mark - Segue @@ -526,7 +527,7 @@ NSString * reuseIdentifier(MWMPlacePageCellType cellType) if ([segue.identifier isEqualToString:kOpeningHoursEditorSegue]) { MWMOpeningHoursEditorViewController * dvc = segue.destinationViewController; - dvc.openingHours = [self getCellValue:MWMPlacePageCellTypeOpenHours]; + dvc.openingHours = @(m_mapObject.GetOpeningHours().c_str()); dvc.delegate = self; } else if ([segue.identifier isEqualToString:kCuisineEditorSegue]) diff --git a/iphone/Maps/Classes/Framework/MWMFrameworkListener.h b/iphone/Maps/Classes/Framework/MWMFrameworkListener.h index 1e03fa1673..18d5bbbd8c 100644 --- a/iphone/Maps/Classes/Framework/MWMFrameworkListener.h +++ b/iphone/Maps/Classes/Framework/MWMFrameworkListener.h @@ -7,7 +7,6 @@ + (void)removeObserver:(id)observer; @property (nonatomic, readonly) location::EMyPositionMode myPositionMode; -@property (nonatomic) UserMark const * userMark; - (instancetype)init __attribute__((unavailable("call +listener instead"))); - (instancetype)copy __attribute__((unavailable("call +listener instead"))); diff --git a/iphone/Maps/Classes/Framework/MWMFrameworkListener.mm b/iphone/Maps/Classes/Framework/MWMFrameworkListener.mm index 4f900d0593..7b119cce56 100644 --- a/iphone/Maps/Classes/Framework/MWMFrameworkListener.mm +++ b/iphone/Maps/Classes/Framework/MWMFrameworkListener.mm @@ -10,7 +10,6 @@ namespace using TObserver = id; using TRouteBuildingObserver = id; using TMyPositionObserver = id; -using TUsermarkObserver = id; using TStorageObserver = id; using TDrapeObserver = id; @@ -18,7 +17,6 @@ using TObservers = NSHashTable<__kindof TObserver>; Protocol * pRouteBuildingObserver = @protocol(MWMFrameworkRouteBuilderObserver); Protocol * pMyPositionObserver = @protocol(MWMFrameworkMyPositionObserver); -Protocol * pUserMarkObserver = @protocol(MWMFrameworkUserMarkObserver); Protocol * pStorageObserver = @protocol(MWMFrameworkStorageObserver); Protocol * pDrapeObserver = @protocol(MWMFrameworkDrapeObserver); @@ -41,7 +39,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block) @property (nonatomic) TObservers * routeBuildingObservers; @property (nonatomic) TObservers * myPositionObservers; -@property (nonatomic) TObservers * userMarkObservers; @property (nonatomic) TObservers * storageObservers; @property (nonatomic) TObservers * drapeObservers; @@ -50,10 +47,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block) @end @implementation MWMFrameworkListener -{ - unique_ptr m_userMark; - mutex m_userMarkMutex; -} + (MWMFrameworkListener *)listener { @@ -72,8 +65,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block) [listener.routeBuildingObservers addObject:observer]; if ([observer conformsToProtocol:pMyPositionObserver]) [listener.myPositionObservers addObject:observer]; - if ([observer conformsToProtocol:pUserMarkObserver]) - [listener.userMarkObservers addObject:observer]; if ([observer conformsToProtocol:pStorageObserver]) [listener.storageObservers addObject:observer]; if ([observer conformsToProtocol:pDrapeObserver]) @@ -88,7 +79,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block) MWMFrameworkListener * listener = [MWMFrameworkListener listener]; [listener.routeBuildingObservers removeObject:observer]; [listener.myPositionObservers removeObject:observer]; - [listener.userMarkObservers removeObject:observer]; [listener.storageObservers removeObject:observer]; [listener.drapeObservers removeObject:observer]; }); @@ -101,13 +91,11 @@ void loopWrappers(TObservers * observers, TLoopBlock block) { _routeBuildingObservers = [TObservers weakObjectsHashTable]; _myPositionObservers = [TObservers weakObjectsHashTable]; - _userMarkObservers = [TObservers weakObjectsHashTable]; _storageObservers = [TObservers weakObjectsHashTable]; _drapeObservers = [TObservers weakObjectsHashTable]; [self registerRouteBuilderListener]; [self registerMyPositionListener]; - [self registerUserMarkObserver]; [self registerStorageObserver]; [self registerDrapeObserver]; } @@ -160,27 +148,6 @@ void loopWrappers(TObservers * observers, TLoopBlock block) }); } -#pragma mark - MWMFrameworkUserMarkObserver - -- (void)registerUserMarkObserver -{ - TObservers * observers = self.userMarkObservers; - auto & f = GetFramework(); - f.SetUserMarkActivationListener([self, observers](unique_ptr mark) - { - lock_guard lock(m_userMarkMutex); - m_userMark = move(mark); - loopWrappers(observers, [self](TUsermarkObserver observer) - { - lock_guard lock(self->m_userMarkMutex); - if (self->m_userMark != nullptr) - [observer processUserMarkEvent:self->m_userMark->GetUserMark()]; - else - [observer processUserMarkEvent:nullptr]; - }); - }); -} - #pragma mark - MWMFrameworkStorageObserver - (void)registerStorageObserver @@ -215,19 +182,4 @@ void loopWrappers(TObservers * observers, TLoopBlock block) }); } -#pragma mark - Properties - -- (UserMark const *)userMark -{ - return m_userMark ? m_userMark->GetUserMark() : nullptr; -} - -- (void)setUserMark:(UserMark const *)userMark -{ - if (userMark) - m_userMark.reset(new UserMarkCopy(userMark, false)); - else - m_userMark = nullptr; -} - @end diff --git a/iphone/Maps/Classes/Framework/MWMFrameworkObservers.h b/iphone/Maps/Classes/Framework/MWMFrameworkObservers.h index ee329d2a38..243884668c 100644 --- a/iphone/Maps/Classes/Framework/MWMFrameworkObservers.h +++ b/iphone/Maps/Classes/Framework/MWMFrameworkObservers.h @@ -27,12 +27,6 @@ using namespace storage; @end -@protocol MWMFrameworkUserMarkObserver - -- (void)processUserMarkEvent:(UserMark const *)mark; - -@end - @protocol MWMFrameworkStorageObserver - (void)processCountryEvent:(TCountryId const &)countryId; diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.h b/iphone/Maps/Classes/MWMBasePlacePageView.h index 5ac7c79d49..e01b4baa00 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.h +++ b/iphone/Maps/Classes/MWMBasePlacePageView.h @@ -10,7 +10,6 @@ @property (weak, nonatomic) IBOutlet UITableView * featureTable; @property (weak, nonatomic) IBOutlet UIView * separatorView; @property (weak, nonatomic) IBOutlet UIButton * directionButton; -@property (nonatomic) MWMPlacePageTypeDescriptionView * typeDescriptionView; - (void)configureWithEntity:(MWMPlacePageEntity *)entity; - (void)addBookmark; diff --git a/iphone/Maps/Classes/MWMBasePlacePageView.mm b/iphone/Maps/Classes/MWMBasePlacePageView.mm index e54f18391c..29066889d6 100644 --- a/iphone/Maps/Classes/MWMBasePlacePageView.mm +++ b/iphone/Maps/Classes/MWMBasePlacePageView.mm @@ -7,7 +7,6 @@ #import "MWMPlacePageEntity.h" #import "MWMPlacePageInfoCell.h" #import "MWMPlacePageOpeningHoursCell.h" -#import "MWMPlacePageTypeDescription.h" #import "MWMPlacePageViewManager.h" #import "Statistics.h" #import "UIColor+MapsMeColor.h" @@ -171,9 +170,7 @@ enum class AttributePosition - (void)configure { MWMPlacePageEntity * entity = self.entity; - MWMPlacePageEntityType const type = entity.type; - - if (type == MWMPlacePageEntityTypeBookmark) + if (entity.isBookmark) { self.titleLabel.text = entity.bookmarkTitle.length > 0 ? entity.bookmarkTitle : entity.title; self.typeLabel.text = [entity.bookmarkCategory capitalizedString]; @@ -197,22 +194,8 @@ enum class AttributePosition } } - [self.typeDescriptionView removeFromSuperview]; - if (type == MWMPlacePageEntityTypeEle || type == MWMPlacePageEntityTypeHotel) - { - MWMPlacePageTypeDescription * description = [[MWMPlacePageTypeDescription alloc] initWithPlacePageEntity:entity]; - self.typeDescriptionView = static_cast(type == MWMPlacePageEntityTypeEle ? - description.eleDescription : - description.hotelDescription); - [self addSubview:self.typeDescriptionView]; - } - else - { - self.typeDescriptionView = nil; - } - + BOOL const isMyPosition = entity.isMyPosition; self.addressLabel.text = entity.address; - BOOL const isMyPosition = type == MWMPlacePageEntityTypeMyPosition; BOOL const isHeadingAvaible = [CLLocationManager headingAvailable]; using namespace location; auto const mode = [MWMFrameworkListener listener].myPositionMode; @@ -231,9 +214,9 @@ enum class AttributePosition - (AttributePosition)distanceAttributePosition { - if ((self.typeLabel.text.length || self.typeDescriptionView)) + if (self.typeLabel.text.length) return AttributePosition::Type; - else if ((!self.typeLabel.text.length && !self.typeDescriptionView) && self.addressLabel.text.length) + else if (!self.typeLabel.text.length && self.addressLabel.text.length) return AttributePosition::Address; else return AttributePosition::Title; @@ -281,7 +264,6 @@ enum class AttributePosition [self.typeLabel sizeToFit]; [self.addressLabel sizeToFit]; [self layoutLabels]; - [self.typeDescriptionView layoutNearPoint:{self.typeLabel.maxX, self.typeLabel.minY}]; [self layoutDistanceBoxWithPosition:position]; [self layoutTableViewWithPosition:position]; self.height = self.featureTable.height + self.separatorView.height + self.titleLabel.height + @@ -348,9 +330,6 @@ enum class AttributePosition { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatToggleBookmark) withParameters:@{kStatValue : kStatAdd}]; - self.entity.type = MWMPlacePageEntityTypeBookmark; - [self.typeDescriptionView removeFromSuperview]; - self.typeDescriptionView = nil; [self.typeLabel sizeToFit]; m_sections.push_back(PlacePageSection::Bookmark); @@ -364,7 +343,6 @@ enum class AttributePosition { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatToggleBookmark) withParameters:@{kStatValue : kStatRemove}]; - self.entity.type = MWMPlacePageEntityTypeRegular; auto const it = find(m_sections.begin(), m_sections.end(), PlacePageSection::Bookmark); if (it != m_sections.end()) diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index 92ace94e31..949e89db87 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -179,7 +179,6 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; { MWMPlacePageViewManager * manager = self.manager; MapViewController * ovc = static_cast(manager.ownerViewController); - ovc.skipPlacePageDismissOnViewDisappear = YES; SelectSetVC * vc = [[SelectSetVC alloc] initWithPlacePageManager:manager]; [ovc.navigationController pushViewController:vc animated:YES]; } @@ -195,7 +194,6 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; { MWMPlacePageViewManager * manager = self.manager; MapViewController * ovc = static_cast(manager.ownerViewController); - ovc.skipPlacePageDismissOnViewDisappear = YES; MWMBookmarkDescriptionViewController * viewController = [[MWMBookmarkDescriptionViewController alloc] initWithPlacePageManager:manager]; [ovc.navigationController pushViewController:viewController animated:YES]; } diff --git a/iphone/Maps/Classes/MWMPlacePageActionBar.mm b/iphone/Maps/Classes/MWMPlacePageActionBar.mm index 6ba04d5e4b..dff4409221 100644 --- a/iphone/Maps/Classes/MWMPlacePageActionBar.mm +++ b/iphone/Maps/Classes/MWMPlacePageActionBar.mm @@ -48,21 +48,17 @@ static NSString * const kPlacePageActionBarNibName = @"PlacePageActionBar"; - (void)configureWithPlacePage:(MWMPlacePage *)placePage { self.placePage = placePage; - switch (placePage.manager.entity.type) - { - case MWMPlacePageEntityTypeAPI: - [self setupApiBar]; - break; - case MWMPlacePageEntityTypeBookmark: - [self setupBookmarkBar]; - break; - case MWMPlacePageEntityTypeMyPosition: - [self setupMyPositionBar]; - break; - default: - [self setupDefaultBar]; - break; - } + MWMPlacePageEntity * entity = placePage.manager.entity; + if (entity.isApi) + [self setupApiBar]; + // TODO(Vlad): API point can be a bookmark too. Probably "else if" shoud be replaced by "if". + else if (entity.isBookmark) + [self setupBookmarkBar]; + else if (entity.isMyPosition) + [self setupMyPositionBar]; + else + [self setupDefaultBar]; + self.autoresizingMask = UIViewAutoresizingNone; [self setNeedsLayout]; } @@ -167,35 +163,30 @@ static NSString * const kPlacePageActionBarNibName = @"PlacePageActionBar"; CGFloat const maximumWidth = 360.; CGFloat const screenWidth = MIN(size.height, size.width); CGFloat const actualWidth = IPAD ? maximumWidth : (size.height < size.width ? MIN(screenWidth, maximumWidth) : screenWidth); - switch (self.placePage.manager.entity.type) + MWMPlacePageEntity * entity = self.placePage.manager.entity; + if (entity.isApi) + { + CGFloat const boxWidth = 4 * buttonWidth; + CGFloat const leftOffset = (actualWidth - boxWidth) / 5.; + self.apiBackButton.minX = leftOffset; + self.shareButton.minX = self.apiBackButton.maxX + leftOffset; + self.bookmarkButton.minX = self.shareButton.maxX + leftOffset; + self.routeButton.minX = self.bookmarkButton.maxX; + } + else if (entity.isMyPosition) + { + CGFloat const boxWidth = 2 * buttonWidth; + CGFloat const leftOffset = (actualWidth - boxWidth) / 3.; + self.shareButton.minX = leftOffset; + self.bookmarkButton.minX = actualWidth - leftOffset - buttonWidth; + } + else { - case MWMPlacePageEntityTypeAPI: - { - CGFloat const boxWidth = 4 * buttonWidth; - CGFloat const leftOffset = (actualWidth - boxWidth) / 5.; - self.apiBackButton.minX = leftOffset; - self.shareButton.minX = self.apiBackButton.maxX + leftOffset; - self.bookmarkButton.minX = self.shareButton.maxX + leftOffset; - self.routeButton.minX = self.bookmarkButton.maxX; - break; - } - case MWMPlacePageEntityTypeMyPosition: - { - CGFloat const boxWidth = 2 * buttonWidth; - CGFloat const leftOffset = (actualWidth - boxWidth) / 3.; - self.shareButton.minX = leftOffset; - self.bookmarkButton.minX = actualWidth - leftOffset - buttonWidth; - break; - } - default: - { - CGFloat const boxWidth = 3 * buttonWidth; - CGFloat const leftOffset = (actualWidth - boxWidth) / 4.; - self.shareButton.minX = leftOffset; - self.bookmarkButton.minX = self.shareButton.maxX + leftOffset; - self.routeButton.minX = self.bookmarkButton.maxX + leftOffset; - break; - } + CGFloat const boxWidth = 3 * buttonWidth; + CGFloat const leftOffset = (actualWidth - boxWidth) / 4.; + self.shareButton.minX = leftOffset; + self.bookmarkButton.minX = self.shareButton.maxX + leftOffset; + self.routeButton.minX = self.bookmarkButton.maxX + leftOffset; } self.apiBackLabel.minX = self.apiBackButton.minX; self.shareLabel.minX = self.shareButton.minX; diff --git a/iphone/Maps/Classes/MWMPlacePageDescriptionView.xib b/iphone/Maps/Classes/MWMPlacePageDescriptionView.xib deleted file mode 100644 index 7801593ec8..0000000000 --- a/iphone/Maps/Classes/MWMPlacePageDescriptionView.xib +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.h b/iphone/Maps/Classes/MWMPlacePageEntity.h index 879801af41..23da0b5924 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.h +++ b/iphone/Maps/Classes/MWMPlacePageEntity.h @@ -1,6 +1,5 @@ #include "Framework.h" -#include "map/user_mark.hpp" #include "indexer/feature_meta.hpp" typedef NS_ENUM(NSUInteger, MWMPlacePageCellType) @@ -22,16 +21,6 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageCellType) MWMPlacePageCellTypeCount }; -typedef NS_ENUM(NSUInteger, MWMPlacePageEntityType) -{ - MWMPlacePageEntityTypeRegular, - MWMPlacePageEntityTypeBookmark, - MWMPlacePageEntityTypeEle, - MWMPlacePageEntityTypeHotel, - MWMPlacePageEntityTypeAPI, - MWMPlacePageEntityTypeMyPosition -}; - using MWMPlacePageCellTypeValueMap = map; @class MWMPlacePageViewManager; @@ -49,24 +38,23 @@ using MWMPlacePageCellTypeValueMap = map; @property (nonatomic, readonly) BOOL isHTMLDescription; @property (copy, nonatomic) NSString * bookmarkColor; @property (copy, nonatomic) NSSet * cuisines; -@property (copy, nonatomic) NSArray * nearbyStreets; -@property (nonatomic, readonly) BOOL canEditObject; - -@property (nonatomic) MWMPlacePageEntityType type; - -@property (nonatomic) int typeDescriptionValue; @property (nonatomic) BookmarkAndCategory bac; @property (weak, nonatomic) MWMPlacePageViewManager * manager; -@property (nonatomic, readonly) ms::LatLon latlon; +- (FeatureID const &)featureID; +- (BOOL)isMyPosition; +- (BOOL)isBookmark; +- (BOOL)isApi; +- (ms::LatLon)latlon; +- (m2::PointD const &)mercator; +- (NSString *)apiURL; +- (instancetype)initWithInfo:(place_page::Info const &)info; - (void)synchronize; - (void)toggleCoordinateSystem; - (NSString *)getCellValue:(MWMPlacePageCellType)cellType; -- (BOOL)isCellEditable:(MWMPlacePageCellType)cellType; -- (void)saveEditedCells:(MWMPlacePageCellTypeValueMap const &)cells; @end diff --git a/iphone/Maps/Classes/MWMPlacePageEntity.mm b/iphone/Maps/Classes/MWMPlacePageEntity.mm index 5b7d965fca..cb803b921c 100644 --- a/iphone/Maps/Classes/MWMPlacePageEntity.mm +++ b/iphone/Maps/Classes/MWMPlacePageEntity.mm @@ -3,8 +3,8 @@ #import "MWMPlacePageViewManager.h" #import "MapViewController.h" +#include "Framework.h" #include "platform/measurement_utils.hpp" -#include "indexer/osm_editor.hpp" using feature::Metadata; @@ -16,17 +16,19 @@ namespace NSString * const kOSMCuisineSeparator = @";"; -NSString * makeOSMCuisineString(NSSet * cuisines) -{ - NSMutableArray * osmCuisines = [NSMutableArray arrayWithCapacity:cuisines.count]; - for (NSString * cuisine in cuisines) - [osmCuisines addObject:cuisine]; - [osmCuisines sortUsingComparator:^NSComparisonResult(NSString * s1, NSString * s2) - { - return [s1 compare:s2]; - }]; - return [osmCuisines componentsJoinedByString:kOSMCuisineSeparator]; -} +//TODO(Alex): If we can format cuisines in subtitle we won't need this function. + +//NSString * makeOSMCuisineString(NSSet * cuisines) +//{ +// NSMutableArray * osmCuisines = [NSMutableArray arrayWithCapacity:cuisines.count]; +// for (NSString * cuisine in cuisines) +// [osmCuisines addObject:cuisine]; +// [osmCuisines sortUsingComparator:^NSComparisonResult(NSString * s1, NSString * s2) +// { +// return [s1 compare:s2]; +// }]; +// return [osmCuisines componentsJoinedByString:kOSMCuisineSeparator]; +//} NSUInteger gMetaFieldsMap[MWMPlacePageCellTypeCount] = {}; @@ -57,17 +59,10 @@ void initFieldsMap() } } // namespace -@interface MWMPlacePageEntity () - - -@property (nonatomic, readwrite) BOOL canEditObject; - -@end - @implementation MWMPlacePageEntity { - set m_editableFields; MWMPlacePageCellTypeValueMap m_values; + place_page::Info m_info; } + (NSString *)makeMWMCuisineString:(NSSet *)cuisines @@ -88,11 +83,12 @@ void initFieldsMap() return [localizedCuisines componentsJoinedByString:kMWMCuisineSeparator]; } -- (instancetype)init +- (instancetype)initWithInfo:(const place_page::Info &)info { self = [super init]; if (self) { + m_info = info; initFieldsMap(); [self config]; } @@ -101,31 +97,12 @@ void initFieldsMap() - (void)config { - UserMark const * mark = [MWMFrameworkListener listener].userMark; - _latlon = mark->GetLatLon(); - using Type = UserMark::Type; - switch (mark->GetMarkType()) - { - case Type::API: - [self configureForApi:static_cast(mark)]; - break; - case Type::DEBUG_MARK: - break; - case Type::MY_POSITION: - [self configureForMyPosition:static_cast(mark)]; - break; - case Type::SEARCH: - [self configureWithFeature:mark->GetFeature() andCustomName:nil]; - break; - case Type::POI: - [self configureWithFeature:mark->GetFeature() - andCustomName:@(static_cast(mark)->GetCustomName().c_str())]; - break; - case Type::BOOKMARK: - [self configureForBookmark:mark]; - break; - } - [self setEditableTypes]; + [self configureDefault]; + + if (m_info.IsFeature()) + [self configureFeature]; + if (m_info.IsBookmark()) + [self configureBookmark]; } - (void)setMetaField:(NSUInteger)key value:(string const &)value @@ -138,117 +115,60 @@ void initFieldsMap() m_values[cellType] = value; } -- (void)configureForBookmark:(UserMark const *)bookmark -{ - // TODO: There is need to get address info which store feature address. - Framework & f = GetFramework(); - self.bac = f.FindBookmark(bookmark); - self.type = MWMPlacePageEntityTypeBookmark; - BookmarkCategory * category = f.GetBmCategory(self.bac.first); - BookmarkData const & data = static_cast(bookmark)->GetData(); - - self.bookmarkTitle = @(data.GetName().c_str()); - self.bookmarkCategory = @(category->GetName().c_str()); - string const description = data.GetDescription(); - self.bookmarkDescription = @(description.c_str()); - _isHTMLDescription = strings::IsHTML(description); - self.bookmarkColor = @(data.GetType().c_str()); - - [self configureWithFeature:bookmark->GetFeature() andCustomName:nil]; -} - -- (void)configureForMyPosition:(MyPositionMarkPoint const *)myPositionMark -{ - // TODO: There is need to get address info which store feature address. - self.title = L(@"my_position"); - self.type = MWMPlacePageEntityTypeMyPosition; -} - -- (void)configureForApi:(ApiMarkPoint const *)apiMark +- (void)configureDefault { - // TODO: There is need to get address info which store feature address. - self.type = MWMPlacePageEntityTypeAPI; - self.title = @(apiMark->GetName().c_str()); - self.category = @(GetFramework().GetApiDataHolder().GetAppTitle().c_str()); + search::AddressInfo const address = GetFramework().GetAddressInfoAtPoint(m_info.GetMercator()); + self.title = @(m_info.GetTitle().c_str()); + self.address = @(address.FormatAddress().c_str()); } -- (void)configureWithFeature:(FeatureType *)feature andCustomName:(NSString *)customName +- (void)configureFeature { - NSString * emptyName = L(@"dropped_pin"); - // Custom name is used in shared links and should override default feature's name in PP. - BOOL const customNameIsEmpty = customName.length == 0; - self.title = customNameIsEmpty ? emptyName : customName; - // feature can be nullptr if user selected any empty area. - if (feature) + // Category can also be custom-formatted, please check m_info getters. + self.category = @(m_info.GetSubtitle().c_str()); + // TODO(Vlad): Refactor using osm::Props instead of direct Metadata access. + feature::Metadata const & md = m_info.GetMetadata(); + for (auto const type : md.GetPresentTypes()) { - search::AddressInfo const info = GetFramework().GetFeatureAddressInfo(*feature); - feature::Metadata const & metadata = feature->GetMetadata(); - NSString * const name = @(info.GetPinName().c_str()); - if (customNameIsEmpty) - self.title = name.length > 0 ? name : emptyName; - self.category = @(info.GetPinType().c_str()); - self.address = @(info.FormatAddress().c_str()); - - if (!info.m_house.empty()) - [self setMetaField:MWMPlacePageCellTypeBuilding value:info.m_house]; - - for (auto const type : metadata.GetPresentTypes()) + switch (type) { - switch (type) - { - case Metadata::FMD_CUISINE: - { - [self deserializeCuisine:@(metadata.Get(type).c_str())]; - NSString * cuisine = [self getCellValue:MWMPlacePageCellTypeCuisine]; - if (self.category.length == 0) - self.category = cuisine; - else if (![self.category isEqualToString:cuisine]) - self.category = [NSString stringWithFormat:@"%@%@%@", self.category, kMWMCuisineSeparator, cuisine]; - break; - } - case Metadata::FMD_ELE: - { - self.typeDescriptionValue = atoi(metadata.Get(type).c_str()); - if (self.type != MWMPlacePageEntityTypeBookmark) - self.type = MWMPlacePageEntityTypeEle; - break; - } - case Metadata::FMD_OPERATOR: - { - NSString * bank = @(metadata.Get(type).c_str()); - if (self.category.length) - self.category = [NSString stringWithFormat:@"%@%@%@", self.category, kMWMCuisineSeparator, bank]; - else - self.category = bank; - break; - } - case Metadata::FMD_STARS: - { - self.typeDescriptionValue = atoi(metadata.Get(type).c_str()); - if (self.type != MWMPlacePageEntityTypeBookmark) - self.type = MWMPlacePageEntityTypeHotel; - break; - } - case Metadata::FMD_URL: - case Metadata::FMD_WEBSITE: - case Metadata::FMD_PHONE_NUMBER: - case Metadata::FMD_OPEN_HOURS: - case Metadata::FMD_EMAIL: - case Metadata::FMD_POSTCODE: - [self setMetaField:gMetaFieldsMap[type] value:metadata.Get(type)]; - break; - case Metadata::FMD_INTERNET: - [self setMetaField:gMetaFieldsMap[type] value:L(@"WiFi_available").UTF8String]; - break; - default: - break; - } + case Metadata::FMD_URL: + case Metadata::FMD_WEBSITE: + case Metadata::FMD_PHONE_NUMBER: + case Metadata::FMD_OPEN_HOURS: + case Metadata::FMD_EMAIL: + case Metadata::FMD_POSTCODE: + [self setMetaField:gMetaFieldsMap[type] value:md.Get(type)]; + break; + case Metadata::FMD_INTERNET: + [self setMetaField:gMetaFieldsMap[type] value:L(@"WiFi_available").UTF8String]; + break; + case Metadata::FMD_ELE: + [self setMetaField:gMetaFieldsMap[type] value:"▲" + m_info.GetElevation()]; + break; + case Metadata::FMD_STARS: + [self setMetaField:gMetaFieldsMap[type] value:m_info.FormatStars()]; + break; + default: + break; } - - [self processStreets]; } } +- (void)configureBookmark +{ + auto const bac = m_info.GetBookmarkAndCategory(); + BookmarkCategory * cat = GetFramework().GetBmCategory(bac.first); + BookmarkData const & data = static_cast(cat->GetUserMark(bac.second))->GetData(); + + self.bookmarkTitle = @(data.GetName().c_str()); + self.bookmarkCategory = @(cat->GetName().c_str()); + string const & description = data.GetDescription(); + self.bookmarkDescription = @(description.c_str()); + _isHTMLDescription = strings::IsHTML(description); + self.bookmarkColor = @(data.GetType().c_str()); +} + - (void)toggleCoordinateSystem { NSUserDefaults * ud = [NSUserDefaults standardUserDefaults]; @@ -261,114 +181,6 @@ void initFieldsMap() self.cuisines = [NSSet setWithArray:[cuisine componentsSeparatedByString:kOSMCuisineSeparator]]; } -- (void)processStreets -{ - FeatureType * feature = [MWMFrameworkListener listener].userMark->GetFeature(); - if (!feature) - return; - - Framework & frm = GetFramework(); - auto const streets = frm.GetNearbyFeatureStreets(*feature); - NSMutableArray * arr = [[NSMutableArray alloc] initWithCapacity:streets.size()]; - for (auto const & street : streets) - [arr addObject:@(street.c_str())]; - self.nearbyStreets = arr; - - auto const info = frm.GetFeatureAddressInfo(*feature); - [self setMetaField:MWMPlacePageCellTypeStreet value:info.m_street]; -} - -#pragma mark - Editing - -- (void)setEditableTypes -{ - FeatureType const * feature = [MWMFrameworkListener listener].userMark->GetFeature(); - if (!feature) - return; - - osm::EditableProperties const editable = osm::Editor::Instance().GetEditableProperties(*feature); - self.canEditObject = editable.IsEditable(); - if (editable.m_name) - m_editableFields.insert(MWMPlacePageCellTypeName); - if (editable.m_address) - { - m_editableFields.insert(MWMPlacePageCellTypeStreet); - m_editableFields.insert(MWMPlacePageCellTypeBuilding); - } - for (feature::Metadata::EType const type : editable.m_metadata) - { - NSAssert(gMetaFieldsMap[type] >= Metadata::FMD_COUNT || gMetaFieldsMap[type] == 0, @"Incorrect enum value"); - MWMPlacePageCellType const field = static_cast(gMetaFieldsMap[type]); - m_editableFields.insert(field); - } -} - -- (BOOL)isCellEditable:(MWMPlacePageCellType)cellType -{ - return m_editableFields.count(cellType) == 1; -} - -- (void)saveEditedCells:(MWMPlacePageCellTypeValueMap const &)cells -{ - FeatureType * feature = [MWMFrameworkListener listener].userMark->GetFeature(); - NSAssert(feature != nullptr, @"Feature is null"); - if (!feature) - return; - - auto & metadata = feature->GetMetadata(); - NSString * entityStreet = [self getCellValue:MWMPlacePageCellTypeStreet]; - string streetName = (entityStreet ? entityStreet : @"").UTF8String; - NSString * entityHouseNumber = [self getCellValue:MWMPlacePageCellTypeBuilding]; - string houseNumber = (entityHouseNumber ? entityHouseNumber : @"").UTF8String;; - for (auto const & cell : cells) - { - switch (cell.first) - { - case MWMPlacePageCellTypePhoneNumber: - case MWMPlacePageCellTypeWebsite: - case MWMPlacePageCellTypeOpenHours: - case MWMPlacePageCellTypeEmail: - case MWMPlacePageCellTypeWiFi: - { - Metadata::EType const fmdType = static_cast(gMetaFieldsMap[cell.first]); - NSAssert(fmdType > 0 && fmdType < Metadata::FMD_COUNT, @"Incorrect enum value"); - metadata.Set(fmdType, cell.second); - break; - } - case MWMPlacePageCellTypeCuisine: - { - Metadata::EType const fmdType = static_cast(gMetaFieldsMap[cell.first]); - NSAssert(fmdType > 0 && fmdType < Metadata::FMD_COUNT, @"Incorrect enum value"); - NSString * osmCuisineStr = makeOSMCuisineString(self.cuisines); - metadata.Set(fmdType, osmCuisineStr.UTF8String); - break; - } - case MWMPlacePageCellTypeName: - { - // TODO(AlexZ): Make sure that we display and save name in the same language (default?). - auto names = feature->GetNames(); - names.AddString(StringUtf8Multilang::kDefaultCode, cell.second); - feature->SetNames(names); - break; - } - case MWMPlacePageCellTypeStreet: - { - streetName = cell.second; - break; - } - case MWMPlacePageCellTypeBuilding: - { - houseNumber = cell.second; - break; - } - default: - NSAssert(false, @"Invalid field for editor"); - break; - } - } - osm::Editor::Instance().EditFeature(*feature, streetName, houseNumber); -} - #pragma mark - Getters - (NSString *)getCellValue:(MWMPlacePageCellType)cellType @@ -380,9 +192,10 @@ void initFieldsMap() case MWMPlacePageCellTypeCoordinate: return [self coordinate]; case MWMPlacePageCellTypeBookmark: - return self.type == MWMPlacePageEntityTypeBookmark ? @"haveValue" : nil; + return m_info.IsBookmark() ? @"haveValue" : nil; case MWMPlacePageCellTypeEditButton: - return self.canEditObject ? @"haveValue" : nil; + // TODO(Vlad): It's a really strange way to "display" cell if returned text is not nil. + return m_info.IsEditable() ? @"Refactor Me" : nil; default: { auto const it = m_values.find(cellType); @@ -392,14 +205,48 @@ void initFieldsMap() } } +- (FeatureID const &)featureID +{ + return m_info.GetID(); +} + +- (BOOL)isMyPosition +{ + return m_info.IsMyPosition(); +} + +- (BOOL)isBookmark +{ + return m_info.IsBookmark(); +} + +- (BOOL)isApi +{ + return m_info.HasApiUrl(); +} + +- (ms::LatLon)latlon +{ + return m_info.GetLatLon(); +} + +- (m2::PointD const &)mercator +{ + return m_info.GetMercator(); +} + +- (NSString *)apiURL +{ + return @(m_info.GetApiUrl().c_str()); +} + - (NSString *)coordinate { BOOL const useDMSFormat = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsLatLonAsDMSKey]; ms::LatLon const latlon = self.latlon; return @((useDMSFormat ? MeasurementUtils::FormatLatLon(latlon.lat, latlon.lon) - : MeasurementUtils::FormatLatLonAsDMS(latlon.lat, latlon.lon, 2)) - .c_str()); + : MeasurementUtils::FormatLatLonAsDMS(latlon.lat, latlon.lon, 2)).c_str()); } #pragma mark - Properties @@ -423,6 +270,16 @@ void initFieldsMap() #pragma mark - Bookmark editing +- (void)setBac:(BookmarkAndCategory)bac +{ + m_info.m_bac = bac; +} + +- (BookmarkAndCategory)bac +{ + return m_info.GetBookmarkAndCategory(); +} + - (NSString *)bookmarkCategory { if (!_bookmarkCategory) diff --git a/iphone/Maps/Classes/MWMPlacePageNavigationBar.mm b/iphone/Maps/Classes/MWMPlacePageNavigationBar.mm index 623d33c3ce..cc61b74b83 100644 --- a/iphone/Maps/Classes/MWMPlacePageNavigationBar.mm +++ b/iphone/Maps/Classes/MWMPlacePageNavigationBar.mm @@ -54,7 +54,7 @@ static inline CGPoint const dismissCenter(CGFloat xPosition) navBar.placePage = placePage; MWMPlacePageEntity * entity = placePage.manager.entity; - navBar.titleLabel.text = entity.type == MWMPlacePageEntityTypeBookmark ? entity.bookmarkTitle : entity.title; + navBar.titleLabel.text = entity.isMyPosition ? entity.bookmarkTitle : entity.title; [navBar show]; } diff --git a/iphone/Maps/Classes/MWMPlacePageTypeDescription.h b/iphone/Maps/Classes/MWMPlacePageTypeDescription.h deleted file mode 100644 index b280ba6400..0000000000 --- a/iphone/Maps/Classes/MWMPlacePageTypeDescription.h +++ /dev/null @@ -1,16 +0,0 @@ -#import "MWMPlacePageEntity.h" - -@interface MWMPlacePageTypeDescriptionView : UIView - -- (void)layoutNearPoint:(CGPoint const &)point; - -@end - -@interface MWMPlacePageTypeDescription : NSObject - -@property (nonatomic) IBOutlet MWMPlacePageTypeDescriptionView * eleDescription; -@property (nonatomic) IBOutlet MWMPlacePageTypeDescriptionView * hotelDescription; - -- (instancetype)initWithPlacePageEntity:(MWMPlacePageEntity *)entity; - -@end diff --git a/iphone/Maps/Classes/MWMPlacePageTypeDescription.mm b/iphone/Maps/Classes/MWMPlacePageTypeDescription.mm deleted file mode 100644 index 1c3fd4b4dd..0000000000 --- a/iphone/Maps/Classes/MWMPlacePageTypeDescription.mm +++ /dev/null @@ -1,73 +0,0 @@ -#import "MWMPlacePageTypeDescription.h" - -namespace -{ - -NSString * const kPlacePageDescriptionViewNibName = @"MWMPlacePageDescriptionView"; -CGFloat const kLeftOffset = 8.0; - -} // namespace - -@implementation MWMPlacePageTypeDescriptionView - -- (void)layoutNearPoint:(CGPoint const &)point -{ - self.origin = {point.x + kLeftOffset, point.y}; -} - -@end - -@interface MWMPlacePageELEDescription : MWMPlacePageTypeDescriptionView - -@property (weak, nonatomic) IBOutlet UILabel * heightLabel; - -- (void)configureWithHeight:(NSUInteger)height; - -@end - -@interface MWMPlacePageHotelDescription : MWMPlacePageTypeDescriptionView - -- (void)configureWithStarsCount:(NSUInteger)count; - -@end - -@implementation MWMPlacePageTypeDescription - -- (instancetype)initWithPlacePageEntity:(MWMPlacePageEntity *)entity -{ - self = [super init]; - if (self) - { - [[NSBundle mainBundle] loadNibNamed:kPlacePageDescriptionViewNibName owner:self options:nil]; - if (entity.type == MWMPlacePageEntityTypeEle) - [static_cast(self.eleDescription) configureWithHeight:entity.typeDescriptionValue]; - else - [static_cast(self.hotelDescription) configureWithStarsCount:entity.typeDescriptionValue]; - self.eleDescription.autoresizingMask = self.hotelDescription.autoresizingMask = UIViewAutoresizingNone; - } - return self; -} - -@end - -@implementation MWMPlacePageHotelDescription - -- (void)configureWithStarsCount:(NSUInteger)count -{ - [self.subviews enumerateObjectsUsingBlock:^(UIImageView * star, NSUInteger idx, BOOL *stop) - { - star.highlighted = (idx < count); - }]; -} - -@end - -@implementation MWMPlacePageELEDescription - -- (void)configureWithHeight:(NSUInteger)height -{ - self.heightLabel.text = [NSString stringWithFormat:@"%@", @(height)]; -} - -@end - diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.h b/iphone/Maps/Classes/MWMPlacePageViewManager.h index 76b172dc08..6933f38876 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.h +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.h @@ -14,8 +14,7 @@ - (instancetype)initWithViewController:(UIViewController *)viewController delegate:(id)delegate; -- (void)showPlacePage; -- (void)reloadPlacePage; +- (void)showPlacePage:(place_page::Info const &)info; - (void)refreshPlacePage; - (void)mwm_refreshUI; - (BOOL)hasPlacePage; @@ -33,7 +32,6 @@ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator; - (void)reloadBookmark; -- (void)changeBookmarkCategory:(BookmarkAndCategory)bac; - (void)dragPlacePage:(CGRect)frame; - (void)showDirectionViewWithTitle:(NSString *)title type:(NSString *)type; - (void)hideDirectionView; diff --git a/iphone/Maps/Classes/MWMPlacePageViewManager.mm b/iphone/Maps/Classes/MWMPlacePageViewManager.mm index eb91816251..026c51859b 100644 --- a/iphone/Maps/Classes/MWMPlacePageViewManager.mm +++ b/iphone/Maps/Classes/MWMPlacePageViewManager.mm @@ -21,23 +21,17 @@ #import "3party/Alohalytics/src/alohalytics_objc.h" #include "geometry/distance_on_sphere.hpp" +#include "map/place_page_info.hpp" #include "platform/measurement_utils.hpp" extern NSString * const kAlohalyticsTapEventKey; extern NSString * const kBookmarksChangedNotification; -typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) -{ - MWMPlacePageManagerStateClosed, - MWMPlacePageManagerStateOpen -}; - @interface MWMPlacePageViewManager () @property (weak, nonatomic) UIViewController * ownerViewController; @property (nonatomic, readwrite) MWMPlacePageEntity * entity; @property (nonatomic) MWMPlacePage * placePage; -@property (nonatomic) MWMPlacePageManagerState state; @property (nonatomic) MWMDirectionView * directionView; @property (weak, nonatomic) id delegate; @@ -54,7 +48,6 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) { self.ownerViewController = viewController; self.delegate = delegate; - self.state = MWMPlacePageManagerStateClosed; } return self; } @@ -66,31 +59,17 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)dismissPlacePage { - MWMFrameworkListener * listener = [MWMFrameworkListener listener]; - if (!listener.userMark) - return; [self.delegate placePageDidClose]; - self.state = MWMPlacePageManagerStateClosed; [self.placePage dismiss]; [[MapsAppDelegate theApp].m_locationManager stop:self]; - listener.userMark = nullptr; - GetFramework().DeactivateUserMark(); + GetFramework().DeactivateMapSelection(false); self.placePage = nil; } -- (void)showPlacePage +- (void)showPlacePage:(place_page::Info const &)info { [[MapsAppDelegate theApp].m_locationManager start:self]; - [self reloadPlacePage]; -} - -- (void)reloadPlacePage -{ - MWMFrameworkListener * listener = [MWMFrameworkListener listener]; - if (!listener.userMark) - return; - self.entity = [[MWMPlacePageEntity alloc] init]; - self.state = MWMPlacePageManagerStateOpen; + self.entity = [[MWMPlacePageEntity alloc] initWithInfo:info]; if (IPAD) [self setPlacePageForiPad]; else @@ -131,7 +110,7 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)configPlacePage { - if (self.entity.type == MWMPlacePageEntityTypeMyPosition) + if (self.entity.isMyPosition) { BOOL hasSpeed; self.entity.category = [[MapsAppDelegate theApp].m_locationManager formattedSpeedAndAltitude:hasSpeed]; @@ -168,7 +147,7 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)updateMyPositionSpeedAndAltitude { - if (self.entity.type != MWMPlacePageEntityTypeMyPosition) + if (!self.entity.isMyPosition) return; BOOL hasSpeed = NO; [self.placePage updateMyPositionStatus:[[MapsAppDelegate theApp].m_locationManager @@ -177,9 +156,6 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)setPlacePageForiPhoneWithOrientation:(UIInterfaceOrientation)orientation { - if (self.state == MWMPlacePageManagerStateClosed) - return; - switch (orientation) { case UIInterfaceOrientationLandscapeLeft: @@ -211,16 +187,12 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatBuildRoute) withParameters:@{kStatValue : kStatDestination}]; [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"ppRoute"]; - MWMFrameworkListener * listener = [MWMFrameworkListener listener]; - m2::PointD const & destination = listener.userMark->GetPivot(); m2::PointD const myPosition([MapsAppDelegate theApp].m_locationManager.lastLocation.mercator); using namespace location; - auto const mode = listener.myPositionMode; - [self.delegate buildRouteFrom:mode != EMyPositionMode::MODE_UNKNOWN_POSITION && - mode != EMyPositionMode::MODE_PENDING_POSITION - ? MWMRoutePoint(myPosition) - : MWMRoutePoint::MWMRoutePointZero() - to:{destination, self.placePage.basePlacePageView.titleLabel.text}]; + auto const mode = MWMFrameworkListener.listener.myPositionMode; + bool const knownPosition = (mode != EMyPositionMode::MODE_UNKNOWN_POSITION && mode != EMyPositionMode::MODE_PENDING_POSITION); + [self.delegate buildRouteFrom:knownPosition ? MWMRoutePoint(myPosition) : MWMRoutePoint::MWMRoutePointZero() + to:{self.entity.mercator, self.placePage.basePlacePageView.titleLabel.text}]; } - (void)routeFrom @@ -243,11 +215,9 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (MWMRoutePoint)target { - UserMark const * m = [MWMFrameworkListener listener].userMark; - m2::PointD const & org = m->GetPivot(); - return m->GetMarkType() == UserMark::Type::MY_POSITION ? - MWMRoutePoint(org) : - MWMRoutePoint(org, self.placePage.basePlacePageView.titleLabel.text); + m2::PointD const & org = self.entity.mercator; + return self.entity.isMyPosition ? MWMRoutePoint(org) + : MWMRoutePoint(org, self.placePage.basePlacePageView.titleLabel.text); } - (void)share @@ -268,19 +238,10 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)apiBack { [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatAPI)]; - ApiMarkPoint const * p = static_cast([MWMFrameworkListener listener].userMark); - NSURL * url = [NSURL URLWithString:@(GetFramework().GenerateApiBackUrl(*p).c_str())]; - [[UIApplication sharedApplication] openURL:url]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.entity.apiURL]]; [self.delegate apiBack]; } -- (void)changeBookmarkCategory:(BookmarkAndCategory)bac; -{ - BookmarkCategory * category = GetFramework().GetBmCategory(bac.first); - BookmarkCategory::Guard guard(*category); - [MWMFrameworkListener listener].userMark = guard.m_controller.GetUserMark(bac.second); -} - - (void)editPlace { [(MapViewController *)self.ownerViewController openEditor]; @@ -291,21 +252,10 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatBookmarks) withParameters:@{kStatValue : kStatAdd}]; Framework & f = GetFramework(); - BookmarkData data = BookmarkData(self.entity.title.UTF8String, f.LastEditedBMType()); - MWMFrameworkListener * listener = [MWMFrameworkListener listener]; + BookmarkData bmData = { self.entity.title.UTF8String, f.LastEditedBMType() }; size_t const categoryIndex = f.LastEditedBMCategory(); - m2::PointD const mercator = listener.userMark->GetPivot(); - size_t const bookmarkIndex = f.GetBookmarkManager().AddBookmark(categoryIndex, mercator, data); - self.entity.bac = make_pair(categoryIndex, bookmarkIndex); - self.entity.type = MWMPlacePageEntityTypeBookmark; - - BookmarkCategory::Guard guard(*f.GetBmCategory(categoryIndex)); - - UserMark const * bookmark = guard.m_controller.GetUserMark(bookmarkIndex); - // TODO(AlexZ): Refactor bookmarks code together to hide this code in the Framework/Drape. - // UI code should never know about any guards, pointers to UserMark etc. - const_cast(bookmark)->SetFeature(f.GetFeatureAtPoint(mercator)); - listener.userMark = bookmark; + size_t const bookmarkIndex = f.GetBookmarkManager().AddBookmark(categoryIndex, self.entity.mercator, bmData); + self.entity.bac = {categoryIndex, bookmarkIndex}; [NSNotificationCenter.defaultCenter postNotificationName:kBookmarksChangedNotification object:nil userInfo:nil]; @@ -317,27 +267,16 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) [[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatBookmarks) withParameters:@{kStatValue : kStatRemove}]; Framework & f = GetFramework(); - BookmarkAndCategory bookmarkAndCategory = self.entity.bac; - BookmarkCategory * bookmarkCategory = f.GetBookmarkManager().GetBmCategory(bookmarkAndCategory.first); - if (!bookmarkCategory) - return; - - UserMark const * bookmark = bookmarkCategory->GetUserMark(bookmarkAndCategory.second); - ASSERT_EQUAL(bookmarkAndCategory, f.FindBookmark(bookmark), ()); - - self.entity.type = MWMPlacePageEntityTypeRegular; - - // TODO(AlexZ): SetFeature is called in GetAddressMark here. - // UI code should never know about any guards, pointers to UserMark etc. - [MWMFrameworkListener listener].userMark = f.GetAddressMark(bookmark->GetPivot()); + BookmarkCategory * bookmarkCategory = f.GetBookmarkManager().GetBmCategory(self.entity.bac.first); if (bookmarkCategory) { { BookmarkCategory::Guard guard(*bookmarkCategory); - guard.m_controller.DeleteUserMark(bookmarkAndCategory.second); + guard.m_controller.DeleteUserMark(self.entity.bac.second); } bookmarkCategory->SaveToKMLFile(); } + self.entity.bac = MakeEmptyBookmarkAndCategory(); [NSNotificationCenter.defaultCenter postNotificationName:kBookmarksChangedNotification object:nil userInfo:nil]; @@ -372,12 +311,13 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (NSString *)distance { CLLocation * location = [MapsAppDelegate theApp].m_locationManager.lastLocation; - UserMark const * userMark = [MWMFrameworkListener listener].userMark; - if (!location || !userMark) + // TODO(AlexZ): Do we REALLY need this check? Why this method is called if user mark/m_info is empty? + // TODO(AlexZ): Can location be checked before calling this method? + if (!location/* || !m_userMark*/) return @""; string distance; CLLocationCoordinate2D const coord = location.coordinate; - ms::LatLon const target = MercatorBounds::ToLatLon(userMark->GetPivot()); + ms::LatLon const target = self.entity.latlon; MeasurementUtils::FormatDistance(ms::DistanceOnEarth(coord.latitude, coord.longitude, target.lat, target.lon), distance); return @(distance.c_str()); @@ -386,11 +326,12 @@ typedef NS_ENUM(NSUInteger, MWMPlacePageManagerState) - (void)onCompassUpdate:(location::CompassInfo const &)info { CLLocation * location = [MapsAppDelegate theApp].m_locationManager.lastLocation; - UserMark const * userMark = [MWMFrameworkListener listener].userMark; - if (!location || !userMark) + // TODO(AlexZ): Do we REALLY need this check? Why compass update is here if user mark/m_info is empty? + // TODO(AlexZ): Can location be checked before calling this method? + if (!location/* || !m_userMark*/) return; - CGFloat const angle = ang::AngleTo(location.mercator, userMark->GetPivot()) + info.m_bearing; + CGFloat const angle = ang::AngleTo(location.mercator, self.entity.mercator) + info.m_bearing; CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2 - angle); [self.placePage setDirectionArrowTransform:transform]; [self.directionView setDirectionArrowTransform:transform]; diff --git a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm index 219008b985..49832d10df 100644 --- a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm @@ -194,7 +194,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) __weak MWMiPhoneLandscapePlacePage * weakSelf = self; BOOL const stateClosed = self.state == MWMiPhoneLandscapePlacePageStateClosed; if (stateClosed) - GetFramework().DeactivateUserMark(); + GetFramework().DeactivateMapSelection(false); self.panRecognizer.enabled = !stateClosed; [self startAnimatingPlacePage:self initialVelocity:CGPointMake(self.panVelocity, 0.0) completion:^ diff --git a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm index 2bf7eca183..94ca8340c6 100644 --- a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm @@ -345,7 +345,7 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) _targetPoint = targetPoint; __weak MWMiPhonePortraitPlacePage * weakSelf = self; if (self.state == MWMiPhonePortraitPlacePageStateClosed) - GetFramework().DeactivateUserMark(); + GetFramework().DeactivateMapSelection(false); [self startAnimatingPlacePage:self initialVelocity:{0.0, self.panVelocity} completion:^ { diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 1de866f0a2..42669e885f 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -15,7 +15,7 @@ namespace search { struct AddressInfo; } @interface MapViewController : MWMViewController { CGPoint m_popoverPos; - + LocationPredictor * m_predictor; } @@ -49,6 +49,5 @@ namespace search { struct AddressInfo; } @property (nonatomic, readonly) MWMMapViewControlsManager * controlsManager; @property (nonatomic) m2::PointD restoreRouteDestination; @property (nonatomic) MWMAPIBar * apiBar; -@property (nonatomic) BOOL skipPlacePageDismissOnViewDisappear; @end diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 230b555828..212288d2dc 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -102,8 +102,8 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; @end @interface MapViewController () + MWMFrameworkMyPositionObserver, MWMFrameworkDrapeObserver, + MWMFrameworkStorageObserver> @property (nonatomic, readwrite) MWMMapViewControlsManager * controlsManager; @property (nonatomic) MWMBottomMenuState menuRestoreState; @@ -203,9 +203,19 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; [self.controlsManager dismissPlacePage]; } -- (void)onMyPositionClicked:(id)sender +- (void)onMapObjectDeselected:(bool)switchFullScreenMode { - GetFramework().SwitchMyPositionNextMode(); + [self dismissPlacePage]; + + auto & f = GetFramework(); + if (switchFullScreenMode && self.controlsManager.searchHidden && !f.IsRouteNavigable()) + self.controlsManager.hidden = !self.controlsManager.hidden; +} + +- (void)onMapObjectSelected:(place_page::Info const &)info +{ + self.controlsManager.hidden = NO; + [self.controlsManager showPlacePage:info]; } - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController @@ -365,8 +375,6 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; return; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; - self.skipPlacePageDismissOnViewDisappear = NO; - [self.controlsManager reloadPlacePage]; self.controlsManager.menuState = self.menuRestoreState; [self refreshAd]; @@ -426,8 +434,6 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; { [super viewWillDisappear:animated]; self.menuRestoreState = self.controlsManager.menuState; - if (!self.skipPlacePageDismissOnViewDisappear) - [self dismissPlacePage]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } @@ -485,6 +491,10 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; - (void)initialize { + Framework & f = GetFramework(); + + f.SetMapSelectionListeners([self](place_page::Info const & info) { [self onMapObjectSelected:info]; }, + [self](bool switchFullScreen){ [self onMapObjectDeselected:switchFullScreen]; }); m_predictor = [[LocationPredictor alloc] initWithObserver:self]; self.forceRoutingStateChange = ForceRoutingStateChangeNone; self.userTouchesAction = UserTouchesActionNone; @@ -559,7 +569,7 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; { case routing::IRouter::ResultCode::NoError: { - GetFramework().ActivateUserMark(nullptr, true); + GetFramework().DeactivateMapSelection(true); if (self.forceRoutingStateChange == ForceRoutingStateChangeStartFollowing) [self.controlsManager routingNavigation]; else @@ -615,25 +625,6 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; } } -#pragma mark - MWMFrameworkUserMarkObserver - -- (void)processUserMarkEvent:(UserMark const *)mark -{ - if (mark == nullptr) - { - [self dismissPlacePage]; - - auto & f = GetFramework(); - if (!f.HasActiveUserMark() && self.controlsManager.searchHidden && !f.IsRouteNavigable()) - self.controlsManager.hidden = !self.controlsManager.hidden; - } - else - { - self.controlsManager.hidden = NO; - [self.controlsManager showPlacePage]; - } -} - #pragma mark - MWMFrameworkStorageObserver - (void)processCountryEvent:(TCountryId const &)countryId @@ -784,7 +775,7 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; { Framework & f = GetFramework(); if (self.popoverVC) - f.ActivateUserMark(nullptr, true); + f.DeactivateMapSelection(true); CGFloat const sf = self.view.contentScaleFactor; @@ -822,10 +813,9 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; { if ([segue.identifier isEqualToString:kEditorSegue]) { - self.skipPlacePageDismissOnViewDisappear = YES; UINavigationController * dvc = segue.destinationViewController; MWMEditorViewController * editorVC = (MWMEditorViewController *)[dvc topViewController]; - editorVC.entity = sender; + [editorVC setFeatureToEdit:((MWMPlacePageEntity *)sender).featureID]; } else if ([segue.identifier isEqualToString:kAuthorizationSegue]) { diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index dac78fb737..a7d9af2308 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -301,7 +301,6 @@ 671182E51C7F0DDB00CB8177 /* packed_polygons_obsolete.bin in Resources */ = {isa = PBXBuildFile; fileRef = 671182DF1C7F0DD400CB8177 /* packed_polygons_obsolete.bin */; }; 671182E61C7F0DDD00CB8177 /* countries_obsolete.txt in Resources */ = {isa = PBXBuildFile; fileRef = 671182DE1C7F0DD400CB8177 /* countries_obsolete.txt */; }; 6741A9421BF340DE002C974C /* sound-strings in Resources */ = {isa = PBXBuildFile; fileRef = 5605022E1B6211E100169CAD /* sound-strings */; }; - 6741A9431BF340DE002C974C /* MWMPlacePageDescriptionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F67BC26E1B254B1F00FE1D7B /* MWMPlacePageDescriptionView.xib */; }; 6741A9441BF340DE002C974C /* PlacePageBookmarkCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 342BB7AA1BC7CC5C00DF6443 /* PlacePageBookmarkCell.xib */; }; 6741A9451BF340DE002C974C /* classificator.txt in Resources */ = {isa = PBXBuildFile; fileRef = EE026F0511D6AC0D00645242 /* classificator.txt */; }; 6741A9461BF340DE002C974C /* MWMSearchTabbedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34CC4C081B81F3B500E44C1F /* MWMSearchTabbedViewController.xib */; }; @@ -444,7 +443,6 @@ 6741A9DF1BF340DE002C974C /* MWMSearchHistoryClearCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34B82AC21B84608600180497 /* MWMSearchHistoryClearCell.mm */; }; 6741A9E01BF340DE002C974C /* MWMDownloaderDialogHeader.mm in Sources */ = {isa = PBXBuildFile; fileRef = F64F4B731B4A45FD0081A24A /* MWMDownloaderDialogHeader.mm */; }; 6741A9E11BF340DE002C974C /* MWMSearchTableView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34F8ADD81B97229A004184CC /* MWMSearchTableView.mm */; }; - 6741A9E21BF340DE002C974C /* MWMPlacePageTypeDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = F67BC2741B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm */; }; 6741A9E31BF340DE002C974C /* TimeUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = B08AA8D91A26299A00810B1C /* TimeUtils.mm */; }; 6741A9E41BF340DE002C974C /* MWMPlacePageBookmarkCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6CB216C1AF13EBD00FB8963 /* MWMPlacePageBookmarkCell.mm */; }; 6741A9E51BF340DE002C974C /* MWMPlacePageViewManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = F653D4221AE9398700282659 /* MWMPlacePageViewManager.mm */; }; @@ -693,8 +691,6 @@ F66A8FB21B0A0954001B9C97 /* PlacePageView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F66A8FB11B0A0954001B9C97 /* PlacePageView.xib */; }; F6791B131C43DEA7007A8A6E /* MWMStartButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6791B121C43DEA7007A8A6E /* MWMStartButton.mm */; }; F6791B141C43DF0B007A8A6E /* MWMStartButton.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6791B121C43DEA7007A8A6E /* MWMStartButton.mm */; }; - F67BC26F1B254B2000FE1D7B /* MWMPlacePageDescriptionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F67BC26E1B254B1F00FE1D7B /* MWMPlacePageDescriptionView.xib */; }; - F67BC2751B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm in Sources */ = {isa = PBXBuildFile; fileRef = F67BC2741B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm */; }; F681DE971BFB390A00B547C7 /* MWMWhatsNewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = F681DE961BFB390A00B547C7 /* MWMWhatsNewController.mm */; }; F6830F111B85F6B900C42AAE /* MWMLanesPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = F6830F101B85F6B900C42AAE /* MWMLanesPanel.mm */; }; F68E6BD21B8DB7AE0040566D /* MWMRouteHelperPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = F68E6BD11B8DB7AE0040566D /* MWMRouteHelperPanel.mm */; }; @@ -1334,9 +1330,6 @@ F66A8FB11B0A0954001B9C97 /* PlacePageView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PlacePageView.xib; sourceTree = ""; }; F6791B111C43DEA7007A8A6E /* MWMStartButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMStartButton.h; sourceTree = ""; }; F6791B121C43DEA7007A8A6E /* MWMStartButton.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMStartButton.mm; sourceTree = ""; }; - F67BC26E1B254B1F00FE1D7B /* MWMPlacePageDescriptionView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMPlacePageDescriptionView.xib; sourceTree = ""; }; - F67BC2731B254F5500FE1D7B /* MWMPlacePageTypeDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMPlacePageTypeDescription.h; sourceTree = ""; }; - F67BC2741B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMPlacePageTypeDescription.mm; sourceTree = ""; }; F681DE951BFB390A00B547C7 /* MWMWhatsNewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMWhatsNewController.h; sourceTree = ""; }; F681DE961BFB390A00B547C7 /* MWMWhatsNewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMWhatsNewController.mm; sourceTree = ""; }; F6830F0F1B85F6B900C42AAE /* MWMLanesPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMLanesPanel.h; sourceTree = ""; }; @@ -2755,9 +2748,6 @@ F6ED138F1B1EF96B0095C6DE /* MWMBookmarkDescriptionViewController.h */, F6ED13901B1EF96B0095C6DE /* MWMBookmarkDescriptionViewController.mm */, F6ED13921B1EFA2F0095C6DE /* MWMBookmarkDescriptionViewController.xib */, - F67BC2731B254F5500FE1D7B /* MWMPlacePageTypeDescription.h */, - F67BC2741B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm */, - F67BC26E1B254B1F00FE1D7B /* MWMPlacePageDescriptionView.xib */, ); name = PlacePage; path = ../..; @@ -3020,7 +3010,6 @@ 5605022F1B6211E100169CAD /* sound-strings in Resources */, 34CCFDE21C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib in Resources */, 452FCA3B1B6A3DF7007019AB /* colors.txt in Resources */, - F67BC26F1B254B2000FE1D7B /* MWMPlacePageDescriptionView.xib in Resources */, 342BB7AB1BC7CC5C00DF6443 /* PlacePageBookmarkCell.xib in Resources */, EE026F0611D6AC0D00645242 /* classificator.txt in Resources */, 34CC4C0A1B81F3B500E44C1F /* MWMSearchTabbedViewController.xib in Resources */, @@ -3157,7 +3146,6 @@ 671182E51C7F0DDB00CB8177 /* packed_polygons_obsolete.bin in Resources */, 676507601C10559800830BB3 /* patterns.txt in Resources */, 6741A9421BF340DE002C974C /* sound-strings in Resources */, - 6741A9431BF340DE002C974C /* MWMPlacePageDescriptionView.xib in Resources */, 3401CD801C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.xib in Resources */, 6741A9441BF340DE002C974C /* PlacePageBookmarkCell.xib in Resources */, 6741A9451BF340DE002C974C /* classificator.txt in Resources */, @@ -3399,7 +3387,6 @@ 34B82AC41B84608600180497 /* MWMSearchHistoryClearCell.mm in Sources */, F64F4B741B4A45FD0081A24A /* MWMDownloaderDialogHeader.mm in Sources */, 34F8ADD91B97229A004184CC /* MWMSearchTableView.mm in Sources */, - F67BC2751B254F5500FE1D7B /* MWMPlacePageTypeDescription.mm in Sources */, B08AA8DA1A26299A00810B1C /* TimeUtils.mm in Sources */, F6CB216D1AF13EBD00FB8963 /* MWMPlacePageBookmarkCell.mm in Sources */, F653D4231AE9398700282659 /* MWMPlacePageViewManager.mm in Sources */, @@ -3605,7 +3592,6 @@ 6741A9DF1BF340DE002C974C /* MWMSearchHistoryClearCell.mm in Sources */, 6741A9E01BF340DE002C974C /* MWMDownloaderDialogHeader.mm in Sources */, 6741A9E11BF340DE002C974C /* MWMSearchTableView.mm in Sources */, - 6741A9E21BF340DE002C974C /* MWMPlacePageTypeDescription.mm in Sources */, 6741A9E31BF340DE002C974C /* TimeUtils.mm in Sources */, 341F99EE1C6B28A7001C67B8 /* MWMMapDownloaderExtendedDataSource.mm in Sources */, 6741A9E41BF340DE002C974C /* MWMPlacePageBookmarkCell.mm in Sources */, -- cgit v1.2.3