[ios] Code cleanup.

This commit is contained in:
Ilya Grechuhin 2015-07-15 17:37:10 +03:00 committed by Alex Zolotarev
parent 29f38640e9
commit 4f98f57347
7 changed files with 28 additions and 36 deletions

View file

@ -1,8 +1,9 @@
#import "ActiveMapsVC.h"
#import "Statistics.h"
#import "MapCell.h"
#import "BadgeView.h"
#import "Common.h"
#import "MapCell.h"
#import "Statistics.h"
extern NSString * const MapsStatusChangedNotification;
@ -107,12 +108,13 @@ extern NSString * const MapsStatusChangedNotification;
if (status == TStatus::ENotDownloaded)
{
LocalAndRemoteSizeT const size = self.mapsLayout.GetRemoteCountrySizes(group, position);
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", formattedSize(size.first), formattedSize(size.second)];
}
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
cell.sizeLabel.text = [self formattedMapSize:self.mapsLayout.GetCountrySize(group, position, options).second];
cell.sizeLabel.text = formattedSize(self.mapsLayout.GetCountrySize(group, position, options).second);
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
cell.sizeLabel.text = [self formattedMapSize:self.mapsLayout.GetDownloadableCountrySize(group, position).second];
cell.sizeLabel.text = formattedSize(self.mapsLayout.GetDownloadableCountrySize(group, position).second);
}
#pragma mark - DownloaderParentVC virtual methods implementation

View file

@ -59,13 +59,15 @@ static inline BOOL isIOSVersionLessThan(NSUInteger version)
return isIOSVersionLessThan([NSString stringWithFormat:@"%@", @(version)]);
}
static uint64_t const KB = 1024;
static uint64_t const MB = 1024 * 1024;
static inline NSString * formattedSize(uint64_t size)
{
uint64_t const mb = 1024 * 1024;
NSString * sizeString;
if (size > mb)
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 512 * 1024) / mb, NSLocalizedString(@"mb", nil)];
if (size > MB)
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 512 * KB) / MB, NSLocalizedString(@"mb", nil)];
else
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 1023) / 1024, NSLocalizedString(@"kb", nil)];
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 1023) / KB, NSLocalizedString(@"kb", nil)];
return [sizeString uppercaseString];
}

View file

@ -7,6 +7,7 @@
//
#import "ActiveMapsVC.h"
#import "Common.h"
#import "MWMAlertViewController.h"
#import "MWMDownloaderDialogCell.h"
#import "MWMDownloaderDialogHeader.h"
@ -42,7 +43,7 @@
}
self.isMapsFiles = isMaps;
self.titles = titles;
self.size = [NSString stringWithFormat:@"%@ %@", @(totalRoutingSize / (1024 * 1024)), L(@"mb")];
self.size = [NSString stringWithFormat:@"%@ %@", @(totalRoutingSize / MB), L(@"mb")];
}
return self;
}

View file

@ -691,7 +691,7 @@ typedef NS_OPTIONS(NSUInteger, MapInfoView)
Platform::EConnectionType const connection = Platform::ConnectionStatus();
if (connection != Platform::EConnectionType::CONNECTION_NONE)
{
if (connection == Platform::EConnectionType::CONNECTION_WWAN && sizeToDownload > 50 * 1024 * 1024)
if (connection == Platform::EConnectionType::CONNECTION_WWAN && sizeToDownload > 50 * MB)
{
NSString * title = [NSString stringWithFormat:L(@"no_wifi_ask_cellular_download"), name];
[self.alertController presentnoWiFiAlertWithName:title downloadBlock:^{layout.DownloadMap(idx, static_cast<TMapOptions>(opt));}];

View file

@ -1,6 +1,7 @@
#import "CountryTreeVC.h"
#import "ActiveMapsVC.h"
#import "Common.h"
#import "CountryTreeVC.h"
#import "Statistics.h"
extern NSString * const MapsStatusChangedNotification;
@ -113,12 +114,12 @@ extern NSString * const MapsStatusChangedNotification;
if (status == TStatus::ENotDownloaded)
{
LocalAndRemoteSizeT const size = self.tree.GetRemoteLeafSizes(position);
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", [self formattedMapSize:size.first], [self formattedMapSize:size.second]];
cell.sizeLabel.text = [NSString stringWithFormat:@"%@ / %@", formattedSize(size.first), formattedSize(size.second)];
}
else if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
cell.sizeLabel.text = [self formattedMapSize:self.tree.GetLeafSize(position, options).second];
cell.sizeLabel.text = formattedSize(self.tree.GetLeafSize(position, options).second);
else if (status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed || status == TStatus::EDownloading || status == TStatus::EInQueue)
cell.sizeLabel.text = [self formattedMapSize:self.tree.GetDownloadableLeafSize(position).second];
cell.sizeLabel.text = formattedSize(self.tree.GetDownloadableLeafSize(position).second);
}
}

