[new downloader][ios] Added downloader statuses support.

This commit is contained in:
Ilya Grechuhin 2016-02-19 15:55:17 +03:00 committed by Sergey Yershov
parent 372c6b7811
commit 751204a9b7
31 changed files with 390 additions and 174 deletions

View file

@ -4,6 +4,7 @@
#import "MWMCircularProgress.h"
#import "MWMDownloadMapRequest.h"
#import "MWMDownloadMapRequestView.h"
#import "MWMStorage.h"
#import "Statistics.h"
#include "Framework.h"
@ -76,13 +77,13 @@
}
else
{
m_countryId = kInvalidCountryId;
m_countryId = storage::kInvalidCountryId;
auto const & countryInfoGetter = f.CountryInfoGetter();
LocationManager * locationManager = [MapsAppDelegate theApp].m_locationManager;
if (locationManager.lastLocationIsValid)
m_countryId = countryInfoGetter.GetRegionCountryId(locationManager.lastLocation.mercator);
if (m_countryId != kInvalidCountryId)
if (m_countryId != storage::kInvalidCountryId)
{
storage::NodeAttrs attrs;
s.GetNodeAttrs(m_countryId, attrs);
@ -121,15 +122,14 @@
{
[[Statistics instance] logEvent:kStatEventName(kStatDownloadRequest, kStatButton)
withParameters:@{kStatValue : kStatProgress}];
auto & s = GetFramework().Storage();
if (progress.state == MWMCircularProgressStateFailed)
{
s.RetryDownloadNode(m_countryId);
[MWMStorage retryDownloadNode:m_countryId];
self.progressView.state = MWMCircularProgressStateSpinner;
}
else
{
s.CancelDownloadNode(m_countryId);
[MWMStorage cancelDownloadNode:m_countryId];
}
[self showRequest];
}
@ -139,7 +139,7 @@
- (IBAction)downloadMapTouchUpInside:(nonnull UIButton *)sender
{
[[Statistics instance] logEvent:kStatEventName(kStatDownloadRequest, kStatDownloadMap)];
[MapsAppDelegate downloadNode:m_countryId alertController:self.delegate.alertController onSuccess:^
[MWMStorage downloadNode:m_countryId alertController:self.delegate.alertController onSuccess:^
{
[self showRequest];
self.progressView.state = MWMCircularProgressStateSpinner;

View file

@ -1,5 +1,6 @@
#import "Common.h"
#import "MapsAppDelegate.h"
#import "MWMAlertViewController.h"
#import "MWMAuthorizationCommon.h"
#import "MWMAuthorizationLoginViewController.h"
#import "MWMAuthorizationWebViewLoginViewController.h"

View file

@ -8,12 +8,14 @@
#import "MWMBottomMenuView.h"
#import "MWMBottomMenuViewController.h"
#import "MWMButton.h"
#import "MWMFrameworkListener.h"
#import "MWMFrameworkObservers.h"
#import "MWMMapViewControlsManager.h"
#import "MWMSearchManager.h"
#import "SettingsAndMoreVC.h"
#import "Statistics.h"
#import "UIImageView+Coloring.h"
#import "UIColor+MapsMeColor.h"
#import "UIImageView+Coloring.h"
#import "UIKitCategories.h"
#import "3party/Alohalytics/src/alohalytics_objc.h"

View file

@ -1,9 +1,13 @@
#import "Common.h"
#import "EAGLView.h"
#import "MWMAPIBar.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMAlertViewController.h"
#import "MWMAPIBar.h"
#import "MWMBottomMenuViewController.h"
#import "MWMButton.h"
#import "MWMFrameworkListener.h"
#import "MWMFrameworkObservers.h"
#import "MWMMapViewControlsManager.h"
#import "MWMPlacePageEntity.h"
#import "MWMPlacePageViewManager.h"
@ -12,8 +16,6 @@
#import "MWMSearchManager.h"
#import "MWMSearchView.h"
#import "MWMZoomButtons.h"
#import "MapViewController.h"
#import "MapsAppDelegate.h"
#import "RouteState.h"
#import "Statistics.h"

View file

@ -3,6 +3,7 @@
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMStorage.h"
#import "Statistics.h"
#import "TimeUtils.h"
@ -65,7 +66,7 @@ using namespace storage;
NSString * notificationCountryId = userInfo[kDownloadMapCountryId];
TCountryId const countryId = notificationCountryId.UTF8String;
[MapsAppDelegate downloadNode:countryId alertController:mapViewController.alertController onSuccess:^
[MWMStorage downloadNode:countryId alertController:mapViewController.alertController onSuccess:^
{
auto & f = GetFramework();
double const defaultZoom = 10;

View file

@ -2,6 +2,4 @@
@interface MWMMapDownloaderLargeCountryTableViewCell : MWMMapDownloaderTableViewCell
- (void)setMapCountText:(NSString *)text;
@end

View file

@ -15,9 +15,12 @@
[super layoutSubviews];
}
- (void)setMapCountText:(NSString *)text
#pragma mark - Config
- (void)config:(storage::NodeAttrs const &)nodeAttrs
{
self.mapsCount.text = text;
[super config:nodeAttrs];
self.mapsCount.text = @(nodeAttrs.m_mwmCounter).stringValue;
}
#pragma mark - Properties

View file

@ -2,6 +2,6 @@
@interface MWMMapDownloaderPlaceTableViewCell : MWMMapDownloaderTableViewCell
- (void)setAreaText:(NSString *)text;
@property (nonatomic) BOOL needDisplayArea;
@end

View file

@ -16,12 +16,16 @@
[super layoutSubviews];
}
- (void)setAreaText:(NSString *)text
#pragma mark - Config
- (void)config:(storage::NodeAttrs const &)nodeAttrs
{
self.area.text = text;
BOOL const isAreaHidden = (text.length == 0);
self.area.hidden = isAreaHidden;
self.titleBottomOffset.priority = isAreaHidden ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow;
[super config:nodeAttrs];
BOOL const isAreaVisible = (self.needDisplayArea && nodeAttrs.m_parentInfo.size() == 1);
if (isAreaVisible)
self.area.text = @(nodeAttrs.m_parentInfo[0].m_localName.c_str());
self.area.hidden = !isAreaVisible;
self.titleBottomOffset.priority = isAreaVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh;
}
#pragma mark - Properties

View file

@ -1,10 +1,15 @@
#import "MWMMapDownloaderProtocol.h"
#import "MWMTableViewCell.h"
#include "storage/storage.hpp"
@interface MWMMapDownloaderTableViewCell : MWMTableViewCell
@property (nonatomic, readonly) CGFloat estimatedHeight;
@property (weak, nonatomic) id<MWMMapDownloaderProtocol> delegate;
- (void)setTitleText:(NSString *)text;
- (void)setDownloadSizeText:(NSString *)text;
- (void)registerObserver;
- (void)config:(storage::NodeAttrs const &)nodeAttrs;
- (void)setCountryId:(storage::TCountryId const &)countryId;
@end

View file

@ -1,29 +1,51 @@
#import "Common.h"
#import "MWMCircularProgress.h"
#import "MWMFrameworkListener.h"
#import "MWMMapDownloaderTableViewCell.h"
@interface MWMMapDownloaderTableViewCell () <MWMCircularProgressProtocol>
#include "Framework.h"
@interface MWMMapDownloaderTableViewCell () <MWMFrameworkStorageObserver, MWMCircularProgressProtocol>
@property (nonatomic) MWMCircularProgress * progressView;
@property (weak, nonatomic) IBOutlet UIView * stateWrapper;
@property (weak, nonatomic) IBOutlet UILabel * title;
@property (weak, nonatomic) IBOutlet UILabel * downloadSize;
@property (nonatomic) BOOL isObserver;
@end
@implementation MWMMapDownloaderTableViewCell
{
storage::TCountryId m_countryId;
}
#pragma mark - Properties
- (void)awakeFromNib
{
[super awakeFromNib];
[self reset];
}
- (void)prepareForReuse
{
[super prepareForReuse];
[self reset];
}
- (void)reset
{
self.progressView = [[MWMCircularProgress alloc] initWithParentView:self.stateWrapper];
self.progressView.delegate = self;
[self.progressView setImage:[UIImage imageNamed:@"ic_download"] forState:MWMCircularProgressStateNormal];
[self.progressView setImage:[UIImage imageNamed:@"ic_download"] forState:MWMCircularProgressStateSelected];
[self.progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateProgress];
[self.progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateSpinner];
[self.progressView setImage:[UIImage imageNamed:@"ic_download_error"] forState:MWMCircularProgressStateFailed];
[self.progressView setImage:[UIImage imageNamed:@"ic_check"] forState:MWMCircularProgressStateCompleted];
m_countryId = kInvalidCountryId;
}
- (void)layoutSubviews
@ -34,21 +56,97 @@
[super layoutSubviews];
}
- (void)setTitleText:(NSString *)text
#pragma mark - Config
- (void)config:(storage::NodeAttrs const &)nodeAttrs
{
self.title.text = text;
[self configProgressView:nodeAttrs];
self.title.text = @(nodeAttrs.m_nodeLocalName.c_str());
self.downloadSize.text = formattedSize(nodeAttrs.m_mwmSize);
}
- (void)setDownloadSizeText:(NSString *)text
- (void)configProgressView:(const storage::NodeAttrs &)nodeAttrs
{
self.downloadSize.text = text;
switch (nodeAttrs.m_status)
{
case NodeStatus::NotDownloaded:
self.progressView.state = MWMCircularProgressStateNormal;
break;
case NodeStatus::Downloading:
self.progressView.progress = static_cast<CGFloat>(nodeAttrs.m_downloadingProgress) / 100.0;
break;
case NodeStatus::InQueue:
self.progressView.state = MWMCircularProgressStateSpinner;
break;
case NodeStatus::Undefined:
case NodeStatus::Error:
self.progressView.state = MWMCircularProgressStateFailed;
break;
case NodeStatus::OnDisk:
self.progressView.state = MWMCircularProgressStateCompleted;
break;
case NodeStatus::OnDiskOutOfDate:
self.progressView.state = MWMCircularProgressStateSelected;
break;
case NodeStatus::Mixed:
break;
}
}
#pragma mark - MWMCircularProgressDelegate
#pragma mark - Framework observer
- (void)registerObserver
{
if (self.isObserver)
return;
[MWMFrameworkListener addObserver:self];
self.isObserver = YES;
}
#pragma mark - MWMFrameworkStorageObserver
- (void)processCountryEvent:(TCountryId const &)countryId
{
if (countryId != m_countryId)
return;
storage::NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(m_countryId, nodeAttrs);
[self configProgressView:nodeAttrs];
}
- (void)processCountry:(TCountryId const &)countryId progress:(TLocalAndRemoteSize const &)progress
{
if (countryId != m_countryId)
return;
self.progressView.progress = static_cast<CGFloat>(progress.first) / progress.second;
}
#pragma mark - MWMCircularProgressProtocol
- (void)progressButtonPressed:(nonnull MWMCircularProgress *)progress
{
storage::NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(m_countryId, nodeAttrs);
switch (nodeAttrs.m_status)
{
case NodeStatus::NotDownloaded:
[self.delegate downloadNode:m_countryId];
break;
case NodeStatus::Undefined:
case NodeStatus::Error:
[self.delegate retryDownloadNode:m_countryId];
break;
case NodeStatus::OnDiskOutOfDate:
[self.delegate updateNode:m_countryId];
break;
case NodeStatus::Downloading:
case NodeStatus::InQueue:
[self.delegate cancelNode:m_countryId];
break;
case NodeStatus::OnDisk:
case NodeStatus::Mixed:
break;
}
}
#pragma mark - Properties
@ -58,4 +156,14 @@
return 52.0;
}
- (void)setCountryId:(storage::TCountryId const &)countryId
{
if (m_countryId == countryId)
return;
m_countryId = countryId;
storage::NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(m_countryId, nodeAttrs);
[self config:nodeAttrs];
}
@end

View file

@ -1,3 +1,4 @@
#import "MWMMapDownloaderProtocol.h"
#import "MWMMapDownloaderTableViewCell.h"
#include "storage/index.hpp"
@ -18,4 +19,6 @@
@interface MWMMapDownloaderDataSource : NSObject <MWMMapDownloaderDataSourceProtocol>
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate;
@end

View file

@ -8,42 +8,42 @@
using namespace storage;
@interface MWMMapDownloaderDataSource ()
@property (weak, nonatomic) id<MWMMapDownloaderProtocol> delegate;
@end
@implementation MWMMapDownloaderDataSource
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate
{
self = [super init];
if (self)
_delegate = delegate;
return self;
}
#pragma mark - Fill cells with data
- (void)fillCell:(MWMMapDownloaderTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
TCountryId const countryId = [self countryIdForIndexPath:indexPath];
auto const & s = GetFramework().Storage();
NodeAttrs nodeAttrs;
s.GetNodeAttrs(countryId, nodeAttrs);
[cell setTitleText:@(nodeAttrs.m_nodeLocalName.c_str())];
[cell setDownloadSizeText:formattedSize(nodeAttrs.m_mwmSize)];
if ([cell isKindOfClass:[MWMMapDownloaderLargeCountryTableViewCell class]])
if ([cell isKindOfClass:[MWMMapDownloaderPlaceTableViewCell class]])
static_cast<MWMMapDownloaderPlaceTableViewCell *>(cell).needDisplayArea = self.isParentRoot;
if ([cell isKindOfClass:[MWMMapDownloaderSubplaceTableViewCell class]])
{
MWMMapDownloaderLargeCountryTableViewCell * tCell = (MWMMapDownloaderLargeCountryTableViewCell *)cell;
[tCell setMapCountText:@(nodeAttrs.m_mwmCounter).stringValue];
}
else if ([cell isKindOfClass:[MWMMapDownloaderPlaceTableViewCell class]])
{
MWMMapDownloaderPlaceTableViewCell * tCell = (MWMMapDownloaderPlaceTableViewCell *)cell;
BOOL const isSingleParent = (nodeAttrs.m_parentInfo.size() == 1);
NSString * areaText = (self.isParentRoot && isSingleParent)
? @(nodeAttrs.m_parentInfo[0].m_localName.c_str())
: @"";
[tCell setAreaText:areaText];
if ([cell isKindOfClass:[MWMMapDownloaderSubplaceTableViewCell class]])
{
BOOL const correctDataSource = [self respondsToSelector:@selector(searchMatchedResultForCountryId:)];
NSAssert(correctDataSource, @"Invalid data source");
if (!correctDataSource)
return;
MWMMapDownloaderSubplaceTableViewCell * tCell = (MWMMapDownloaderSubplaceTableViewCell *)cell;
[tCell setSubplaceText:[self searchMatchedResultForCountryId:countryId]];
}
BOOL const correctDataSource = [self respondsToSelector:@selector(searchMatchedResultForCountryId:)];
NSAssert(correctDataSource, @"Invalid data source");
if (!correctDataSource)
return;
[static_cast<MWMMapDownloaderSubplaceTableViewCell *>(cell)
setSubplaceText:[self searchMatchedResultForCountryId:countryId]];
}
[cell setCountryId:countryId];
}
#pragma mark - UITableViewDataSource
@ -57,6 +57,8 @@ using namespace storage;
{
NSString * reuseIdentifier = [self cellIdentifierForIndexPath:indexPath];
MWMMapDownloaderTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
cell.delegate = self.delegate;
[cell registerObserver];
[self fillCell:cell atIndexPath:indexPath];
return cell;
}

View file

@ -2,6 +2,6 @@
@interface MWMMapDownloaderDefaultDataSource : MWMMapDownloaderDataSource
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId;
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate;
@end

View file

@ -21,9 +21,9 @@ using namespace storage;
TCountryId m_parentId;
}
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate
{
self = [super init];
self = [super initWithDelegate:delegate];
if (self)
[self configData:countryId];
return self;

View file

@ -18,9 +18,9 @@ using namespace storage;
@implementation MWMMapDownloaderExtendedDataSource
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId
- (instancetype)initForRootCountryId:(storage::TCountryId)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate
{
self = [super initForRootCountryId:countryId];
self = [super initForRootCountryId:countryId delegate:delegate];
if (self)
{
self.baseSectionShift = 0;

View file

@ -4,6 +4,6 @@
@interface MWMMapDownloaderSearchDataSource : MWMMapDownloaderDataSource
- (instancetype)initWithSearchResults:(search::Results const &)results;
- (instancetype)initWithSearchResults:(search::Results const &)results delegate:(id<MWMMapDownloaderProtocol>)delegate;
@end

View file

@ -17,9 +17,9 @@ extern NSString * const kPlaceCellIdentifier;
@implementation MWMMapDownloaderSearchDataSource
- (instancetype)initWithSearchResults:(search::Results const &)results
- (instancetype)initWithSearchResults:(search::Results const &)results delegate:(id<MWMMapDownloaderProtocol>)delegate
{
self = [super init];
self = [super initWithDelegate:delegate];
if (self)
[self configSearchResults:results];
return self;

View file

@ -1,9 +1,8 @@
#import "MWMMapDownloaderProtocol.h"
#import "MWMMapDownloaderTableViewCell.h"
#import "MWMViewController.h"
#include "storage/index.hpp"
@interface MWMBaseMapDownloaderViewController : MWMViewController <UITableViewDelegate>
@interface MWMBaseMapDownloaderViewController : MWMViewController <UITableViewDelegate, MWMMapDownloaderProtocol>
@property (weak, nonatomic) IBOutlet UILabel * allMapsLabel;

View file

@ -8,6 +8,7 @@
#import "MWMMapDownloaderTableViewCell.h"
#import "MWMMapDownloaderViewController.h"
#import "MWMSegue.h"
#import "MWMStorage.h"
#import "UIColor+MapsMeColor.h"
#include "Framework.h"
@ -26,8 +27,6 @@ NSString * const kUpdateActionTitle = L(@"downloader_status_outdated");
NSString * const kDeleteActionTitle = L(@"downloader_delete_map");
NSString * const kShowActionTitle = L(@"zoom_to_country");
NSString * const kCancelActionTitle = L(@"cancel");
using TAlertAction = void (^)(UIAlertAction *);
} // namespace
@interface MWMBaseMapDownloaderViewController () <UIActionSheetDelegate>
@ -42,11 +41,6 @@ using TAlertAction = void (^)(UIAlertAction *);
@property (nonatomic) CGFloat lastScrollOffset;
@property (copy, nonatomic) TAlertAction downloadAction;
@property (copy, nonatomic) TAlertAction updateAction;
@property (copy, nonatomic) TAlertAction deleteAction;
@property (copy, nonatomic) TAlertAction showAction;
@property (nonatomic) MWMMapDownloaderDataSource * dataSource;
@property (nonatomic) MWMMapDownloaderDataSource * defaultDataSource;
@ -65,7 +59,6 @@ using namespace storage;
[self configNavBar];
[self configTable];
[self configAllMapsView];
[self configActions];
}
- (void)viewWillAppear:(BOOL)animated
@ -155,32 +148,44 @@ using namespace storage;
else
{
UIAlertController * alertController =
[UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
[UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleActionSheet];
if (isDownloaded)
{
UIAlertAction * showAction = [UIAlertAction actionWithTitle:kShowActionTitle
style:UIAlertActionStyleDefault
handler:self.showAction];
handler:^(UIAlertAction * action)
{
[self showNode:self->m_actionSheetId];
}];
[alertController addAction:showAction];
if (needsUpdate)
{
UIAlertAction * updateAction = [UIAlertAction actionWithTitle:kUpdateActionTitle
style:UIAlertActionStyleDefault
handler:self.updateAction];
handler:^(UIAlertAction * action)
{
[self updateNode:self->m_actionSheetId];
}];
[alertController addAction:updateAction];
}
UIAlertAction * deleteAction = [UIAlertAction actionWithTitle:kDeleteActionTitle
style:UIAlertActionStyleDestructive
handler:self.deleteAction];
handler:^(UIAlertAction * action)
{
[self deleteNode:self->m_actionSheetId];
}];
[alertController addAction:deleteAction];
}
else
{
UIAlertAction * downloadAction = [UIAlertAction actionWithTitle:downloadActionTitle
style:UIAlertActionStyleDefault
handler:self.downloadAction];
handler:^(UIAlertAction * action)
{
[self downloadNode:self->m_actionSheetId];
}];
[alertController addAction:downloadAction];
}
UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:kCancelActionTitle
@ -269,9 +274,9 @@ using namespace storage;
- (IBAction)allMapsAction
{
if (self.parentCountryId == GetFramework().Storage().GetRootId())
[MapsAppDelegate updateNode:self.parentCountryId alertController:self.alertController];
[MWMStorage updateNode:self.parentCountryId alertController:self.alertController];
else
[MapsAppDelegate downloadNode:self.parentCountryId alertController:self.alertController onSuccess:nil];
[MWMStorage downloadNode:self.parentCountryId alertController:self.alertController onSuccess:nil];
}
#pragma mark - UITableViewDelegate
@ -319,43 +324,46 @@ using namespace storage;
{
NSString * btnTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([btnTitle hasPrefix:kDownloadActionTitle])
self.downloadAction(nil);
[self downloadNode:m_actionSheetId];
else if ([btnTitle isEqualToString:kDeleteActionTitle])
self.deleteAction(nil);
[self deleteNode:m_actionSheetId];
else if ([btnTitle isEqualToString:kUpdateActionTitle])
[self updateNode:m_actionSheetId];
else if ([btnTitle isEqualToString:kShowActionTitle])
self.showAction(nil);
[self showNode:m_actionSheetId];
}
#pragma mark - Action Sheet actions
#pragma mark - MWMMapDownloaderProtocol
- (void)configActions
- (void)downloadNode:(storage::TCountryId const &)countryId
{
__weak auto weakSelf = self;
self.downloadAction = ^(UIAlertAction * action)
{
__strong auto self = weakSelf;
if (self)
[MapsAppDelegate downloadNode:self->m_actionSheetId alertController:self.alertController onSuccess:nil];
};
[MWMStorage downloadNode:countryId alertController:self.alertController onSuccess:nil];
}
self.updateAction = ^(UIAlertAction * action)
{
__strong auto self = weakSelf;
if (self)
[MapsAppDelegate updateNode:self->m_actionSheetId alertController:self.alertController];
};
- (void)retryDownloadNode:(storage::TCountryId const &)countryId
{
[MWMStorage retryDownloadNode:countryId];
}
self.deleteAction = ^(UIAlertAction * action)
{
__strong auto self = weakSelf;
if (self)
[MapsAppDelegate deleteNode:self->m_actionSheetId];
};
- (void)updateNode:(storage::TCountryId const &)countryId
{
[MWMStorage updateNode:countryId alertController:self.alertController];
}
self.showAction = ^(UIAlertAction * action)
{
// TODO (igrechuhin) Add implementation
};
- (void)deleteNode:(storage::TCountryId const &)countryId
{
[MWMStorage deleteNode:countryId];
}
- (void)cancelNode:(storage::TCountryId const &)countryId
{
[MWMStorage cancelDownloadNode:countryId];
}
- (void)showNode:(storage::TCountryId const &)countryId
{
[MapsAppDelegate showNode:countryId];
[self.navigationController popToRootViewControllerAnimated:YES];
}
#pragma mark - Managing the Status Bar
@ -386,7 +394,7 @@ using namespace storage;
- (void)setParentCountryId:(TCountryId)parentId
{
self.defaultDataSource = [[MWMMapDownloaderDefaultDataSource alloc] initForRootCountryId:parentId];
self.defaultDataSource = [[MWMMapDownloaderDefaultDataSource alloc] initForRootCountryId:parentId delegate:self];
}
- (void)setDataSource:(MWMMapDownloaderDataSource *)dataSource

View file

@ -0,0 +1,12 @@
#include "storage/index.hpp"
@protocol MWMMapDownloaderProtocol <NSObject>
- (void)downloadNode:(storage::TCountryId const &)countryId;
- (void)retryDownloadNode:(storage::TCountryId const &)countryId;
- (void)updateNode:(storage::TCountryId const &)countryId;
- (void)deleteNode:(storage::TCountryId const &)countryId;
- (void)cancelNode:(storage::TCountryId const &)countryId;
- (void)showNode:(storage::TCountryId const &)countryId;
@end

View file

@ -141,7 +141,7 @@ using namespace storage;
MWMMapDownloaderDataSource * dataSource = self.defaultDataSource;
if (results.GetCount() != 0)
{
self.searchDataSource = [[MWMMapDownloaderSearchDataSource alloc] initWithSearchResults:results];
self.searchDataSource = [[MWMMapDownloaderSearchDataSource alloc] initWithSearchResults:results delegate:self];
dataSource = self.searchDataSource;
}
dispatch_async(dispatch_get_main_queue(), ^()
@ -156,7 +156,7 @@ using namespace storage;
- (void)setParentCountryId:(TCountryId)parentId
{
self.defaultDataSource = [[MWMMapDownloaderExtendedDataSource alloc] initForRootCountryId:parentId];
self.defaultDataSource = [[MWMMapDownloaderExtendedDataSource alloc] initForRootCountryId:parentId delegate:self];
}
#pragma mark - Helpers

View file

@ -9,6 +9,8 @@
#import "MWMAuthorizationCommon.h"
#import "MWMAuthorizationLoginViewController.h"
#import "MWMEditorViewController.h"
#import "MWMFrameworkListener.h"
#import "MWMFrameworkObservers.h"
#import "MWMMapDownloadDialog.h"
#import "MWMMapDownloaderViewController.h"
#import "MWMMapViewControlsManager.h"

View file

@ -1,10 +1,10 @@
#import "DownloadIndicatorProtocol.h"
#import "MWMAlertViewController.h"
#import "MWMFrameworkListener.h"
#import "MWMNavigationController.h"
#include "indexer/map_style.hpp"
#include "storage/index.hpp"
@class MapViewController;
@class LocationManager;
@ -32,9 +32,7 @@ typedef NS_ENUM(NSUInteger, MWMRoutingPlaneMode)
@property (nonatomic, readonly) LocationManager * m_locationManager;
+ (MapsAppDelegate *)theApp;
+ (void)downloadNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess;
+ (void)updateNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController;
+ (void)deleteNode:(storage::TCountryId const &)countryId;
+ (void)showNode:(storage::TCountryId const &)countryId;
- (void)enableStandby;
- (void)disableStandby;

View file

@ -8,6 +8,8 @@
#import "MWMAlertViewController.h"
#import "MWMAuthorizationCommon.h"
#import "MWMController.h"
#import "MWMFrameworkListener.h"
#import "MWMFrameworkObservers.h"
#import "MWMTextToSpeech.h"
#import "Preferences.h"
#import "RouteState.h"
@ -111,53 +113,9 @@ using namespace osm_auth_ios;
return (MapsAppDelegate *)[UIApplication sharedApplication].delegate;
}
#pragma mark - Storage
+ (void)downloadNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess
+ (void)showNode:(storage::TCountryId const &)countryId
{
[self countryId:countryId alertController:alertController performAction:^
{
GetFramework().Storage().DownloadNode(countryId);
if (onSuccess)
onSuccess();
}];
}
+ (void)updateNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController
{
[self countryId:countryId alertController:alertController performAction:^
{
GetFramework().Storage().UpdateNode(countryId);
}];
}
+ (void)deleteNode:(storage::TCountryId const &)countryId
{
GetFramework().Storage().DeleteNode(countryId);
}
+ (void)countryId:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController performAction:(TMWMVoidBlock)action
{
switch (Platform::ConnectionStatus())
{
case Platform::EConnectionType::CONNECTION_NONE:
[alertController presentNoConnectionAlert];
break;
case Platform::EConnectionType::CONNECTION_WIFI:
action();
break;
case Platform::EConnectionType::CONNECTION_WWAN:
{
storage::NodeAttrs attrs;
GetFramework().Storage().GetNodeAttrs(countryId, attrs);
size_t const warningSizeForWWAN = 50 * MB;
if (attrs.m_mwmSize > warningSizeForWWAN)
[alertController presentNoWiFiAlertWithName:@(attrs.m_nodeLocalName.c_str()) okBlock:action];
else
action();
break;
}
}
// TODO (igrechuhin) Add implementation
}
#pragma mark - Notifications

View file

@ -1,18 +1,23 @@
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MWMAlertViewController.h"
#import "MWMMapDownloaderViewController.h"
#import "MWMMigrationView.h"
#import "MWMMigrationViewController.h"
#import "MWMStorage.h"
#include "Framework.h"
#include "platform/platform.hpp"
#include "storage/storage.hpp"
namespace
{
NSString * const kDownloaderSegue = @"Migration2MapDownloaderSegue";
} // namespace
using namespace storage;
@implementation MWMMigrationViewController
- (void)viewDidLoad
@ -95,7 +100,7 @@ NSString * const kDownloaderSegue = @"Migration2MapDownloaderSegue";
case NodeErrorCode::NoInetConnection:
[avc presentDownloaderNoConnectionAlertWithOkBlock:^
{
GetFramework().Storage().RetryDownloadNode(countryId);
[MWMStorage retryDownloadNode:countryId];
}];
break;
}

View file

@ -0,0 +1,13 @@
#import "MWMAlertViewController.h"
#include "storage/index.hpp"
@interface MWMStorage : NSObject
+ (void)downloadNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess;
+ (void)retryDownloadNode:(storage::TCountryId const &)countryId;
+ (void)updateNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController;
+ (void)deleteNode:(storage::TCountryId const &)countryId;
+ (void)cancelDownloadNode:(storage::TCountryId const &)countryId;
@end

View file

@ -0,0 +1,67 @@
#import "Common.h"
#import "MWMStorage.h"
#include "Framework.h"
#include "platform/platform.hpp"
@implementation MWMStorage
+ (void)downloadNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController onSuccess:(TMWMVoidBlock)onSuccess
{
[self countryId:countryId alertController:alertController performAction:^
{
GetFramework().Storage().DownloadNode(countryId);
if (onSuccess)
onSuccess();
}];
}
+ (void)retryDownloadNode:(storage::TCountryId const &)countryId
{
GetFramework().Storage().RetryDownloadNode(countryId);
}
+ (void)updateNode:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController
{
[self countryId:countryId alertController:alertController performAction:^
{
GetFramework().Storage().UpdateNode(countryId);
}];
}
+ (void)deleteNode:(storage::TCountryId const &)countryId
{
GetFramework().Storage().DeleteNode(countryId);
}
+ (void)cancelDownloadNode:(storage::TCountryId const &)countryId
{
GetFramework().Storage().CancelDownloadNode(countryId);
}
+ (void)countryId:(storage::TCountryId const &)countryId alertController:(MWMAlertViewController *)alertController performAction:(TMWMVoidBlock)action
{
switch (Platform::ConnectionStatus())
{
case Platform::EConnectionType::CONNECTION_NONE:
[alertController presentNoConnectionAlert];
break;
case Platform::EConnectionType::CONNECTION_WIFI:
action();
break;
case Platform::EConnectionType::CONNECTION_WWAN:
{
storage::NodeAttrs attrs;
GetFramework().Storage().GetNodeAttrs(countryId, attrs);
size_t const warningSizeForWWAN = 50 * MB;
if (attrs.m_mwmSize > warningSizeForWWAN)
[alertController presentNoWiFiAlertWithName:@(attrs.m_nodeLocalName.c_str()) okBlock:action];
else
action();
break;
}
}
}
@end

View file

@ -1,3 +1,5 @@
#import "MWMViewController.h"
@interface MWMMapDownloadDialog : UIView
+ (instancetype)dialogForController:(MWMViewController *)controller;

View file

@ -1,7 +1,11 @@
#import "Common.h"
#import "MapsAppDelegate.h"
#import "MWMAlertViewController.h"
#import "MWMCircularProgress.h"
#import "MWMFrameworkListener.h"
#import "MWMFrameworkObservers.h"
#import "MWMMapDownloadDialog.h"
#import "MWMStorage.h"
#include "Framework.h"
@ -130,7 +134,7 @@ using namespace storage;
case NodeErrorCode::NoInetConnection:
[avc presentDownloaderNoConnectionAlertWithOkBlock:^
{
GetFramework().Storage().RetryDownloadNode(self->m_countryId);
[MWMStorage retryDownloadNode:self->m_countryId];
}];
break;
}
@ -180,22 +184,22 @@ using namespace storage;
- (void)processCountry:(TCountryId const &)countryId progress:(TLocalAndRemoteSize const &)progress
{
if (self.superview && m_countryId == countryId)
[self showDownloading:static_cast<CGFloat>(progress.first) / static_cast<CGFloat>(progress.second)];
[self showDownloading:static_cast<CGFloat>(progress.first) / progress.second];
}
#pragma mark - MWMCircularProgressDelegate
- (void)progressButtonPressed:(nonnull MWMCircularProgress *)progress
{
auto & s = GetFramework().Storage();
if (progress.state == MWMCircularProgressStateFailed)
{
s.RetryDownloadNode(m_countryId);
[self.progressView startSpinner:NO];
[self showInQueue];
[MWMStorage retryDownloadNode:m_countryId];
}
else
{
s.CancelDownloadNode(m_countryId);
[self showDownloadRequest];
[MWMStorage cancelDownloadNode:m_countryId];
}
}
@ -203,7 +207,7 @@ using namespace storage;
- (IBAction)downloadAction
{
[MapsAppDelegate downloadNode:m_countryId alertController:self.controller.alertController onSuccess:nil];
[MWMStorage downloadNode:m_countryId alertController:self.controller.alertController onSuccess:nil];
}
#pragma mark - Properties
@ -217,6 +221,7 @@ using namespace storage;
[_progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateNormal];
[_progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateSelected];
[_progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateProgress];
[_progressView setImage:[UIImage imageNamed:@"ic_close_spinner"] forState:MWMCircularProgressStateSpinner];
[_progressView setImage:[UIImage imageNamed:@"ic_download_error"] forState:MWMCircularProgressStateFailed];
[_progressView setImage:[UIImage imageNamed:@"ic_check"] forState:MWMCircularProgressStateCompleted];
}

View file

@ -247,6 +247,8 @@
34CCFDE11C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34CCFDDE1C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.mm */; };
34CCFDE21C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34CCFDDF1C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib */; };
34CCFDE31C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34CCFDDF1C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib */; };
34CE8A671C7740E100F4351A /* MWMStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34CE8A661C7740E100F4351A /* MWMStorage.mm */; };
34CE8A681C7740E100F4351A /* MWMStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34CE8A661C7740E100F4351A /* MWMStorage.mm */; };
34CFFE8B1B7DE6FD009D0C9F /* MWMSearchManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34CFFE8A1B7DE6FD009D0C9F /* MWMSearchManager.mm */; };
34CFFE8D1B7DE71C009D0C9F /* MWMSearchView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34CFFE8C1B7DE71C009D0C9F /* MWMSearchView.xib */; };
34CFFE901B7DE83D009D0C9F /* MWMSearchView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34CFFE8F1B7DE83D009D0C9F /* MWMSearchView.mm */; };
@ -1079,6 +1081,8 @@
34CCFDDE1C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMPlacePageOpeningHoursCell.mm; sourceTree = "<group>"; };
34CCFDDF1C22A2EF00F28959 /* MWMPlacePageOpeningHoursCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMPlacePageOpeningHoursCell.xib; sourceTree = "<group>"; };
34CE2ECB1C2AA83F007B59ED /* MWMOpeningHoursCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMOpeningHoursCommon.h; sourceTree = "<group>"; };
34CE8A651C7740E100F4351A /* MWMStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMStorage.h; sourceTree = "<group>"; };
34CE8A661C7740E100F4351A /* MWMStorage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMStorage.mm; sourceTree = "<group>"; };
34CFFE891B7DE6FD009D0C9F /* MWMSearchManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMSearchManager.h; sourceTree = "<group>"; };
34CFFE8A1B7DE6FD009D0C9F /* MWMSearchManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMSearchManager.mm; sourceTree = "<group>"; };
34CFFE8C1B7DE71C009D0C9F /* MWMSearchView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMSearchView.xib; sourceTree = "<group>"; };
@ -1087,6 +1091,7 @@
34D15BA51BD8F93C00C8BCBE /* AddSetTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddSetTableViewCell.h; sourceTree = "<group>"; };
34D15BA61BD8F93C00C8BCBE /* AddSetTableViewCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AddSetTableViewCell.mm; sourceTree = "<group>"; };
34D15BA71BD8F93C00C8BCBE /* AddSetTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddSetTableViewCell.xib; sourceTree = "<group>"; };
34DCDE3D1C76195F00652CAC /* MWMMapDownloaderProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMMapDownloaderProtocol.h; sourceTree = "<group>"; };
34E2731F1C737A4100463965 /* MWMMigrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMigrationViewController.h; sourceTree = "<group>"; };
34E273201C737A4100463965 /* MWMMigrationViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMigrationViewController.mm; sourceTree = "<group>"; };
34E273231C73876500463965 /* MWMMigrationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMigrationView.h; sourceTree = "<group>"; };
@ -1574,6 +1579,7 @@
isa = PBXGroup;
children = (
34479C741C60C6130065D261 /* Framework */,
34CE8A641C7740CF00F4351A /* Storage */,
34ABA61D1C2D514A00FE1BEC /* Input Validators */,
F607C18B1C047FCA00B53A87 /* Segue */,
34FE4C421BCC013500066718 /* Widgets */,
@ -1805,6 +1811,7 @@
342AF0DD1BE24E7C0016F3AE /* MapDownloader */ = {
isa = PBXGroup;
children = (
34DCDE3D1C76195F00652CAC /* MWMMapDownloaderProtocol.h */,
341223B91BEB58FA007227E9 /* MWMBaseMapDownloaderViewController.h */,
341223BA1BEB58FA007227E9 /* MWMBaseMapDownloaderViewController.mm */,
342AF0DE1BE24E9A0016F3AE /* MWMMapDownloaderViewController.h */,
@ -2169,6 +2176,15 @@
path = CustomViews/MapViewControls/PlacePage/Cells/OpeningHours;
sourceTree = "<group>";
};
34CE8A641C7740CF00F4351A /* Storage */ = {
isa = PBXGroup;
children = (
34CE8A651C7740E100F4351A /* MWMStorage.h */,
34CE8A661C7740E100F4351A /* MWMStorage.mm */,
);
path = Storage;
sourceTree = "<group>";
};
34CFFE881B7DE67F009D0C9F /* Search */ = {
isa = PBXGroup;
children = (
@ -3443,6 +3459,7 @@
34ABA6241C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */,
34B82AE21B84AC5E00180497 /* MWMSearchCategoriesManager.mm in Sources */,
34BC722A1B0DECAE0012A34B /* MWMZoomButtonsView.mm in Sources */,
34CE8A671C7740E100F4351A /* MWMStorage.mm in Sources */,
F6F533A31B3C248900C1940B /* UIColor+MapsMeColor.mm in Sources */,
346EDADB1B9F0E35004F8DB5 /* MWMMultilineLabel.mm in Sources */,
34C9BD041C6DB693000DC38D /* MWMViewController.mm in Sources */,
@ -3648,6 +3665,7 @@
6741AA121BF340DE002C974C /* MWMZoomButtonsView.mm in Sources */,
6741AA131BF340DE002C974C /* UIColor+MapsMeColor.mm in Sources */,
34ABA6251C2D551900FE1BEC /* MWMInputValidatorFactory.mm in Sources */,
34CE8A681C7740E100F4351A /* MWMStorage.mm in Sources */,
6741AA141BF340DE002C974C /* MWMMultilineLabel.mm in Sources */,
6741AA151BF340DE002C974C /* Statistics.mm in Sources */,
34C9BD051C6DB693000DC38D /* MWMViewController.mm in Sources */,