From 2f4146dc26ea1f7ff76bb592c7312cec88b04415 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 14 Feb 2012 19:34:24 +0300 Subject: [PATCH] [ios] Do not display flag for current country in the search results. @TODO implement Framework::GetCountryCodeByPosition(), see #622 --- iphone/Maps/Classes/SearchVC.h | 4 +-- iphone/Maps/Classes/SearchVC.mm | 53 +++++++++++++++++++-------------- map/framework.cpp | 6 ++++ map/framework.hpp | 3 ++ 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/iphone/Maps/Classes/SearchVC.h b/iphone/Maps/Classes/SearchVC.h index 50640e5a8a..07f6b49965 100644 --- a/iphone/Maps/Classes/SearchVC.h +++ b/iphone/Maps/Classes/SearchVC.h @@ -19,9 +19,7 @@ namespace search { class Result; } UIButton * m_radarButton; UISearchBar * m_searchBar; UITableView * m_table; -// UILabel * m_warningView; - /// Warning view shows only if this text is not nil -// NSString * m_warningViewText; + string m_currentCountryFlagCode; } - (id)initWithFramework:(Framework *)framework andLocationManager:(LocationManager *)lm; diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index da99e45e42..d35c2ae037 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -438,15 +438,20 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) if (m_radarButton.isSelected) cell.accessoryView = nil; else - { // Show flags only when radar mode is disabled + { // Show flags only when radar mode is disabled and feature is not in the same country as the user char const * flagCode = r.GetRegionFlag(); - if (flagCode) + if (flagCode && m_currentCountryFlagCode != flagCode) { UIImage * flagImage = [UIImage imageNamed:[NSString stringWithFormat:@"%s.png", flagCode]]; UIImageView * imgView = [[UIImageView alloc] initWithImage:flagImage]; cell.accessoryView = imgView; [imgView release]; } + else + { + // Reset cached flag for reused cell + cell.accessoryView = nil; + } } return cell; } @@ -503,23 +508,6 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) } } -- (void)updateCompassFor:(UITableViewCell *)cell withResult:(search::Result const &)res andAngle:(double)angle -{ - CompassView * compass = nil; - if (cell.accessoryView == nil) - { - float const h = m_table.rowHeight * 0.6; - compass = [[CompassView alloc] initWithFrame:CGRectMake(0, 0, h, h)]; - cell.accessoryView = compass; - [compass release]; - } - else if ([cell.accessoryView isKindOfClass:[CompassView class]]) - compass = (CompassView *)cell.accessoryView; - - if (compass) - compass.angle = angle; -} - //****************************************************************** //*********** Location manager callbacks *************************** - (void)onLocationStatusChanged:(location::TLocationStatus)newStatus @@ -529,6 +517,10 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) - (void)onGpsUpdate:(location::GpsInfo const &)info { + // Update current country code only once after Search View was opened + if (m_currentCountryFlagCode.empty()) + m_currentCountryFlagCode = m_framework->GetCountryCodeByPosition(info.m_latitude, info.m_longitude); + // Refresh search results with newer location, but // do not search if text is not entered NSString * queryString = m_searchBar.text; @@ -554,10 +546,25 @@ static void OnSearchResultCallback(search::Results const & res, int queryId) search::Result const & res = [g_lastSearchResults get][[m_table indexPathForCell:cell].row]; if (res.GetResultType() == search::Result::RESULT_FEATURE) { - m2::PointD const center = res.GetFeatureCenter(); - double const angle = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(loc.coordinate.longitude), - MercatorBounds::LatToY(loc.coordinate.latitude)), center) + northDeg / 180. * math::pi; - [self updateCompassFor:cell withResult:res andAngle:angle]; + // Show compass only for cells without flags + CompassView * compass = nil; + if (cell.accessoryView == nil) + { + // Create compass view if it wasn't already created + float const h = m_table.rowHeight * 0.6; + compass = [[CompassView alloc] initWithFrame:CGRectMake(0, 0, h, h)]; + cell.accessoryView = compass; + [compass release]; + } + else if ([cell.accessoryView isKindOfClass:[CompassView class]]) + compass = (CompassView *)cell.accessoryView; + + if (compass) + { + m2::PointD const center = res.GetFeatureCenter(); + compass.angle = ang::AngleTo(m2::PointD(MercatorBounds::LonToX(loc.coordinate.longitude), + MercatorBounds::LatToY(loc.coordinate.latitude)), center) + northDeg / 180. * math::pi; + } } } } diff --git a/map/framework.cpp b/map/framework.cpp index af69bffd57..5e35baa118 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -895,3 +895,9 @@ void Framework::GetFeatureTypes(m2::PointD pt, vector & types) const getTypes.GetFeatureTypes(5, types); } + +string Framework::GetCountryCodeByPosition(double lat, double lon) const +{ + // @TODO add valid implementation + return "by"; +} diff --git a/map/framework.hpp b/map/framework.hpp index 23adeca5b5..7c11072f53 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -145,6 +145,9 @@ public: void Search(search::SearchParams const & params); bool GetCurrentPosition(double & lat, double & lon); + /// @return country code in ISO 3166-1 alpha-2 format (two small letters) or empty string + string GetCountryCodeByPosition(double lat, double lon) const; + void SetMaxWorldRect(); void Invalidate(bool doForceUpdate = false);