View file

@ -25,8 +25,6 @@ using namespace storage;
@interface DownloaderParentVC : ViewController <MapCellDelegate, UIActionSheetDelegate, UIAlertViewDelegate, UITableViewDataSource, UITableViewDelegate>
- (NSString *)formattedMapSize:(uint64_t)size;
- (BOOL)canDownloadSelectedMap;
- (UIActionSheet *)actionSheetToCancelDownloadingSelectedMap;
- (UIActionSheet *)actionSheetToPerformActionOnSelectedMap;

View file

@ -1,4 +1,4 @@
#import "Common.h"
#import "DownloaderParentVC.h"
#import "DiskFreeSpace.h"
#import "Statistics.h"
@ -65,18 +65,6 @@
#pragma mark - Public methods for successors
#define MB (1024 * 1024)
- (NSString *)formattedMapSize:(uint64_t)size
{
NSString * sizeString;
if (size > MB)
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 512 * 1024) / MB, L(@"mb")];
else
sizeString = [NSString stringWithFormat:@"%llu %@", (size + 1023) / 1024, L(@"kb")];
return [sizeString uppercaseString];
}
- (BOOL)canDownloadSelectedMap
{
uint64_t const size = [self selectedMapSizeWithOptions:self.selectedInActionSheetOptions];
@ -109,31 +97,31 @@
if (status == TStatus::ENotDownloaded || status == TStatus::EOutOfMemFailed || status == TStatus::EDownloadFailed)
{
NSString * fullSize = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]];
NSString * onlyMapSize = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::EMap]];
NSString * fullSize = formattedSize([self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]);
NSString * onlyMapSize = formattedSize([self selectedMapSizeWithOptions:TMapOptions::EMap]);
[self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_download_map"), fullSize] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
[self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_download_map_no_routing"), onlyMapSize] action:DownloaderActionDownloadMap toActionSheet:actionSheet];
}
if (status == TStatus::EOnDiskOutOfDate && options == TMapOptions::EMapWithCarRouting)
{
NSString * size = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]];
NSString * size = formattedSize([self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]);
[self addButtonWithTitle:[NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map_and_routing"), size] action:DownloaderActionDownloadAll toActionSheet:actionSheet];
}
if (status == TStatus::EOnDisk && options == TMapOptions::EMap)
{
NSString * size = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::ECarRouting]];
NSString * size = formattedSize([self selectedMapSizeWithOptions:TMapOptions::ECarRouting]);
NSString * title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_download_routing"), size];
[self addButtonWithTitle:title action:DownloaderActionDownloadCarRouting toActionSheet:actionSheet];
}
if (status == TStatus::EOnDiskOutOfDate && options == TMapOptions::EMap)
{
NSString * size = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::EMap]];
NSString * size = formattedSize([self selectedMapSizeWithOptions:TMapOptions::EMap]);
NSString * title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map"), size];
[self addButtonWithTitle:title action:DownloaderActionDownloadMap toActionSheet:actionSheet];
size = [self formattedMapSize:[self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]];
size = formattedSize([self selectedMapSizeWithOptions:TMapOptions::EMapWithCarRouting]);
title = [NSString stringWithFormat:@"%@, %@", L(@"downloader_update_map_and_routing"), size];
[self addButtonWithTitle:title action:DownloaderActionDownloadAll toActionSheet:actionSheet];
}