[ios] Fixed country update in downloader

Closed #163
This commit is contained in:
Alex Zolotarev 2011-04-05 14:08:15 +02:00 committed by Alex Zolotarev
parent d5992c242e
commit 31b55b3d98
2 changed files with 30 additions and 36 deletions

View file

@ -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

View file

@ -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];
}
}