forked from organicmaps/organicmaps
[ios] Splitted downloaded/available maps lists.
This commit is contained in:
parent
a009b7d416
commit
17ad14ac2c
20 changed files with 196 additions and 163 deletions
|
@ -1,4 +1,5 @@
|
|||
#import "MWMBottomMenuView.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
|
||||
#include "platform/location.hpp"
|
||||
|
||||
|
@ -6,7 +7,7 @@
|
|||
|
||||
@protocol MWMBottomMenuControllerProtocol<NSObject>
|
||||
|
||||
- (void)actionDownloadMaps;
|
||||
- (void)actionDownloadMaps:(TMWMMapDownloaderMode)mode;
|
||||
- (void)closeInfoScreens;
|
||||
- (void)addPlace;
|
||||
- (void)didFinishAddingPlace;
|
||||
|
|
|
@ -358,7 +358,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell)
|
|||
{
|
||||
[Statistics logEvent:kStatMenu withParameters:@{kStatButton : kStatDownloadMaps}];
|
||||
self.state = self.restoreState;
|
||||
[self.delegate actionDownloadMaps];
|
||||
[self.delegate actionDownloadMaps:TMWMMapDownloaderMode::Downloaded];
|
||||
}
|
||||
|
||||
- (void)menuActionOpenSettings
|
||||
|
|
|
@ -255,7 +255,7 @@ extern NSString * const kAlohalyticsTapEventKey;
|
|||
|
||||
#pragma mark - MWMSearchManagerProtocol & MWMBottomMenuControllerProtocol
|
||||
|
||||
- (void)actionDownloadMaps
|
||||
- (void)actionDownloadMaps:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
if (platform::migrate::NeedMigrate())
|
||||
{
|
||||
|
@ -272,7 +272,7 @@ extern NSString * const kAlohalyticsTapEventKey;
|
|||
}
|
||||
else
|
||||
{
|
||||
[self.ownerController openMapsDownloader];
|
||||
[self.ownerController openMapsDownloader:mode];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#import "MWMAlertViewController.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
#import "MWMSearchTextField.h"
|
||||
#import "MWMSearchView.h"
|
||||
|
||||
|
@ -15,7 +16,7 @@ typedef NS_ENUM(NSUInteger, MWMSearchManagerState)
|
|||
@property (nonnull, nonatomic, readonly) MWMAlertViewController * alertController;
|
||||
|
||||
- (void)searchViewDidEnterState:(MWMSearchManagerState)state;
|
||||
- (void)actionDownloadMaps;
|
||||
- (void)actionDownloadMaps:(TMWMMapDownloaderMode)mode;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ extern NSString * const kSearchStateKey = @"SearchStateKey";
|
|||
|
||||
- (void)handleDownloadMapsAction
|
||||
{
|
||||
[self.delegate actionDownloadMaps];
|
||||
[self.delegate actionDownloadMaps:TMWMMapDownloaderMode::Available];
|
||||
}
|
||||
|
||||
#pragma mark - State changes
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#import "MWMMapDownloaderProtocol.h"
|
||||
#import "MWMMapDownloaderTableViewCell.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
|
||||
#include "storage/index.hpp"
|
||||
|
||||
@interface MWMMapDownloaderDataSource : NSObject <UITableViewDataSource>
|
||||
|
||||
@property (nonatomic, readonly) BOOL isParentRoot;
|
||||
@property (nonatomic, readonly) BOOL needFullReload;
|
||||
@property (nonatomic, readonly) NSMutableIndexSet * reloadSections;
|
||||
@property (nonatomic, readonly) TMWMMapDownloaderMode mode;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate;
|
||||
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate mode:(TMWMMapDownloaderMode)mode;
|
||||
- (NSString *)parentCountryId;
|
||||
- (NSString *)countryIdForIndexPath:(NSIndexPath *)indexPath;
|
||||
- (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#import "MWMMapDownloaderLargeCountryTableViewCell.h"
|
||||
#import "MWMMapDownloaderPlaceTableViewCell.h"
|
||||
#import "MWMMapDownloaderSubplaceTableViewCell.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
|
||||
#include "Framework.h"
|
||||
|
||||
|
@ -11,20 +12,19 @@ using namespace storage;
|
|||
@interface MWMMapDownloaderDataSource ()
|
||||
|
||||
@property (weak, nonatomic) id<MWMMapDownloaderProtocol> delegate;
|
||||
|
||||
@property (nonatomic, readwrite) BOOL needFullReload;
|
||||
@property (nonatomic) TMWMMapDownloaderMode mode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMMapDownloaderDataSource
|
||||
|
||||
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate
|
||||
- (instancetype)initWithDelegate:(id<MWMMapDownloaderProtocol>)delegate mode:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
_delegate = delegate;
|
||||
_reloadSections = [NSMutableIndexSet indexSet];
|
||||
_mode = mode;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -108,11 +108,4 @@ using namespace storage;
|
|||
return nil;
|
||||
}
|
||||
|
||||
- (void)setNeedFullReload:(BOOL)needFullReload
|
||||
{
|
||||
_needFullReload = needFullReload;
|
||||
if (needFullReload)
|
||||
[self.reloadSections removeAllIndexes];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
@interface MWMMapDownloaderDefaultDataSource : MWMMapDownloaderDataSource
|
||||
|
||||
- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate;
|
||||
- (void)reload;
|
||||
- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate mode:(TMWMMapDownloaderMode)mode;
|
||||
- (void)load;
|
||||
|
||||
@end
|
||||
|
|
|
@ -28,12 +28,6 @@ auto compareLocalNames = ^NSComparisonResult(NSString * s1, NSString * s2)
|
|||
|
||||
using namespace storage;
|
||||
|
||||
@interface MWMMapDownloaderDataSource ()
|
||||
|
||||
@property (nonatomic, readwrite) BOOL needFullReload;
|
||||
|
||||
@end
|
||||
|
||||
@interface MWMMapDownloaderDefaultDataSource ()
|
||||
|
||||
@property (copy, nonatomic) NSArray<NSString *> * indexes;
|
||||
|
@ -49,9 +43,9 @@ using namespace storage;
|
|||
|
||||
@synthesize isParentRoot = _isParentRoot;
|
||||
|
||||
- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate
|
||||
- (instancetype)initForRootCountryId:(NSString *)countryId delegate:(id<MWMMapDownloaderProtocol>)delegate mode:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
self = [super initWithDelegate:delegate];
|
||||
self = [super initWithDelegate:delegate mode:mode];
|
||||
if (self)
|
||||
{
|
||||
m_parentId = countryId.UTF8String;
|
||||
|
@ -66,45 +60,18 @@ using namespace storage;
|
|||
auto const & s = GetFramework().Storage();
|
||||
TCountriesVec downloadedChildren;
|
||||
TCountriesVec availableChildren;
|
||||
s.GetChildrenInGroups(m_parentId, downloadedChildren, availableChildren);
|
||||
[self configAvailableSections:availableChildren];
|
||||
[self configDownloadedSection:downloadedChildren];
|
||||
}
|
||||
|
||||
- (void)reload
|
||||
{
|
||||
[self.reloadSections removeAllIndexes];
|
||||
// Get old data for comparison.
|
||||
NSDictionary<NSString *, NSArray<NSString *> *> * availableCountriesBeforeUpdate = self.availableCountries;
|
||||
NSInteger const downloadedCountriesCountBeforeUpdate = self.downloadedCountries.count;
|
||||
|
||||
// Load updated data.
|
||||
[self load];
|
||||
|
||||
// Compare new data vs old data to understand what kind of reload is required and what sections need reload.
|
||||
NSInteger const downloadedCountriesCountAfterUpdate = self.downloadedCountries.count;
|
||||
self.needFullReload =
|
||||
(downloadedCountriesCountBeforeUpdate == 0 || downloadedCountriesCountAfterUpdate == 0 ||
|
||||
availableCountriesBeforeUpdate.count != self.availableCountries.count ||
|
||||
availableCountriesBeforeUpdate.count == 0);
|
||||
if (self.needFullReload)
|
||||
return;
|
||||
[availableCountriesBeforeUpdate enumerateKeysAndObjectsUsingBlock:^(NSString * key, NSArray<NSString *> * obj, BOOL * stop)
|
||||
s.GetChildrenInGroups(m_parentId, downloadedChildren, availableChildren, true);
|
||||
if (self.mode == TMWMMapDownloaderMode::Available)
|
||||
{
|
||||
NSUInteger const sectionIndex = [self.indexes indexOfObject:key];
|
||||
if (sectionIndex == NSNotFound)
|
||||
{
|
||||
self.needFullReload = YES;
|
||||
*stop = YES;
|
||||
}
|
||||
else if (obj.count != self.availableCountries[key].count)
|
||||
{
|
||||
[self.reloadSections addIndex:sectionIndex];
|
||||
}
|
||||
}];
|
||||
[self.reloadSections shiftIndexesStartingAtIndex:0 by:self.downloadedSectionShift];
|
||||
if (downloadedCountriesCountBeforeUpdate != downloadedCountriesCountAfterUpdate)
|
||||
[self.reloadSections addIndex:self.downloadedSection];
|
||||
self.downloadedCountries = nil;
|
||||
[self configAvailableSections:availableChildren];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.indexes = nil;
|
||||
self.availableCountries = nil;
|
||||
[self configDownloadedSection:downloadedChildren];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)configAvailableSections:(TCountriesVec const &)availableChildren
|
||||
|
@ -145,14 +112,14 @@ using namespace storage;
|
|||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return self.indexes.count + self.downloadedSectionShift;
|
||||
return self.downloadedCountries ? 1 : self.indexes.count;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if (section == self.downloadedSection)
|
||||
if (self.downloadedCountries)
|
||||
return self.downloadedCountries.count;
|
||||
NSString * index = self.indexes[section - self.downloadedSectionShift];
|
||||
NSString * index = self.indexes[section];
|
||||
return self.availableCountries[index].count;
|
||||
}
|
||||
|
||||
|
@ -163,12 +130,12 @@ using namespace storage;
|
|||
|
||||
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
|
||||
{
|
||||
return index + self.downloadedSectionShift;
|
||||
return index;
|
||||
}
|
||||
|
||||
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
if (section == self.downloadedSection)
|
||||
if (self.downloadedCountries)
|
||||
{
|
||||
NodeAttrs nodeAttrs;
|
||||
GetFramework().Storage().GetNodeAttrs(m_parentId, nodeAttrs);
|
||||
|
@ -177,7 +144,7 @@ using namespace storage;
|
|||
else
|
||||
return [NSString stringWithFormat:@"%@ (%@)", L(@"downloader_downloaded_subtitle"), formattedSize(nodeAttrs.m_localMwmSize)];
|
||||
}
|
||||
return self.indexes[section - self.downloadedSectionShift];
|
||||
return self.indexes[section];
|
||||
}
|
||||
|
||||
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
|
||||
|
@ -204,9 +171,9 @@ using namespace storage;
|
|||
{
|
||||
NSInteger const section = indexPath.section;
|
||||
NSInteger const row = indexPath.row;
|
||||
if (section == self.downloadedSection)
|
||||
if (self.downloadedCountries)
|
||||
return self.downloadedCountries[row];
|
||||
NSString * index = self.indexes[section - self.downloadedSectionShift];
|
||||
NSString * index = self.indexes[section];
|
||||
NSArray<NSString *> * availableCountries = self.availableCountries[index];
|
||||
NSString * nsCountryId = availableCountries[indexPath.row];
|
||||
return nsCountryId;
|
||||
|
@ -223,16 +190,4 @@ using namespace storage;
|
|||
return self.isParentRoot ? kCountryCellIdentifier : kPlaceCellIdentifier;
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (NSInteger)downloadedSectionShift
|
||||
{
|
||||
return (self.downloadedCountries.count != 0 ? self.downloadedSection + 1 : 0);
|
||||
}
|
||||
|
||||
- (NSInteger)downloadedSection
|
||||
{
|
||||
return self.downloadedCountries.count != 0 ? 0 : NSNotFound;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -6,12 +6,6 @@
|
|||
|
||||
using namespace storage;
|
||||
|
||||
@interface MWMMapDownloaderDataSource ()
|
||||
|
||||
@property (nonatomic, readwrite) BOOL needFullReload;
|
||||
|
||||
@end
|
||||
|
||||
@interface MWMMapDownloaderDefaultDataSource ()
|
||||
|
||||
@property (nonatomic, readonly) NSInteger downloadedCountrySection;
|
||||
|
@ -34,23 +28,6 @@ using namespace storage;
|
|||
[self configNearMeSection];
|
||||
}
|
||||
|
||||
- (void)reload
|
||||
{
|
||||
NSInteger const closestCoutriesCountBeforeUpdate = self.nearmeCountries.count;
|
||||
|
||||
[super reload];
|
||||
|
||||
NSInteger const closestCoutriesCountAfterUpdate = self.nearmeCountries.count;
|
||||
if (closestCoutriesCountBeforeUpdate != closestCoutriesCountAfterUpdate &&
|
||||
(closestCoutriesCountBeforeUpdate == 0 || closestCoutriesCountAfterUpdate == 0))
|
||||
self.needFullReload = YES;
|
||||
if (self.needFullReload)
|
||||
return;
|
||||
[self.reloadSections shiftIndexesStartingAtIndex:0 by:self.nearmeSectionShift];
|
||||
if (closestCoutriesCountBeforeUpdate != closestCoutriesCountAfterUpdate)
|
||||
[self.reloadSections addIndex:self.nearmeSection];
|
||||
}
|
||||
|
||||
- (void)configNearMeSection
|
||||
{
|
||||
LocationManager * lm = MapsAppDelegate.theApp.locationManager;
|
||||
|
|
|
@ -21,7 +21,7 @@ extern NSString * const kLargeCountryCellIdentifier;
|
|||
|
||||
- (instancetype)initWithSearchResults:(DownloaderSearchResults const &)results delegate:(id<MWMMapDownloaderProtocol>)delegate
|
||||
{
|
||||
self = [super initWithDelegate:delegate];
|
||||
self = [super initWithDelegate:delegate mode:TMWMMapDownloaderMode::Available];
|
||||
if (self)
|
||||
{
|
||||
NSMutableOrderedSet<NSString *> * nsSearchCountryIds =
|
||||
|
@ -89,9 +89,4 @@ extern NSString * const kLargeCountryCellIdentifier;
|
|||
return self.searchMatchedResults[countryId];
|
||||
}
|
||||
|
||||
- (BOOL)needFullReload
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import "MWMMapDownloaderProtocol.h"
|
||||
#import "MWMMapDownloaderTableViewCell.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
#import "MWMViewController.h"
|
||||
|
||||
@interface MWMBaseMapDownloaderViewController : MWMViewController <UITableViewDelegate, MWMMapDownloaderProtocol>
|
||||
|
@ -8,9 +9,9 @@
|
|||
|
||||
@property (nonatomic) BOOL showAllMapsView;
|
||||
|
||||
@property (nonatomic) NSString * parentCountryId;
|
||||
|
||||
- (void)configTable;
|
||||
- (void)configAllMapsView;
|
||||
|
||||
- (void)setParentCountryId:(NSString *)parentId mode:(TMWMMapDownloaderMode)mode;
|
||||
|
||||
@end
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#import "MWMStorage.h"
|
||||
#import "Statistics.h"
|
||||
#import "UIColor+MapsMeColor.h"
|
||||
#import "UIViewController+Navigation.h"
|
||||
|
||||
#include "Framework.h"
|
||||
|
||||
|
@ -34,6 +35,9 @@ NSString * const kDownloadingTitle = L(@"downloader_downloading");
|
|||
NSString * const kMapsTitle = L(@"downloader_maps");
|
||||
NSString * const kShowActionTitle = L(@"zoom_to_country");
|
||||
NSString * const kUpdateActionTitle = L(@"downloader_status_outdated");
|
||||
|
||||
NSString * const kBaseControllerIdentifier = @"MWMBaseMapDownloaderViewController";
|
||||
NSString * const kControllerIdentifier = @"MWMMapDownloaderViewController";
|
||||
} // namespace
|
||||
|
||||
@interface MWMBaseMapDownloaderViewController () <UIActionSheetDelegate, MWMFrameworkStorageObserver>
|
||||
|
@ -58,6 +62,9 @@ NSString * const kUpdateActionTitle = L(@"downloader_status_outdated");
|
|||
@property (nonatomic) BOOL skipCountryEventProcessing;
|
||||
@property (nonatomic) BOOL forceFullReload;
|
||||
|
||||
@property (nonatomic, readonly) NSString * parentCountryId;
|
||||
@property (nonatomic, readonly) TMWMMapDownloaderMode mode;
|
||||
|
||||
@end
|
||||
|
||||
using namespace storage;
|
||||
|
@ -72,7 +79,6 @@ using namespace storage;
|
|||
[super viewDidLoad];
|
||||
[self configNavBar];
|
||||
[self configTable];
|
||||
[self configAllMapsView];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
|
@ -86,6 +92,7 @@ using namespace storage;
|
|||
forBarMetrics:UIBarMetricsDefault];
|
||||
navBar.shadowImage = [[UIImage alloc] init];
|
||||
[MWMFrameworkListener addObserver:self];
|
||||
[self configViews];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
|
@ -98,11 +105,17 @@ using namespace storage;
|
|||
[self notifyParentController];
|
||||
}
|
||||
|
||||
- (void)configViews
|
||||
{
|
||||
[self configAllMapsView];
|
||||
}
|
||||
|
||||
- (void)configNavBar
|
||||
{
|
||||
BOOL const downloaded = self.mode == TMWMMapDownloaderMode::Downloaded;
|
||||
if (self.dataSource.isParentRoot)
|
||||
{
|
||||
self.title = L(@"download_maps");
|
||||
self.title = downloaded ? L(@"downloader_my_maps_title") : L(@"download_maps");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -110,6 +123,15 @@ using namespace storage;
|
|||
GetFramework().Storage().GetNodeAttrs(self.parentCountryId.UTF8String, nodeAttrs);
|
||||
self.title = @(nodeAttrs.m_nodeLocalName.c_str());
|
||||
}
|
||||
|
||||
if (downloaded)
|
||||
{
|
||||
UIBarButtonItem * addButton =
|
||||
[self navBarButtonWithImage:[UIImage imageNamed:@"ic_nav_bar_add"]
|
||||
highlightedImage:[UIImage imageNamed:@"ic_nav_bar_add_press"]
|
||||
action:@selector(openAvailableMaps)];
|
||||
self.navigationItem.rightBarButtonItems = [self alignedNavBarButtonItems:@[ addButton ]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
||||
|
@ -150,7 +172,7 @@ using namespace storage;
|
|||
});
|
||||
if (needReload)
|
||||
{
|
||||
[self configAllMapsView];
|
||||
[self configViews];
|
||||
[self reloadData];
|
||||
}
|
||||
}
|
||||
|
@ -436,6 +458,24 @@ using namespace storage;
|
|||
[self processCountryEvent:parentCountryId];
|
||||
}
|
||||
|
||||
#pragma mark - Countries tree(s) navigation
|
||||
|
||||
- (void)openAvailableMaps
|
||||
{
|
||||
BOOL const isParentRoot = [self.parentCountryId isEqualToString:@(GetFramework().Storage().GetRootId().c_str())];
|
||||
NSString * identifier = isParentRoot ? kControllerIdentifier : kBaseControllerIdentifier;
|
||||
MWMBaseMapDownloaderViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
|
||||
[vc setParentCountryId:self.parentCountryId mode:TMWMMapDownloaderMode::Available];
|
||||
[MWMSegue segueFrom:self to:vc];
|
||||
}
|
||||
|
||||
- (void)openSubtreeForParentCountryId:(NSString *)parentCountryId
|
||||
{
|
||||
MWMBaseMapDownloaderViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:kBaseControllerIdentifier];
|
||||
[vc setParentCountryId:parentCountryId mode:self.mode];
|
||||
[MWMSegue segueFrom:self to:vc];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
|
@ -443,15 +483,9 @@ using namespace storage;
|
|||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
NSString * identifier = [self.dataSource cellIdentifierForIndexPath:indexPath];
|
||||
if ([identifier isEqualToString:kLargeCountryCellIdentifier])
|
||||
{
|
||||
MWMBaseMapDownloaderViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MWMBaseMapDownloaderViewController"];
|
||||
vc.parentCountryId = [self.dataSource countryIdForIndexPath:indexPath];
|
||||
[MWMSegue segueFrom:self to:vc];
|
||||
}
|
||||
[self openSubtreeForParentCountryId:[self.dataSource countryIdForIndexPath:indexPath]];
|
||||
else
|
||||
{
|
||||
[self showActionSheetForRowAtIndexPath:indexPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
|
@ -609,6 +643,15 @@ using namespace storage;
|
|||
return UIStatusBarStyleLightContent;
|
||||
}
|
||||
|
||||
#pragma mark - Configuration
|
||||
|
||||
- (void)setParentCountryId:(NSString *)parentId mode:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
self.defaultDataSource = [[MWMMapDownloaderDefaultDataSource alloc] initForRootCountryId:parentId
|
||||
delegate:self
|
||||
mode:mode];
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setTableView:(UITableView *)tableView
|
||||
|
@ -626,12 +669,12 @@ using namespace storage;
|
|||
|
||||
- (NSString *)parentCountryId
|
||||
{
|
||||
return [self.dataSource parentCountryId];
|
||||
return self.dataSource.parentCountryId;
|
||||
}
|
||||
|
||||
- (void)setParentCountryId:(NSString *)parentId
|
||||
- (TMWMMapDownloaderMode)mode
|
||||
{
|
||||
self.defaultDataSource = [[MWMMapDownloaderDefaultDataSource alloc] initForRootCountryId:parentId delegate:self];
|
||||
return self.dataSource.mode;
|
||||
}
|
||||
|
||||
- (void)setDataSource:(MWMMapDownloaderDataSource *)dataSource
|
||||
|
@ -649,8 +692,8 @@ using namespace storage;
|
|||
- (void)reloadData
|
||||
{
|
||||
MWMMapDownloaderDefaultDataSource * defaultDataSource = self.defaultDataSource;
|
||||
[defaultDataSource reload];
|
||||
if ([self.dataSource isEqual:defaultDataSource])
|
||||
[defaultDataSource load];
|
||||
if (self.dataSource == defaultDataSource)
|
||||
[self reloadTable];
|
||||
}
|
||||
|
||||
|
@ -658,27 +701,16 @@ using namespace storage;
|
|||
{
|
||||
[self.cellHeightCache removeAllObjects];
|
||||
|
||||
MWMMapDownloaderDataSource * dataSource = self.dataSource;
|
||||
UITableView * tableView = self.tableView;
|
||||
if (self.forceFullReload || dataSource.needFullReload)
|
||||
{
|
||||
self.forceFullReload = NO;
|
||||
// If these methods are not called, tableView will not call tableView:cellForRowAtIndexPath:
|
||||
[tableView setNeedsLayout];
|
||||
[tableView layoutIfNeeded];
|
||||
// If these methods are not called, tableView will not call tableView:cellForRowAtIndexPath:
|
||||
[tableView setNeedsLayout];
|
||||
[tableView layoutIfNeeded];
|
||||
|
||||
[tableView reloadData];
|
||||
[tableView reloadData];
|
||||
|
||||
// If these methods are not called, tableView will not display new cells
|
||||
[tableView setNeedsLayout];
|
||||
[tableView layoutIfNeeded];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSMutableIndexSet * reloadSections = dataSource.reloadSections;
|
||||
if (reloadSections.count)
|
||||
[tableView reloadSections:reloadSections withRowAnimation:UITableViewRowAnimationAutomatic];
|
||||
}
|
||||
// If these methods are not called, tableView will not display new cells
|
||||
[tableView setNeedsLayout];
|
||||
[tableView layoutIfNeeded];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
enum class TMWMMapDownloaderMode
|
||||
{
|
||||
Downloaded,
|
||||
Available
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
#import "MWMMapDownloaderExtendedDataSource.h"
|
||||
#import "MWMMapDownloaderSearchDataSource.h"
|
||||
#import "MWMMapDownloaderViewController.h"
|
||||
#import "MWMNoMapsViewController.h"
|
||||
#import "UIColor+MapsMeColor.h"
|
||||
#import "UIKitCategories.h"
|
||||
|
||||
|
@ -9,6 +10,11 @@
|
|||
|
||||
#include "storage/downloader_search_params.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
NSString * const kNoMapsSegue = @"MapDownloaderEmbedNoMapsSegue";
|
||||
} // namespace
|
||||
|
||||
using namespace storage;
|
||||
|
||||
@interface MWMBaseMapDownloaderViewController ()
|
||||
|
@ -18,14 +24,23 @@ using namespace storage;
|
|||
@property (nonatomic) MWMMapDownloaderDataSource * dataSource;
|
||||
@property (nonatomic) MWMMapDownloaderDataSource * defaultDataSource;
|
||||
|
||||
@property (nonatomic, readonly) NSString * parentCountryId;
|
||||
@property (nonatomic, readonly) TMWMMapDownloaderMode mode;
|
||||
|
||||
- (void)configViews;
|
||||
|
||||
- (void)openAvailableMaps;
|
||||
|
||||
- (void)reloadTable;
|
||||
|
||||
@end
|
||||
|
||||
@interface MWMMapDownloaderViewController () <UISearchBarDelegate, UIScrollViewDelegate>
|
||||
@interface MWMMapDownloaderViewController () <UISearchBarDelegate, UIScrollViewDelegate, MWMNoMapsViewControllerProtocol>
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView * statusBarBackground;
|
||||
@property (weak, nonatomic) IBOutlet UISearchBar * searchBar;
|
||||
@property (weak, nonatomic) IBOutlet UIView * noMapsContainer;
|
||||
@property (nonatomic) MWMNoMapsViewController * noMapsController;
|
||||
|
||||
@property (nonatomic) MWMMapDownloaderDataSource * searchDataSource;
|
||||
|
||||
|
@ -53,7 +68,39 @@ using namespace storage;
|
|||
|
||||
- (void)backTap
|
||||
{
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
NSArray<UIViewController *> * viewControllers = self.navigationController.viewControllers;
|
||||
UIViewController * previousViewController = viewControllers[viewControllers.count - 2];
|
||||
if ([previousViewController isKindOfClass:[MWMBaseMapDownloaderViewController class]])
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
else
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
- (void)configViews
|
||||
{
|
||||
[super configViews];
|
||||
[self checkAndConfigNoMapsView];
|
||||
}
|
||||
|
||||
#pragma mark - No Maps
|
||||
|
||||
- (void)checkAndConfigNoMapsView
|
||||
{
|
||||
auto const & s = GetFramework().Storage();
|
||||
if (![self.parentCountryId isEqualToString:@(s.GetRootId().c_str())])
|
||||
return;
|
||||
if (self.mode == TMWMMapDownloaderMode::Available || s.HaveDownloadedCountries())
|
||||
{
|
||||
[self configAllMapsView];
|
||||
self.tableView.hidden = NO;
|
||||
self.noMapsContainer.hidden = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.showAllMapsView = NO;
|
||||
self.tableView.hidden = YES;
|
||||
self.noMapsContainer.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - All Maps Action
|
||||
|
@ -142,11 +189,32 @@ using namespace storage;
|
|||
};
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
#pragma mark - MWMNoMapsViewControllerProtocol
|
||||
|
||||
- (void)setParentCountryId:(NSString *)parentId
|
||||
- (void)handleDownloadMapsAction
|
||||
{
|
||||
self.defaultDataSource = [[MWMMapDownloaderExtendedDataSource alloc] initForRootCountryId:parentId delegate:self];
|
||||
[self openAvailableMaps];
|
||||
}
|
||||
|
||||
#pragma mark - Segue
|
||||
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
||||
{
|
||||
[super prepareForSegue:segue sender:sender];
|
||||
if ([segue.identifier isEqualToString:kNoMapsSegue])
|
||||
{
|
||||
self.noMapsController = segue.destinationViewController;
|
||||
self.noMapsController.delegate = self;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Configuration
|
||||
|
||||
- (void)setParentCountryId:(NSString *)parentId mode:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
self.defaultDataSource = [[MWMMapDownloaderExtendedDataSource alloc] initForRootCountryId:parentId
|
||||
delegate:self
|
||||
mode:mode];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#import "LocationManager.h"
|
||||
#import "LocationPredictor.h"
|
||||
#import "MWMMapDownloaderTypes.h"
|
||||
#import "MWMViewController.h"
|
||||
#import <MyTargetSDKCorp/MTRGNativeAppwallAd.h>
|
||||
|
||||
|
@ -33,7 +34,7 @@ namespace search { struct AddressInfo; }
|
|||
|
||||
- (void)openMigration;
|
||||
- (void)openBookmarks;
|
||||
- (void)openMapsDownloader;
|
||||
- (void)openMapsDownloader:(TMWMMapDownloaderMode)mode;
|
||||
- (void)openEditor;
|
||||
|
||||
- (void)refreshAd;
|
||||
|
|
|
@ -548,10 +548,10 @@ NSString * const kUDViralAlertWasShown = @"ViralAlertWasShown";
|
|||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
|
||||
- (void)openMapsDownloader
|
||||
- (void)openMapsDownloader:(TMWMMapDownloaderMode)mode
|
||||
{
|
||||
[Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"downloader"];
|
||||
[self performSegueWithIdentifier:kDownloaderSegue sender:self];
|
||||
[self performSegueWithIdentifier:kDownloaderSegue sender:@(static_cast<NSInteger>(mode))];
|
||||
}
|
||||
|
||||
- (void)openEditor
|
||||
|
@ -844,7 +844,8 @@ NSString * const kUDViralAlertWasShown = @"ViralAlertWasShown";
|
|||
else if ([segue.identifier isEqualToString:kDownloaderSegue])
|
||||
{
|
||||
MWMMapDownloaderViewController * dvc = segue.destinationViewController;
|
||||
dvc.parentCountryId = @(GetFramework().Storage().GetRootId().c_str());
|
||||
NSNumber * mode = sender;
|
||||
[dvc setParentCountryId:@(GetFramework().Storage().GetRootId().c_str()) mode:static_cast<TMWMMapDownloaderMode>(mode.integerValue)];
|
||||
}
|
||||
else if ([segue.identifier isEqualToString:kMap2FBLoginSegue])
|
||||
{
|
||||
|
|
|
@ -179,7 +179,7 @@ using namespace storage;
|
|||
if ([segue.identifier isEqualToString:kDownloaderSegue])
|
||||
{
|
||||
MWMMapDownloaderViewController * dvc = segue.destinationViewController;
|
||||
dvc.parentCountryId = @(GetFramework().Storage().GetRootId().c_str());
|
||||
[dvc setParentCountryId:@(GetFramework().Storage().GetRootId().c_str()) mode:TMWMMapDownloaderMode::Downloaded];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1140,6 +1140,7 @@
|
|||
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>"; };
|
||||
34E0EECA1CC4F36B008E4919 /* MWMMapDownloaderTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMMapDownloaderTypes.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>"; };
|
||||
|
@ -1925,6 +1926,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
3418CEAB1CBF9D7700641B25 /* NoMaps */,
|
||||
34E0EECA1CC4F36B008E4919 /* MWMMapDownloaderTypes.h */,
|
||||
34DCDE3D1C76195F00652CAC /* MWMMapDownloaderProtocol.h */,
|
||||
341223B91BEB58FA007227E9 /* MWMBaseMapDownloaderViewController.h */,
|
||||
341223BA1BEB58FA007227E9 /* MWMBaseMapDownloaderViewController.mm */,
|
||||
|
|
|
@ -1990,7 +1990,7 @@
|
|||
<containerView hidden="YES" opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kXO-Oh-2vO" userLabel="No Maps Container View">
|
||||
<rect key="frame" x="0.0" y="64" width="600" height="536"/>
|
||||
<connections>
|
||||
<segue destination="3el-Zi-2E4" kind="embed" id="ish-dC-mkH"/>
|
||||
<segue destination="3el-Zi-2E4" kind="embed" identifier="MapDownloaderEmbedNoMapsSegue" id="ish-dC-mkH"/>
|
||||
</connections>
|
||||
</containerView>
|
||||
</subviews>
|
||||
|
@ -2023,6 +2023,7 @@
|
|||
<outlet property="allMapsLabel" destination="VGz-7h-6K5" id="eoI-x5-VSc"/>
|
||||
<outlet property="allMapsView" destination="st5-ZJ-F0A" id="KAY-Rx-kCC"/>
|
||||
<outlet property="allMapsViewBottomOffset" destination="wj3-ZU-xMA" id="jfn-W1-TEn"/>
|
||||
<outlet property="noMapsContainer" destination="kXO-Oh-2vO" id="fpe-Gj-ZmD"/>
|
||||
<outlet property="searchBar" destination="DPt-gs-efn" id="HS1-0c-JX8"/>
|
||||
<outlet property="statusBarBackground" destination="Xxz-fq-71r" id="W1o-7P-C8n"/>
|
||||
<outlet property="tableView" destination="CwW-x8-G3j" id="uIf-Yj-DiC"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue