From b1f3746bd71e620c5b09f064f00bfbb2b48e528b Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 17 Nov 2011 19:46:25 +0300 Subject: [PATCH] [ios] Closes #328 - Delete old maps dialog. @TODO Fix displayed message --- indexer/data_header.hpp | 3 +- iphone/Maps/Classes/EAGLView.h | 3 +- iphone/Maps/Classes/MapViewController.h | 7 +-- iphone/Maps/Classes/MapViewController.mm | 8 ++- .../Maps/Settings/CountriesViewController.mm | 4 +- iphone/Maps/Settings/SettingsManager.h | 10 ++-- iphone/Maps/Settings/SettingsManager.mm | 49 +++++++++++++------ map/framework.cpp | 27 ++++++++++ map/framework.hpp | 7 ++- 9 files changed, 82 insertions(+), 36 deletions(-) diff --git a/indexer/data_header.hpp b/indexer/data_header.hpp index f15ea6cd62..b3d945b697 100644 --- a/indexer/data_header.hpp +++ b/indexer/data_header.hpp @@ -62,7 +62,8 @@ namespace feature enum Version { v1, // April 2011 - v2 // November 2011 + v2, // November 2011 + latestVersion = v2 }; inline Version GetVersion() const { return m_ver; } diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h index b58cb12e0b..9268fdfbe0 100644 --- a/iphone/Maps/Classes/EAGLView.h +++ b/iphone/Maps/Classes/EAGLView.h @@ -1,12 +1,13 @@ #import #import #import -#import "MapViewController.h" #include "../../std/shared_ptr.hpp" #include "RenderBuffer.hpp" class Framework; +class VideoTimer; +class RenderPolicy; namespace iphone { diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index 392db6822e..09083542c1 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -2,12 +2,7 @@ #import "LocationManager.h" #include "../../geometry/point2d.hpp" -#include "../../yg/texture.hpp" -#include "../../map/framework_factory.hpp" -#include "../../map/drawer_yg.hpp" -#include "../../map/navigator.hpp" -#include "../../map/feature_vec_model.hpp" -#include "../../std/shared_ptr.hpp" +#include "../../geometry/rect2d.hpp" @interface MapViewController : UIViewController { diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index bfae6f09ad..d5aa23bd9b 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -5,10 +5,8 @@ #import "../Settings/SettingsManager.h" #include "RenderContext.hpp" -#include "../../geometry/rect2d.hpp" -#include "../../yg/internal/opengl.hpp" -#include "../../yg/screen.hpp" -#include "../../map/drawer_yg.hpp" + +#include "../../map/framework_factory.hpp" @implementation MapViewController @@ -93,7 +91,7 @@ Framework * m_framework = NULL; - (IBAction)OnSettingsClicked:(id)sender { - [[[MapsAppDelegate theApp] settingsManager] Show:self WithStorage:&m_framework->Storage()]; + [[[MapsAppDelegate theApp] settingsManager] show:self withFramework:m_framework]; } - (IBAction)OnSearchClicked:(id)sender diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index cecd86e9bc..ae733f36a7 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -71,7 +71,7 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours) - (void) onCloseButton:(id)sender { - [[[MapsAppDelegate theApp] settingsManager] Hide]; + [[[MapsAppDelegate theApp] settingsManager] hide]; } - (id) initWithStorage: (Storage &)storage andIndex: (TIndex const &) index andHeader: (NSString *)header @@ -119,7 +119,7 @@ static bool IsOurIndex(TIndex const & theirs, TIndex const & ours) if (m_storage->CountryStatus(index) == EOnDisk) { m2::RectD const bounds = m_storage->CountryBounds(index); - [[[MapsAppDelegate theApp] settingsManager] Hide]; + [[[MapsAppDelegate theApp] settingsManager] hide]; [[MapsAppDelegate theApp].m_mapViewController ZoomToRect:bounds]; } } diff --git a/iphone/Maps/Settings/SettingsManager.h b/iphone/Maps/Settings/SettingsManager.h index 0563bc6b80..a762a6a258 100644 --- a/iphone/Maps/Settings/SettingsManager.h +++ b/iphone/Maps/Settings/SettingsManager.h @@ -1,17 +1,17 @@ #import #import -namespace storage { class Storage; } +class Framework; /// Responsible for all settings dialogs -@interface SettingsManager : NSObject +@interface SettingsManager : NSObject { - storage::Storage * m_storage; + Framework * m_framework; UINavigationController * m_navigationController; } // TODO: Refactor SettingsManager.Show: remove storage. -- (void) Show: (UIViewController *)prevController WithStorage: (storage::Storage *)storage; -- (void) Hide; +- (void) show:(UIViewController *)prevController withFramework:(Framework *)framework; +- (void) hide; @end diff --git a/iphone/Maps/Settings/SettingsManager.mm b/iphone/Maps/Settings/SettingsManager.mm index dbba5283cb..ae82369dd2 100644 --- a/iphone/Maps/Settings/SettingsManager.mm +++ b/iphone/Maps/Settings/SettingsManager.mm @@ -3,18 +3,12 @@ #import "MapViewController.h" #import "MapsAppDelegate.h" -#include "../../../storage/storage.hpp" +#include "../../../map/framework.hpp" #include "../../../std/bind.hpp" using namespace storage; -// @TODO update data to new format -// NSLocalizedString(@"Upgrade maps", @"Downloader/Upgrade message title") -// NSLocalizedString(@"MapsWithMe uses new, fresh and more compact maps. For example, USA, Germany, France, Canada and Russia are splitted to smaller States/Regions. But to use new maps you should delete all previously downloaded data and download new maps.", @"Downloader/Upgrade dialog message") -// NSLocalizedString(@"Delete old maps and download new maps", @"Downloader/Upgrade OK button") -// NSLocalizedString(@"Do nothing at the moment", @"Downloader/Upgrade Cancel button") - // @TODO advertisement banner // NSLocalizedString(@"MapsWithMe Pro", @"Banner title") // NSLocalizedString(@"One step ahead! Cool search feature! Bla bla bla", @"Banner message") @@ -76,13 +70,12 @@ using namespace storage; [(CountriesViewController *)controller OnDownload: index withProgress: progress]; } -// Currently displays only countries to download -- (void) Show:(UIViewController *)prevController WithStorage:(Storage *)storage +- (void) show:(UIViewController *)prevController withFramework:(Framework *)framework { - m_storage = storage; + m_framework = framework; CountriesViewController * countriesController = [[[CountriesViewController alloc] - initWithStorage:*m_storage andIndex:TIndex() andHeader:NSLocalizedString(@"Download", @"Settings/Downloader - Main downloader window title")] autorelease]; + initWithStorage:framework->Storage() andIndex:TIndex() andHeader:NSLocalizedString(@"Download", @"Settings/Downloader - Main downloader window title")] autorelease]; m_navigationController = [[UINavigationController alloc] initWithRootViewController:countriesController]; // Subscribe to storage callbacks AND load country names after calling Storage::Subscribe() @@ -96,21 +89,47 @@ using namespace storage; SEL progressSel = @selector(OnCountryDownload:withProgress:); TProgressFunc progressImpl = (TProgressFunc)[self methodForSelector:progressSel]; - m_storage->Subscribe(bind(changeImpl, self, changeSel, _1), bind(progressImpl, self, progressSel, _1, _2)); + framework->Storage().Subscribe(bind(changeImpl, self, changeSel, _1), bind(progressImpl, self, progressSel, _1, _2)); } // display controller only when countries are loaded [prevController presentModalViewController:m_navigationController animated:YES]; + + // display upgrade/delete old maps dialog if necessary + if (framework->NeedToDeleteOldMaps()) + { + UIActionSheet * dialog = [[UIActionSheet alloc] + initWithTitle:NSLocalizedString(@"MapsWithMe uses new, fresh and more compact maps. For example, USA, Germany, France, Canada and Russia are splitted to smaller States/Regions. But to use new maps you should delete all previously downloaded data and download new maps.", @"Downloader/Upgrade dialog message") + delegate:self + cancelButtonTitle:NSLocalizedString(@"Do nothing at the moment", @"Downloader/Upgrade Cancel button") + destructiveButtonTitle:NSLocalizedString(@"Delete old and download new maps", @"Downloader/Upgrade OK button") + otherButtonTitles:nil]; + [dialog showInView:m_navigationController.view]; + [dialog release]; + } } // Hides all opened settings windows -- (void) Hide +- (void) hide { - m_storage->Unsubscribe(); + m_framework->Storage().Unsubscribe(); [m_navigationController dismissModalViewControllerAnimated:YES]; [m_navigationController release], m_navigationController = nil; - m_storage = nil; + m_framework = nil; +} + +// Called from Upgrade/Delete old maps dialog +- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if (buttonIndex == 0) + { // delete old maps and show downloader + m_framework->DeleteOldMaps(); + } + else + { // User don't want to upgrade at the moment - so be it. + [self hide]; + } } @end diff --git a/map/framework.cpp b/map/framework.cpp index edf44844a5..59e3cfc389 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -626,3 +626,30 @@ void Framework::SetupMeasurementSystem() Invalidate(); } +// 0 - old April version which we should delete +#define MAXIMUM_VERSION_TO_DELETE 0 + +bool Framework::NeedToDeleteOldMaps() const +{ + return m_lowestMapVersion == MAXIMUM_VERSION_TO_DELETE; +} + +void Framework::DeleteOldMaps() +{ + Platform & p = GetPlatform(); + vector maps; + p.GetFilesInDir(p.WritableDir(), "*" DATA_FILE_EXTENSION, maps); + for (vector::iterator it = maps.begin(); it != maps.end(); ++it) + { + feature::DataHeader header; + LoadMapHeader(p.GetReader(*it), header); + if (header.GetVersion() <= MAXIMUM_VERSION_TO_DELETE) + { + LOG(LINFO, ("Deleting old map", *it)); + RemoveMap(*it); + FileWriter::DeleteFileX(p.WritablePathForFile(*it)); + InvalidateRect(header.GetBounds()); + } + } + m_lowestMapVersion = MAXIMUM_VERSION_TO_DELETE + 1; +} diff --git a/map/framework.hpp b/map/framework.hpp index b2292040ad..b4eeb2dc13 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -109,7 +109,12 @@ public: Framework(); virtual ~Framework(); - int GetLowestLoadedMapVersion() const { return m_lowestMapVersion; } + /// @name Used on iPhone for upgrade from April 1.0.1 version + //@{ + /// @return true if client should display delete old maps dialog before using downloader + bool NeedToDeleteOldMaps() const; + void DeleteOldMaps(); + //@} storage::Storage & Storage() { return m_storage; }