diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index 4cfa4a1011..debe36453d 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -19,9 +19,9 @@ using namespace storage; static TIndex CalculateIndex(TIndex const & parentIndex, NSIndexPath * indexPath) { TIndex index = parentIndex; - if (index.m_group == -1) + if (index.m_group == TIndex::INVALID) index.m_group = indexPath.row; - else if (index.m_country == -1) + else if (index.m_country == TIndex::INVALID) index.m_country = indexPath.row; else index.m_region = indexPath.row; @@ -30,27 +30,14 @@ static TIndex CalculateIndex(TIndex const & parentIndex, NSIndexPath * indexPath static NSInteger RowFromIndex(TIndex const & index) { - if (index.m_region != -1) + if (index.m_region != TIndex::INVALID) return index.m_region; - else if (index.m_country != -1) + else if (index.m_country != TIndex::INVALID) return index.m_country; else return index.m_group; } -static bool IsOurIndex(TIndex const & theirs, TIndex const & ours) -{ - TIndex theirsFixed = theirs; - if (theirsFixed.m_region != -1) - theirsFixed.m_region = -1; - else if (theirsFixed.m_country != -1) - theirsFixed.m_country = -1; - else - theirsFixed.m_group = -1; - - return ours == theirsFixed; -} - @implementation CountriesViewController - (void) OnCloseButton:(id)sender @@ -364,24 +351,18 @@ TIndex g_clickedIndex; - (void) OnCountryChange: (TIndex const &) index { - if (IsOurIndex(index, m_index)) - { - UITableView * tableView = (UITableView *)self.view; - UITableViewCell * cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: RowFromIndex(index) inSection: 0]]; - if (cell) - [self UpdateCell: cell forCountry: index]; - } + UITableView * tableView = (UITableView *)self.view; + UITableViewCell * cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: RowFromIndex(index) inSection: 0]]; + if (cell) + [self UpdateCell: cell forCountry: index]; } - (void) OnDownload: (TIndex const &) index withProgress: (TDownloadProgress const &) progress { - if (IsOurIndex(index, m_index)) - { - UITableView * tableView = (UITableView *)self.view; - UITableViewCell * cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: RowFromIndex(index) inSection: 0]]; - if (cell) - cell.detailTextLabel.text = [NSString stringWithFormat: @"Downloading %qu%%, touch to cancel", progress.first * 100 / progress.second]; - } + UITableView * tableView = (UITableView *)self.view; + UITableViewCell * cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: RowFromIndex(index) inSection: 0]]; + if (cell) + cell.detailTextLabel.text = [NSString stringWithFormat: @"Downloading %qu%%, touch to cancel", progress.first * 100 / progress.second]; } @end diff --git a/iphone/Maps/Settings/SettingsManager.mm b/iphone/Maps/Settings/SettingsManager.mm index 36ce125f8f..0f688b9f36 100644 --- a/iphone/Maps/Settings/SettingsManager.mm +++ b/iphone/Maps/Settings/SettingsManager.mm @@ -21,12 +21,25 @@ using namespace storage; [super dealloc]; } -- (void) OnCountryChange: (TIndex const &) index +/// Get right controller from the stack +- (UIViewController *) ControllerByIndex:(TIndex const &)index +{ + NSArray * controllers = [m_navController viewControllers]; + if (index.m_region != TIndex::INVALID && [controllers count] >= 3) + return [controllers objectAtIndex:2]; + else if (index.m_country != TIndex::INVALID && [controllers count] >= 2) + return [controllers objectAtIndex:1]; + else if (index.m_group != TIndex::INVALID && [controllers count] >= 1) + return [controllers objectAtIndex:0]; + return nil; +} + +- (void) OnCountryChange: (TIndex const &)index { if (m_navController) { - UIViewController * controller = m_navController.topViewController; - if ([controller respondsToSelector:@selector(OnCountryChange:)]) + UIViewController * controller = [self ControllerByIndex:index]; + if (controller && [controller respondsToSelector:@selector(OnCountryChange:)]) [(CountriesViewController *)controller OnCountryChange: index]; } } @@ -35,8 +48,8 @@ using namespace storage; { if (m_navController) { - UIViewController * controller = m_navController.topViewController; - if ([controller respondsToSelector:@selector(OnDownload:withProgress:)]) + UIViewController * controller = [self ControllerByIndex:index]; + if (controller && [controller respondsToSelector:@selector(OnDownload:withProgress:)]) [(CountriesViewController *)controller OnDownload: index withProgress: progress]; } }