Merge pull request #2704 from igrechuhin/ig-master

[ios] Added storage space check before download.
This commit is contained in:
Vladimir Byko-Ianko 2016-04-04 12:08:58 +03:00
commit fb22d23502
11 changed files with 76 additions and 21 deletions

View file

@ -27,6 +27,7 @@
- (void)presentPedestrianToastAlert:(BOOL)isFirstLaunch;
- (void)presentIncorrectFeauturePositionAlert;
- (void)presentInternalErrorAlert;
- (void)presentNotEnoughSpaceAlert;
- (void)presentInvalidUserNameOrPasswordAlert;
- (void)presentDisableAutoDownloadAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock;
- (void)presentDownloaderNoConnectionAlertWithOkBlock:(nonnull TMWMVoidBlock)okBlock cancelBlock:(nonnull TMWMVoidBlock)cancelBlock;

View file

@ -89,6 +89,11 @@ static NSString * const kAlertControllerNibIdentifier = @"MWMAlertViewController
[self displayAlert:[MWMAlert internalErrorAlert]];
}
- (void)presentNotEnoughSpaceAlert
{
[self displayAlert:[MWMAlert notEnoughSpaceAlert]];
}
- (void)presentInvalidUserNameOrPasswordAlert
{
[self displayAlert:[MWMAlert invalidUserNameOrPasswordAlert]];

View file

@ -24,6 +24,7 @@
+ (MWMAlert *)pedestrianToastShareAlert:(BOOL)isFirstLaunch;
+ (MWMAlert *)incorrectFeauturePositionAlert;
+ (MWMAlert *)internalErrorAlert;
+ (MWMAlert *)notEnoughSpaceAlert;
+ (MWMAlert *)invalidUserNameOrPasswordAlert;
+ (MWMAlert *)point2PointAlertWithOkBlock:(TMWMVoidBlock)okBlock needToRebuild:(BOOL)needToRebuild;
+ (MWMAlert *)disableAutoDownloadAlertWithOkBlock:(TMWMVoidBlock)okBlock;

View file

@ -122,6 +122,11 @@
return [MWMDefaultAlert internalErrorAlert];
}
+ (MWMAlert *)notEnoughSpaceAlert
{
return [MWMDefaultAlert notEnoughSpaceAlert];
}
+ (MWMAlert *)invalidUserNameOrPasswordAlert
{
return [MWMDefaultAlert invalidUserNameOrPasswordAlert];

View file

@ -9,6 +9,7 @@
+ (instancetype)internalRoutingErrorAlert;
+ (instancetype)incorrectFeauturePositionAlert;
+ (instancetype)internalErrorAlert;
+ (instancetype)notEnoughSpaceAlert;
+ (instancetype)invalidUserNameOrPasswordAlert;
+ (instancetype)noCurrentPositionAlert;
+ (instancetype)pointsInDifferentMWMAlert;

View file

@ -168,6 +168,18 @@ static NSString * const kDefaultAlertNibName = @"MWMDefaultAlert";
rightButtonAction:nil];
}
+ (instancetype)notEnoughSpaceAlert
{
kStatisticsEvent = @"Not Enough Space Alert";
MWMDefaultAlert * alert = [self defaultAlertWithTitle:@"migration_download_error_dialog"
message:@"migration_no_space_message"
rightButtonTitle:@"ok"
leftButtonTitle:nil
rightButtonAction:nil];
[alert setNeedsCloseAlertAfterEnterBackground];
return alert;
}
+ (instancetype)invalidUserNameOrPasswordAlert
{
kStatisticsEvent = @"Invalid User Name or Password Alert";

View file

@ -22,7 +22,7 @@ using namespace storage;
@interface MWMStorage ()
+ (void)performAction:(TMWMVoidBlock)action alertController:(MWMAlertViewController *)alertController;
+ (void)checkConnectionAndPerformAction:(TMWMVoidBlock)action alertController:(MWMAlertViewController *)alertController;
@end
@ -103,7 +103,7 @@ using namespace storage;
[view setProgress:static_cast<CGFloat>(progress.first) / progress.second];
};
[MWMStorage performAction:^
[MWMStorage checkConnectionAndPerformAction:^
{
self->m_countryId = f.PreMigrate(position, onStatusChanged, onProgressChanged);
if (self->m_countryId != kInvalidCountryId)

View file

@ -5,6 +5,8 @@
#include "platform/platform.hpp"
#include "storage/storage_helpers.hpp"
namespace
{
NSString * const kStorageCanShowNoWifiAlert = @"StorageCanShowNoWifiAlert";
@ -23,13 +25,12 @@ using namespace storage;
+ (void)downloadNode:(TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess
{
[self performAction:^
[self checkEnoughSpaceFor:countryId andPerformAction:^
{
GetFramework().Storage().DownloadNode(countryId);
if (onSuccess)
onSuccess();
}
alertController:alertController];
} alertController:alertController];
}
+ (void)retryDownloadNode:(TCountryId const &)countryId
@ -39,11 +40,10 @@ using namespace storage;
+ (void)updateNode:(TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController
{
[self performAction:^
[self checkEnoughSpaceFor:countryId andPerformAction:^
{
GetFramework().Storage().UpdateNode(countryId);
}
alertController:alertController];
} alertController:alertController];
}
+ (void)deleteNode:(TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController
@ -71,20 +71,46 @@ using namespace storage;
GetFramework().ShowNode(countryId);
}
+ (void)downloadNodes:(storage::TCountriesVec const &)countryIds alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess
+ (void)downloadNodes:(TCountriesVec const &)countryIds
alertController:(MWMAlertViewController *)alertController
onSuccess:(TMWMVoidBlock)onSuccess
{
[self performAction:[countryIds, onSuccess]
size_t requiredSize = accumulate(countryIds.begin(), countryIds.end(), kMaxMwmSizeBytes,
[](size_t const & size, TCountryId const & countryId)
{
NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(countryId, nodeAttrs);
return size + nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize;
});
if (GetPlatform().GetWritableStorageStatus(requiredSize) == Platform::TStorageStatus::STORAGE_OK)
{
auto & s = GetFramework().Storage();
for (auto const & countryId : countryIds)
s.DownloadNode(countryId);
if (onSuccess)
onSuccess();
[self checkConnectionAndPerformAction:[countryIds, onSuccess]
{
auto & s = GetFramework().Storage();
for (auto const & countryId : countryIds)
s.DownloadNode(countryId);
if (onSuccess)
onSuccess();
} alertController:alertController];
}
else
{
[alertController presentNotEnoughSpaceAlert];
}
alertController:alertController];
}
+ (void)performAction:(TMWMVoidBlock)action alertController:(MWMAlertViewController *)alertController
+ (void)checkEnoughSpaceFor:(TCountryId const &)countryId
andPerformAction:(TMWMVoidBlock)action
alertController:(MWMAlertViewController *)alertController
{
if (IsEnoughSpaceForDownload(countryId, GetFramework().Storage()))
[self checkConnectionAndPerformAction:action alertController:alertController];
else
[alertController presentNotEnoughSpaceAlert];
}
+ (void)checkConnectionAndPerformAction:(TMWMVoidBlock)action
alertController:(MWMAlertViewController *)alertController
{
switch (Platform::ConnectionStatus())
{

View file

@ -240,8 +240,7 @@ void Framework::StopLocationFollow()
bool Framework::IsEnoughSpaceForMigrate() const
{
uint64_t const kSpaceSize = 100 /*Mb*/ * 1024 * 1024;
return GetPlatform().GetWritableStorageStatus(kSpaceSize) == Platform::TStorageStatus::STORAGE_OK;
return GetPlatform().GetWritableStorageStatus(kMaxMwmSizeBytes) == Platform::TStorageStatus::STORAGE_OK;
}
TCountryId Framework::PreMigrate(ms::LatLon const & position,

View file

@ -24,8 +24,11 @@ bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & stor
{
NodeAttrs nodeAttrs;
storage.GetNodeAttrs(countryId, nodeAttrs);
size_t constexpr kDownloadExtraSpaceSize = 1 /*Mb*/ * 1024 * 1024;
size_t const downloadSpaceSize = kDownloadExtraSpaceSize + nodeAttrs.m_mwmSize;
// Mwm size is less than kMaxMwmSizeBytes. In case of map update at first we download updated map
// and only after that we do delete the obsolete map. So in such a case we might need up to
// kMaxMwmSizeBytes of extra space.
size_t const downloadSpaceSize =
kMaxMwmSizeBytes + nodeAttrs.m_mwmSize - nodeAttrs.m_localMwmSize;
return GetPlatform().GetWritableStorageStatus(downloadSpaceSize) ==
Platform::TStorageStatus::STORAGE_OK;
}

View file

@ -11,6 +11,8 @@ namespace storage
class CountryInfoGetter;
class Storage;
size_t constexpr kMaxMwmSizeBytes = 100 /*Mb*/ * 1024 * 1024;
/// \returns true if |position| is covered by a downloaded mwms and false otherwise.
/// \note |position| has coordinates in mercator.
/// \note This method takes into acount only maps enumerated in countries.txt.