[iOS] Do not delete country before updating download.

This commit is contained in:
vng 2012-07-08 22:55:43 -07:00 committed by Alex Zolotarev
parent 7a8ffa56db
commit 36e2064bc1
4 changed files with 38 additions and 36 deletions

View file

@ -174,8 +174,7 @@ namespace android
void Framework::ShowCountry(storage::TIndex const & idx)
{
storage::Country const & country = m_work.Storage().CountryByIndex(idx);
m2::RectD const r = m_work.GetCountryBounds(country.GetFile().m_fileName);
m2::RectD const r = m_work.GetCountryBounds(idx);
m_doLoadState = false;

View file

@ -11,12 +11,15 @@
#include "../../platform/platform.hpp"
#define MAX_3G_MEGABYTES 50
#define MB 1024*1024
using namespace storage;
static TIndex CalculateIndex(TIndex const & parentIndex, NSIndexPath * indexPath)
{
TIndex index = parentIndex;
@ -51,8 +54,10 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
return ours == theirsFixed;
}
@implementation CountriesViewController
- (void) onAboutButton:(id)sender
{
// display WebView with About text
@ -114,11 +119,13 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
TIndex const index = CalculateIndex(m_index, indexPath);
storage::Storage & s = GetFramework().Storage();
if (s.CountryStatus(index) == EOnDisk)
TIndex const index = CalculateIndex(m_index, indexPath);
Framework & frm = GetFramework();
if (frm.GetCountryStatus(index) == EOnDisk)
{
m2::RectD const bounds = s.CountryBounds(index);
m2::RectD const bounds = frm.GetCountryBounds(index);
[[[MapsAppDelegate theApp] settingsManager] hide];
[[MapsAppDelegate theApp].m_mapViewController ZoomToRect:bounds];
}
@ -133,7 +140,9 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
{
cell.accessoryView = nil;
storage::Storage & s = GetFramework().Storage();
Framework & frm = GetFramework();
Storage & s = frm.Storage();
string const & flag = s.CountryFlag(countryIndex);
if (!flag.empty())
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%s.png", flag.c_str()]];
@ -141,7 +150,7 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
// do not show status for parent categories
if (cell.reuseIdentifier != @"ParentCell")
{
switch (s.CountryStatus(countryIndex))
switch (frm.GetCountryStatus(countryIndex))
{
case EOnDisk:
case EOnDiskOutOfDate:
@ -185,17 +194,6 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours)
break;
}
case EGeneratingIndex:
{
cell.textLabel.textColor = [UIColor colorWithRed:52.f/255.f
green:43.f/255.f
blue:182.f/255.f
alpha:1.f];
cell.detailTextLabel.text = NSLocalizedString(@"Generating search index ...",
@"Settings/Downloader - info for country which started downloading");
break;
}
case EDownloadFailed:
cell.textLabel.textColor = [UIColor redColor];
cell.detailTextLabel.text = NSLocalizedString(@"download_has_failed", @"Settings/Downloader - info for country when download fails");
@ -260,20 +258,18 @@ UITableViewCell * g_clickedCell = nil;
if (buttonIndex == 0)
{
// Delete country
storage::Storage & s = GetFramework().Storage();
switch (s.CountryStatus(g_clickedIndex))
Framework & frm = GetFramework();
switch (frm.GetCountryStatus(g_clickedIndex))
{
case EOnDiskOutOfDate:
s.DeleteCountry(g_clickedIndex);
// no break here!
case ENotDownloaded:
case EDownloadFailed:
s.DownloadCountry(g_clickedIndex);
frm.Storage().DownloadCountry(g_clickedIndex);
break;
default:
s.DeleteCountry(g_clickedIndex);
frm.DeleteCountry(g_clickedIndex);
// remove "zoom to country" icon
g_clickedCell.accessoryType = UITableViewCellAccessoryNone;
}
@ -323,9 +319,12 @@ UITableViewCell * g_clickedCell = nil;
// deselect the current row (don't keep the table selection persistent)
[tableView deselectRowAtIndexPath: indexPath animated:YES];
UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath];
// Push the new table view on the stack
TIndex const index = CalculateIndex(m_index, indexPath);
storage::Storage & s = GetFramework().Storage();
Framework & frm = GetFramework();
Storage & s = frm.Storage();
if (s.CountriesCount(index))
{
CountriesViewController * newController = [[CountriesViewController alloc] initWithIndex: index andHeader: cell.textLabel.text];
@ -339,7 +338,7 @@ UITableViewCell * g_clickedCell = nil;
g_clickedIndex = index;
g_clickedCell = cell;
switch (s.CountryStatus(index))
switch (frm.GetCountryStatus(index))
{
case EOnDisk:
{
@ -416,11 +415,7 @@ UITableViewCell * g_clickedCell = nil;
case EInQueue:
// cancel download
s.DeleteCountry(index);
break;
case EGeneratingIndex:
// we can't stop index generation at this moment
frm.DeleteCountry(index);
break;
default:

View file

@ -28,6 +28,8 @@
#include "../std/target_os.hpp"
#include "../std/vector.hpp"
using namespace storage;
void Framework::AddMap(string const & file)
{
@ -212,7 +214,7 @@ Framework::~Framework()
ClearBookmarks();
}
void Framework::DeleteCountry(storage::TIndex const & index)
void Framework::DeleteCountry(TIndex const & index)
{
if (!m_storage.DeleteFromDownloader(index))
{
@ -224,11 +226,11 @@ void Framework::DeleteCountry(storage::TIndex const & index)
m_storage.NotifyStatusChanged(index);
}
storage::TStatus Framework::GetCountryStatus(storage::TIndex const & index) const
TStatus Framework::GetCountryStatus(TIndex const & index) const
{
using namespace storage;
storage::TStatus res = m_storage.CountryStatus(index);
TStatus res = m_storage.CountryStatus(index);
if (res == EUnknown)
{
@ -267,6 +269,11 @@ m2::RectD Framework::GetCountryBounds(string const & file) const
return r;
}
m2::RectD Framework::GetCountryBounds(TIndex const & index) const
{
return GetCountryBounds(m_storage.CountryByIndex(index).GetFile().m_fileName);
}
void Framework::UpdateAfterDownload(string const & file)
{
m2::RectD rect;

View file

@ -150,6 +150,7 @@ public:
/// Get country rect from borders (not from mwm file).
/// @param[in] file Pass country file name without extension as an id.
m2::RectD GetCountryBounds(string const & file) const;
m2::RectD GetCountryBounds(storage::TIndex const & index) const;
//@}
void AddBookmark(string const & category, Bookmark const & bm);