diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm index 75975d8962..6b5cff6913 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/MWMMapViewControlsManager.mm @@ -112,6 +112,10 @@ extern NSString * const kAlohalyticsTapEventKey; - (MWMAlertViewController *)alertController { return self.ownerController.alertController; } - (void)searchViewDidEnterState:(MWMSearchManagerState)state { + if (state == MWMSearchManagerStateMapSearch) + { + [self.navigationManager setMapSearch]; + } if (state == MWMSearchManagerStateHidden) { if (!IPAD || MapsAppDelegate.theApp.routingPlaneMode == MWMRoutingPlaneModeNone) diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm index 654a72a982..19c3ee0d61 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/MWMSearchManager.mm @@ -90,7 +90,7 @@ extern NSString * const kSearchStateKey = @"SearchStateKey"; - (IBAction)textFieldDidEndEditing:(UITextField *)textField { - if (textField.text.length == 0) + if (textField.text.length == 0 && self.state != MWMSearchManagerStateHidden) [self endSearch]; } @@ -275,6 +275,15 @@ extern NSString * const kSearchStateKey = @"SearchStateKey"; [self.searchTextField resignFirstResponder]; self.rootView.compact = YES; [MWMSearch setSearchOnMap:YES]; + + if ([MWMNavigationDashboardManager manager].state == MWMNavigationDashboardStateNavigation) + { + self.searchTextField.text = @""; + [self.tabbedController resetSelectedTab]; + self.tableViewController = nil; + self.noMapsController = nil; + self.rootView.isVisible = NO; + } } #pragma mark - Properties diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm index bf7260b740..8e19935986 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm @@ -67,7 +67,6 @@ NSString * identifierForType(MWMSearchTableCellType type) { [super viewWillDisappear:animated]; [MWMSearch removeObserver:self]; - [MWMSearch clear]; } - (void)mwm_refreshUI { [self.view mwm_refreshUI]; } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h index ea549bde14..ca4bc37f42 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.h @@ -45,6 +45,7 @@ typedef NS_ENUM(NSUInteger, MWMNavigationDashboardState) { - (void)updateDashboard; - (void)setRouteBuilderProgress:(CGFloat)progress; - (void)mwm_refreshUI; +- (void)setMapSearch; - (void)addInfoDisplay:(id)infoDisplay; diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm index 41aedd1546..75db4dcd88 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm @@ -138,6 +138,7 @@ using TInfoDisplays = NSHashTable<__kindof TInfoDisplay>; [self.routePreview remove]; self.routePreview = nil; [self.navigationInfoView addToView:self.ownerView]; + [MWMMapViewControlsManager manager].searchHidden = YES; } - (void)mwm_refreshUI @@ -246,4 +247,10 @@ using TInfoDisplays = NSHashTable<__kindof TInfoDisplay>; return self.navigationInfoView.extraCompassBottomOffset; } +- (void)setMapSearch +{ + if (_navigationInfoView) + [self.navigationInfoView setMapSearch]; +} + @end diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.h index 1eeda5ea64..032c48ec55 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.h +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.h @@ -1,12 +1,27 @@ #import "MWMNavigationDashboardInfoProtocol.h" +enum class NavigationSearchState +{ + Maximized, + MinimizedNormal, + MinimizedSearch, + MinimizedGas, + MinimizedParking, + MinimizedFood, + MinimizedShop, + MinimizedATM +}; + @interface MWMNavigationInfoView : UIView @property(nonatomic) CGFloat leftBound; @property(nonatomic, readonly) CGFloat extraCompassBottomOffset; @property(nonatomic, readonly) CGFloat visibleHeight; +@property(nonatomic, readonly) NavigationSearchState searchState; - (void)addToView:(UIView *)superview; - (void)remove; +- (void)setMapSearch; + @end diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.mm index 8b5f766242..afbb56e865 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.mm @@ -1,9 +1,12 @@ #import "MWMNavigationInfoView.h" +#import "AppInfo.h" #import "Common.h" #import "MWMButton.h" #import "MWMLocationHelpers.h" #import "MWMLocationManager.h" +#import "MWMMapViewControlsManager.h" #import "MWMRouter.h" +#import "MWMSearch.h" #import "UIFont+MapsMeFonts.h" #import "UIImageView+Coloring.h" @@ -25,27 +28,22 @@ CGFloat constexpr kSearchButtonsSideSize = 44; NSTimeInterval constexpr kCollapseSearchTimeout = 5.0; -enum class SearchState -{ - Maximized, - MinimizedNormal, - MinimizedSearch, - MinimizedGas, - MinimizedParking, - MinimizedFood, - MinimizedShop, - MinimizedATM -}; +map const kSearchStateButtonImageNames{ + {NavigationSearchState::Maximized, @"ic_routing_search"}, + {NavigationSearchState::MinimizedNormal, @"ic_routing_search"}, + {NavigationSearchState::MinimizedSearch, @"ic_routing_search_off"}, + {NavigationSearchState::MinimizedGas, @"ic_routing_fuel_off"}, + {NavigationSearchState::MinimizedParking, @"ic_routing_parking_off"}, + {NavigationSearchState::MinimizedFood, @"ic_routing_food_off"}, + {NavigationSearchState::MinimizedShop, @"ic_routing_shop_off"}, + {NavigationSearchState::MinimizedATM, @"ic_routing_atm_off"}}; -map const kSearchStateButtonImageNames{ - {SearchState::Maximized, @"ic_routing_search"}, - {SearchState::MinimizedNormal, @"ic_routing_search"}, - {SearchState::MinimizedSearch, @"ic_routing_search_off"}, - {SearchState::MinimizedGas, @"ic_routing_fuel_off"}, - {SearchState::MinimizedParking, @"ic_routing_parking_off"}, - {SearchState::MinimizedFood, @"ic_routing_food_off"}, - {SearchState::MinimizedShop, @"ic_routing_shop_off"}, - {SearchState::MinimizedATM, @"ic_routing_atm_off"}}; +map const kSearchButtonRequest{ + {NavigationSearchState::MinimizedGas, L(@"fuel")}, + {NavigationSearchState::MinimizedParking, L(@"parking")}, + {NavigationSearchState::MinimizedFood, L(@"food")}, + {NavigationSearchState::MinimizedShop, L(@"shop")}, + {NavigationSearchState::MinimizedATM, L(@"atm")}}; BOOL defaultOrientation() { @@ -64,7 +62,6 @@ BOOL defaultOrientation() @property(weak, nonatomic) IBOutlet UIImageView * secondTurnImageView; @property(weak, nonatomic) IBOutlet NSLayoutConstraint * turnsWidth; -@property(weak, nonatomic) IBOutlet UIView * searchView; @property(weak, nonatomic) IBOutlet UIView * searchButtonsView; @property(weak, nonatomic) IBOutlet MWMButton * searchMainButton; @property(weak, nonatomic) IBOutlet NSLayoutConstraint * searchButtonsViewHeight; @@ -73,13 +70,13 @@ BOOL defaultOrientation() @property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * searchLandscapeConstraints; @property(nonatomic) IBOutletCollection(UIButton) NSArray * searchButtons; @property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * searchButtonsSideSize; -@property(weak, nonatomic) IBOutlet MWMButton * searchButtonGas; -@property(weak, nonatomic) IBOutlet MWMButton * searchButtonParking; -@property(weak, nonatomic) IBOutlet MWMButton * searchButtonFood; -@property(weak, nonatomic) IBOutlet MWMButton * searchButtonShop; -@property(weak, nonatomic) IBOutlet MWMButton * searchButtonATM; +@property(weak, nonatomic) IBOutlet MWMButton * searchGasButton; +@property(weak, nonatomic) IBOutlet MWMButton * searchParkingButton; +@property(weak, nonatomic) IBOutlet MWMButton * searchFoodButton; +@property(weak, nonatomic) IBOutlet MWMButton * searchShopButton; +@property(weak, nonatomic) IBOutlet MWMButton * searchATMButton; -@property(nonatomic) SearchState searchState; +@property(nonatomic, readwrite) NavigationSearchState searchState; @property(nonatomic) BOOL isVisible; @property(weak, nonatomic) MWMNavigationDashboardEntity * navigationInfo; @@ -91,7 +88,7 @@ BOOL defaultOrientation() - (void)addToView:(UIView *)superview { self.isVisible = YES; - [self setSearchState:SearchState::MinimizedNormal animated:NO]; + [self setSearchState:NavigationSearchState::MinimizedNormal animated:NO]; if (IPAD) { self.turnsWidth.constant = kTurnsiPadWidth; @@ -123,44 +120,58 @@ BOOL defaultOrientation() } - (CGFloat)visibleHeight { return self.streetNameView.maxY; } +- (void)setMapSearch { [self setSearchState:NavigationSearchState::MinimizedSearch animated:YES]; } #pragma mark - Search - (IBAction)searchMainButtonTouchUpInside { switch (self.searchState) { - case SearchState::Maximized: - [self setSearchState:SearchState::MinimizedSearch animated:YES]; + case NavigationSearchState::Maximized: + [MWMMapViewControlsManager manager].searchHidden = NO; + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; break; - case SearchState::MinimizedNormal: - [self setSearchState:SearchState::Maximized animated:YES]; + case NavigationSearchState::MinimizedNormal: + [self setSearchState:NavigationSearchState::Maximized animated:YES]; break; - case SearchState::MinimizedSearch: - case SearchState::MinimizedGas: - case SearchState::MinimizedParking: - case SearchState::MinimizedFood: - case SearchState::MinimizedShop: - case SearchState::MinimizedATM: - [self setSearchState:SearchState::MinimizedNormal animated:YES]; + case NavigationSearchState::MinimizedSearch: + case NavigationSearchState::MinimizedGas: + case NavigationSearchState::MinimizedParking: + case NavigationSearchState::MinimizedFood: + case NavigationSearchState::MinimizedShop: + case NavigationSearchState::MinimizedATM: + [MWMSearch clear]; + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; break; } } - (IBAction)searchButtonTouchUpInside:(MWMButton *)sender { - if (sender == self.searchButtonGas) - [self setSearchState:SearchState::MinimizedGas animated:YES]; - else if (sender == self.searchButtonParking) - [self setSearchState:SearchState::MinimizedParking animated:YES]; - else if (sender == self.searchButtonFood) - [self setSearchState:SearchState::MinimizedFood animated:YES]; - else if (sender == self.searchButtonShop) - [self setSearchState:SearchState::MinimizedShop animated:YES]; - else if (sender == self.searchButtonATM) - [self setSearchState:SearchState::MinimizedATM animated:YES]; + auto const body = ^(NavigationSearchState state) { + [MWMSearch setSearchOnMap:YES]; + NSString * query = [kSearchButtonRequest.at(state) stringByAppendingString:@" "]; + NSString * locale = [[AppInfo sharedInfo] languageId]; + [MWMSearch searchQuery:query forInputLocale:locale]; + [self setSearchState:state animated:YES]; + }; + + if (sender == self.searchGasButton) + body(NavigationSearchState::MinimizedGas); + else if (sender == self.searchParkingButton) + body(NavigationSearchState::MinimizedParking); + else if (sender == self.searchFoodButton) + body(NavigationSearchState::MinimizedFood); + else if (sender == self.searchShopButton) + body(NavigationSearchState::MinimizedShop); + else if (sender == self.searchATMButton) + body(NavigationSearchState::MinimizedATM); } -- (void)collapseSearchOnTimer { [self setSearchState:SearchState::MinimizedNormal animated:YES]; } +- (void)collapseSearchOnTimer +{ + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; +} #pragma mark - MWMNavigationDashboardInfoProtocol - (void)updateNavigationInfo:(MWMNavigationDashboardEntity *)info @@ -211,7 +222,7 @@ BOOL defaultOrientation() defaultView ? kSearchMainButtonBottomOffsetPortrait : kSearchMainButtonBottomOffsetLandscape; CGFloat alpha = 1; CGFloat searchButtonsSideSize = kSearchButtonsSideSize; - if (self.searchState == SearchState::Maximized) + if (self.searchState == NavigationSearchState::Maximized) { self.searchButtonsViewWidth.constant = defaultView ? kSearchButtonsViewWidthPortrait : kSearchButtonsViewWidthLandscape; @@ -254,30 +265,30 @@ BOOL defaultOrientation() - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - if (self.searchState == SearchState::Maximized) + if (self.searchState == NavigationSearchState::Maximized) return; [super touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - if (self.searchState == SearchState::Maximized) + if (self.searchState == NavigationSearchState::Maximized) return; [super touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - if (self.searchState == SearchState::Maximized) - [self setSearchState:SearchState::MinimizedNormal animated:YES]; + if (self.searchState == NavigationSearchState::Maximized) + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; else [super touchesEnded:touches withEvent:event]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { - if (self.searchState == SearchState::Maximized) - [self setSearchState:SearchState::MinimizedNormal animated:YES]; + if (self.searchState == NavigationSearchState::Maximized) + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; else [super touchesCancelled:touches withEvent:event]; } @@ -301,7 +312,7 @@ BOOL defaultOrientation() }]; } -- (void)setSearchState:(SearchState)searchState animated:(BOOL)animated +- (void)setSearchState:(NavigationSearchState)searchState animated:(BOOL)animated { self.searchState = searchState; auto block = ^{ @@ -319,7 +330,7 @@ BOOL defaultOrientation() } SEL const collapseSelector = @selector(collapseSearchOnTimer); [NSObject cancelPreviousPerformRequestsWithTarget:self selector:collapseSelector object:self]; - if (self.searchState == SearchState::Maximized) + if (self.searchState == NavigationSearchState::Maximized) { [self.superview bringSubviewToFront:self]; [self performSelector:collapseSelector withObject:self afterDelay:kCollapseSearchTimeout]; @@ -330,7 +341,7 @@ BOOL defaultOrientation() } } -- (void)setSearchState:(SearchState)searchState +- (void)setSearchState:(NavigationSearchState)searchState { _searchState = searchState; self.searchMainButton.imageName = kSearchStateButtonImageNames.at(searchState); @@ -356,11 +367,12 @@ BOOL defaultOrientation() { _leftBound = MAX(leftBound, 0.0); [self setNeedsLayout]; + [self layoutIfNeeded]; } - (CGFloat)extraCompassBottomOffset { - return defaultOrientation() || self.searchView.hidden ? 0 : kSearchButtonsViewHeightLandscape; + return defaultOrientation() ? 0 : kSearchButtonsViewHeightLandscape; } @end diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.xib b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.xib index e199d3dfa3..1cfa33f3a1 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.xib +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationInfoView.xib @@ -16,11 +16,14 @@ - + - - + + - - + + - - - - - + + + - - + + + - - - + + + + + + + + - - - - - - - - - - - - - - + - - + + + + + + + + + + diff --git a/iphone/Maps/Classes/Search/MWMSearch.mm b/iphone/Maps/Classes/Search/MWMSearch.mm index 011ff5e1c5..c6218e1d52 100644 --- a/iphone/Maps/Classes/Search/MWMSearch.mm +++ b/iphone/Maps/Classes/Search/MWMSearch.mm @@ -21,6 +21,8 @@ using TObservers = NSHashTable<__kindof TObserver>; @property(nonatomic) BOOL searchOnMap; @property(nonatomic) BOOL textChanged; +@property(nonatomic) BOOL isSearching; +@property(nonatomic) BOOL isPendingUpdate; @property(nonatomic) TObservers * observers; @@ -64,23 +66,48 @@ using TObservers = NSHashTable<__kindof TObserver>; if (!self) return; runAsyncOnMainQueue([self, results] { - if (!results.IsEndMarker()) + if (results.IsEndMarker()) + { + [self onSearchCompleted]; + } + else { self->m_results = results; self.suggestionsCount = results.GetSuggestsCount(); self.resultsCount = results.GetCount(); [self onSearchResultsUpdated]; } - else if (results.IsEndedNormal()) - { - [self onSearchCompleted]; - } }); }; } return self; } +- (void)update +{ + if (self.isSearching) + { + self.isPendingUpdate = YES; + return; + } + self.isPendingUpdate = NO; + if (m_params.m_query.empty()) + return; + CLLocation * lastLocation = [MWMLocationManager lastLocation]; + if (lastLocation) + m_params.SetPosition(lastLocation.coordinate.latitude, lastLocation.coordinate.longitude); + if (self.searchOnMap) + GetFramework().StartInteractiveSearch(m_params); + else + GetFramework().Search(m_params); +} + +- (void)showResultsOnMap +{ + if (self.searchOnMap) + GetFramework().ShowSearchResults(m_results); +} + #pragma mark - Add/Remove Observers + (void)addObserver:(id)observer @@ -132,6 +159,7 @@ using TObservers = NSHashTable<__kindof TObserver>; + (void)clear { + GetFramework().CancelInteractiveSearch(); MWMSearch * manager = [MWMSearch manager]; manager->m_params.Clear(); manager->m_results.Clear(); @@ -149,34 +177,12 @@ using TObservers = NSHashTable<__kindof TObserver>; + (NSUInteger)suggestionsCount { return [MWMSearch manager].suggestionsCount; } + (NSUInteger)resultsCount { return [MWMSearch manager].resultsCount; } -- (void)update -{ - auto & f = GetFramework(); - f.CancelInteractiveSearch(); - [self onSearchCompleted]; - if (m_params.m_query.empty()) - return; - CLLocation * lastLocation = [MWMLocationManager lastLocation]; - if (lastLocation) - m_params.SetPosition(lastLocation.coordinate.latitude, lastLocation.coordinate.longitude); - if (self.searchOnMap) - { - if (self.textChanged) - f.UpdateUserViewportChanged(); - else - f.ShowSearchResults(m_results); - f.StartInteractiveSearch(m_params); - } - else - { - f.Search(m_params); - } -} #pragma mark - Notifications - (void)onSearchStarted { + self.isSearching = YES; for (TObserver observer in self.observers) { if ([observer respondsToSelector:@selector(onSearchStarted)]) @@ -186,13 +192,15 @@ using TObservers = NSHashTable<__kindof TObserver>; - (void)onSearchCompleted { + self.isSearching = NO; + if (self.isPendingUpdate) + [self update]; for (TObserver observer in self.observers) { if ([observer respondsToSelector:@selector(onSearchCompleted)]) [observer onSearchCompleted]; } - if (IPAD) - GetFramework().UpdateUserViewportChanged(); + [self showResultsOnMap]; } - (void)onSearchResultsUpdated