[ios] Added download map from place page support.

This commit is contained in:
Ilya Grechuhin 2016-05-20 16:44:39 +03:00
parent 0fcbb76b78
commit 8e8c1b373a
7 changed files with 143 additions and 22 deletions

View file

@ -1,6 +1,10 @@
#import "Common.h"
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MapViewController.h"
#import "MWMBasePlacePageView.h"
#import "MWMCircularProgress.h"
#import "MWMFrameworkListener.h"
#import "MWMPlacePage.h"
#import "MWMPlacePageActionBar.h"
#import "MWMPlacePageBookmarkCell.h"
@ -9,6 +13,8 @@
#import "MWMPlacePageInfoCell.h"
#import "MWMPlacePageOpeningHoursCell.h"
#import "MWMPlacePageViewManager.h"
#import "MWMStorage.h"
#import "MWMViewController.h"
#import "NSString+Categories.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"
@ -102,8 +108,11 @@ enum class AttributePosition
};
} // namespace
@interface MWMBasePlacePageView () <UITableViewDelegate, UITableViewDataSource,
MWMPlacePageOpeningHoursCellProtocol, MWMPlacePageBookmarkDelegate>
using namespace storage;
@interface MWMBasePlacePageView ()<
UITableViewDelegate, UITableViewDataSource, MWMPlacePageOpeningHoursCellProtocol,
MWMPlacePageBookmarkDelegate, MWMCircularProgressProtocol, MWMFrameworkStorageObserver>
{
vector<PlacePageSection> m_sections;
map<PlacePageSection, vector<MWMPlacePageCellType>> m_cells;
@ -116,6 +125,8 @@ enum class AttributePosition
@property (nonatomic, readwrite) BOOL openingHoursCellExpanded;
@property (nonatomic) BOOL isBookmarkCellExpanded;
@property (nonatomic) MWMCircularProgress * mapDownloadProgress;
@end
@implementation MWMBasePlacePageView
@ -168,13 +179,6 @@ enum class AttributePosition
- (void)configure
{
MWMPlacePageEntity * entity = self.entity;
// TODO(Iliya): We need to determine that mwm was already uploaded (not only that we can download mwm).
// Probably we should determine it in MWMPlacePageEntity, but I'm not sure about core interface.
// I typed some placeholder in MWMPlacePageEntity class. Please look and use it or implement smth better.
self.downloadProgressView.hidden = YES;
// TODO(Vlad): We need to display external name not only for bookmarks but the same in case when we have localized and default place name.
// Probably we need to move bookmark naming logic in core.
if (entity.isBookmark)
{
if (![entity.bookmarkTitle isEqualToString:entity.title] && entity.bookmarkTitle.length > 0)
@ -219,10 +223,70 @@ enum class AttributePosition
[self.featureTable reloadData];
[self configureCurrentShedule];
[self configureMapDownloader];
[MWMFrameworkListener addObserver:self];
[self setNeedsLayout];
[self layoutIfNeeded];
}
- (void)configureMapDownloader
{
TCountryId const & countryId = self.entity.countryId;
if (countryId == kInvalidCountryId)
{
self.downloadProgressView.hidden = YES;
}
else
{
self.downloadProgressView.hidden = NO;
NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(countryId, nodeAttrs);
MWMCircularProgress * progress = self.mapDownloadProgress;
switch (nodeAttrs.m_status)
{
case NodeStatus::NotDownloaded:
case NodeStatus::Partly:
{
MWMCircularProgressStateVec const affectedStates = {MWMCircularProgressStateNormal,
MWMCircularProgressStateSelected};
[progress setImage:[UIImage imageNamed:@"ic_download"] forStates:affectedStates];
[progress setColoring:MWMButtonColoringBlack forStates:affectedStates];
progress.state = MWMCircularProgressStateNormal;
break;
}
case NodeStatus::Downloading:
{
auto const & prg = nodeAttrs.m_downloadingProgress;
progress.progress = static_cast<CGFloat>(prg.first) / prg.second;
break;
}
case NodeStatus::InQueue:
progress.state = MWMCircularProgressStateSpinner;
break;
case NodeStatus::Undefined:
case NodeStatus::Error:
progress.state = MWMCircularProgressStateFailed;
break;
case NodeStatus::OnDisk:
{
self.downloadProgressView.hidden = YES;
[self setNeedsLayout];
[UIView animateWithDuration:kDefaultAnimationDuration animations:^{ [self layoutIfNeeded]; }];
break;
}
case NodeStatus::OnDiskOutOfDate:
{
MWMCircularProgressStateVec const affectedStates = {MWMCircularProgressStateNormal,
MWMCircularProgressStateSelected};
[progress setImage:[UIImage imageNamed:@"ic_update"] forStates:affectedStates];
[progress setColoring:MWMButtonColoringOther forStates:affectedStates];
progress.state = MWMCircularProgressStateNormal;
break;
}
}
}
}
- (void)configureCurrentShedule
{
MWMPlacePageOpeningHoursCell * cell =
@ -623,4 +687,62 @@ enum class AttributePosition
return m_cells[m_sections[section]];
}
#pragma mark - MWMFrameworkStorageObserver
- (void)processCountryEvent:(TCountryId const &)countryId
{
if (countryId != self.entity.countryId)
return;
[self configureMapDownloader];
}
- (void)processCountry:(TCountryId const &)countryId progress:(MapFilesDownloader::TProgress const &)progress
{
if (countryId != self.entity.countryId)
return;
self.mapDownloadProgress.progress = static_cast<CGFloat>(progress.first) / progress.second;
}
#pragma mark - MWMCircularProgressProtocol
- (void)progressButtonPressed:(nonnull MWMCircularProgress *)progress
{
TCountryId const & countryId = self.entity.countryId;
NodeAttrs nodeAttrs;
GetFramework().Storage().GetNodeAttrs(countryId, nodeAttrs);
MWMAlertViewController * avc = self.ownerPlacePage.manager.ownerViewController.alertController;
switch (nodeAttrs.m_status)
{
case NodeStatus::NotDownloaded:
case NodeStatus::Partly:
[MWMStorage downloadNode:countryId alertController:avc onSuccess:nil];
break;
case NodeStatus::Undefined:
case NodeStatus::Error:
[MWMStorage retryDownloadNode:countryId];
break;
case NodeStatus::OnDiskOutOfDate:
[MWMStorage updateNode:countryId alertController:avc];
break;
case NodeStatus::Downloading:
case NodeStatus::InQueue:
[MWMStorage cancelDownloadNode:countryId];
break;
case NodeStatus::OnDisk:
break;
}
}
#pragma mark - Properties
- (MWMCircularProgress *)mapDownloadProgress
{
if (!_mapDownloadProgress)
{
_mapDownloadProgress = [MWMCircularProgress downloaderProgressForParentView:self.downloadProgressView];
_mapDownloadProgress.delegate = self;
}
return _mapDownloadProgress;
}
@end

View file

@ -1,5 +1,6 @@
#import "MWMPlacePage+Animation.h"
#import "MWMPlacePageViewManager.h"
#import "MWMViewController.h"
#import <objc/runtime.h>
@implementation MWMPlacePage (Animation)

View file

@ -65,8 +65,6 @@ using MWMPlacePageCellTypeValueMap = map<MWMPlacePageCellType, string>;
- (NSString *)getCellValue:(MWMPlacePageCellType)cellType;
- (place_page::Info const &)info;
// TODO (SeregaE, Ilia): uncoment this line and method's implementation in .mm file,
// or please implement better solution.
//- (storage::TCountryId const &)countryId;
- (storage::TCountryId const &)countryId;
@end

View file

@ -179,11 +179,10 @@ void initFieldsMap()
return m_info.GetID();
}
//- (storage::TCountryId const &)countryId
//{
// TODO(SeregaE): We probably should store countryId in instance of place_page::Info and here will be something like
// return m_info.CountryId();
//}
- (storage::TCountryId const &)countryId
{
return m_info.m_countryId;
}
- (BOOL)isMyPosition
{

View file

@ -4,6 +4,7 @@
#import "MWMPlacePageEntity.h"
#import "MWMPlacePageNavigationBar.h"
#import "MWMPlacePageViewManager.h"
#import "MWMViewController.h"
#import "Statistics.h"
#import <objc/runtime.h>

View file

@ -1,18 +1,18 @@
#include "Framework.h"
@class MWMPlacePageEntity, MWMPlacePageNavigationBar;
@class MWMPlacePageEntity, MWMPlacePageNavigationBar, MWMViewController;
@protocol MWMPlacePageViewManagerProtocol;
@interface MWMPlacePageViewManager : NSObject
@property (weak, nonatomic, readonly) UIViewController * ownerViewController;
@property (weak, nonatomic, readonly) MWMViewController * ownerViewController;
@property (nonatomic, readonly) MWMPlacePageEntity * entity;
@property (nonatomic) MWMPlacePageNavigationBar * iPhoneNavigationBar;
@property (nonatomic) CGFloat topBound;
@property (nonatomic) CGFloat leftBound;
@property (nonatomic, readonly) BOOL isDirectionViewShown;
- (instancetype)initWithViewController:(UIViewController *)viewController
- (instancetype)initWithViewController:(MWMViewController *)viewController
delegate:(id<MWMPlacePageViewManagerProtocol>)delegate;
- (void)showPlacePage:(place_page::Info const &)info;
- (void)refreshPlacePage;

View file

@ -29,7 +29,7 @@ extern NSString * const kBookmarksChangedNotification;
@interface MWMPlacePageViewManager () <LocationObserver>
@property (weak, nonatomic) UIViewController * ownerViewController;
@property (weak, nonatomic) MWMViewController * ownerViewController;
@property (nonatomic, readwrite) MWMPlacePageEntity * entity;
@property (nonatomic) MWMPlacePage * placePage;
@property (nonatomic) MWMDirectionView * directionView;
@ -40,7 +40,7 @@ extern NSString * const kBookmarksChangedNotification;
@implementation MWMPlacePageViewManager
- (instancetype)initWithViewController:(UIViewController *)viewController
- (instancetype)initWithViewController:(MWMViewController *)viewController
delegate:(id<MWMPlacePageViewManagerProtocol>)delegate
{
self = [super init];