forked from organicmaps/organicmaps
[ios] Updated disable auto download logic.
This commit is contained in:
parent
e915129c9f
commit
ea139eedc8
4 changed files with 32 additions and 26 deletions
|
@ -120,7 +120,6 @@
|
|||
else
|
||||
{
|
||||
[Statistics logEvent:kStatDownloaderDownloadCancel withParameters:@{kStatFrom : kStatSearch}];
|
||||
[MWMMapDownloadDialog pauseAutoDownload:YES];
|
||||
[MWMStorage cancelDownloadNode:m_countryId];
|
||||
}
|
||||
[self showRequest];
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
@interface MWMMapDownloadDialog : UIView
|
||||
|
||||
+ (void)pauseAutoDownload:(BOOL)pause;
|
||||
|
||||
+ (instancetype)dialogForController:(MWMViewController *)controller;
|
||||
|
||||
- (void)processViewportCountryEvent:(storage::TCountryId const &)countryId;
|
||||
|
|
|
@ -15,8 +15,8 @@ extern char const * kAutoDownloadEnabledKey;
|
|||
|
||||
namespace
|
||||
{
|
||||
NSString * const kAutoDownloadPaused = @"AutoDownloadPaused";
|
||||
NSTimeInterval constexpr kAutoDownloadPauseExpiartion = 24 * 60 * 60;
|
||||
NSTimeInterval constexpr kDisableAutoDownloadInterval = 30;
|
||||
NSInteger constexpr kDisableAutoDownloadCount = 3;
|
||||
} // namespace
|
||||
|
||||
using namespace storage;
|
||||
|
@ -34,6 +34,8 @@ using namespace storage;
|
|||
|
||||
@property (nonatomic) MWMCircularProgress * progress;
|
||||
|
||||
@property (nonatomic) NSMutableArray<NSDate *> * skipDownloadTimes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMMapDownloadDialog
|
||||
|
@ -85,7 +87,7 @@ using namespace storage;
|
|||
{
|
||||
bool autoDownloadEnabled = true;
|
||||
(void)Settings::Get(kAutoDownloadEnabledKey, autoDownloadEnabled);
|
||||
if (autoDownloadEnabled && ![MWMMapDownloadDialog isAutoDownloadPaused])
|
||||
if (autoDownloadEnabled)
|
||||
{
|
||||
[Statistics logEvent:kStatDownloaderMapAction
|
||||
withParameters:@{
|
||||
|
@ -125,8 +127,6 @@ using namespace storage;
|
|||
}
|
||||
else
|
||||
{
|
||||
if (nodeAttrs.m_status == NodeStatus::NotDownloaded)
|
||||
[MWMMapDownloadDialog pauseAutoDownload:YES];
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
@ -217,23 +217,27 @@ using namespace storage;
|
|||
|
||||
#pragma mark - Autodownload
|
||||
|
||||
+ (void)pauseAutoDownload:(BOOL)pause
|
||||
- (void)skipDownload
|
||||
{
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
if (pause)
|
||||
[ud setObject:[NSDate date] forKey:kAutoDownloadPaused];
|
||||
else
|
||||
[ud removeObjectForKey:kAutoDownloadPaused];
|
||||
[ud synchronize];
|
||||
}
|
||||
bool autoDownloadEnabled = true;
|
||||
(void)Settings::Get(kAutoDownloadEnabledKey, autoDownloadEnabled);
|
||||
if (!autoDownloadEnabled)
|
||||
return;
|
||||
|
||||
+ (BOOL)isAutoDownloadPaused
|
||||
{
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
NSDate * pausedTime = [ud objectForKey:kAutoDownloadPaused];
|
||||
if (!pausedTime)
|
||||
return NO;
|
||||
return [[NSDate date] timeIntervalSinceDate:pausedTime] < kAutoDownloadPauseExpiartion;
|
||||
NSDate * currentTime = [NSDate date];
|
||||
[self.skipDownloadTimes filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSDate * evaluatedObject, NSDictionary<NSString *, id> * bindings)
|
||||
{
|
||||
return [currentTime timeIntervalSinceDate:evaluatedObject] < kDisableAutoDownloadInterval;
|
||||
}]];
|
||||
[self.skipDownloadTimes addObject:currentTime];
|
||||
if (self.skipDownloadTimes.count >= kDisableAutoDownloadCount)
|
||||
{
|
||||
[self.skipDownloadTimes removeAllObjects];
|
||||
MWMAlertViewController * ac = self.controller.alertController;
|
||||
[ac presentDisableAutoDownloadAlertWithOkBlock:^{
|
||||
Settings::Set(kAutoDownloadEnabledKey, false);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MWMFrameworkStorageObserver
|
||||
|
@ -274,7 +278,7 @@ using namespace storage;
|
|||
{
|
||||
[Statistics logEvent:kStatDownloaderDownloadCancel withParameters:@{kStatFrom : kStatMap}];
|
||||
[self showDownloadRequest];
|
||||
[MWMMapDownloadDialog pauseAutoDownload:YES];
|
||||
[self skipDownload];
|
||||
[MWMStorage cancelDownloadNode:m_countryId];
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +295,6 @@ using namespace storage;
|
|||
kStatScenario : kStatDownload
|
||||
}];
|
||||
[self showInQueue];
|
||||
[MWMMapDownloadDialog pauseAutoDownload:NO];
|
||||
[MWMStorage downloadNode:m_countryId alertController:self.controller.alertController onSuccess:nil];
|
||||
}
|
||||
|
||||
|
@ -307,4 +310,11 @@ using namespace storage;
|
|||
return _progress;
|
||||
}
|
||||
|
||||
- (NSMutableArray<NSDate *> *)skipDownloadTimes
|
||||
{
|
||||
if (!_skipDownloadTimes)
|
||||
_skipDownloadTimes = [@[] mutableCopy];
|
||||
return _skipDownloadTimes;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -268,7 +268,6 @@ typedef NS_ENUM(NSUInteger, Section)
|
|||
[[Statistics instance] logEvent:kStatEventName(kStatSettings, kStatAutoDownload)
|
||||
withParameters:@{kStatValue : (value ? kStatOn : kStatOff)}];
|
||||
Settings::Set(kAutoDownloadEnabledKey, (bool)value);
|
||||
[MWMMapDownloadDialog pauseAutoDownload:NO];
|
||||
break;
|
||||
}
|
||||
// 3D buildings
|
||||
|
|
Loading…
Add table
Reference in a new issue