diff --git a/iphone/Maps/ActiveMapsVC.mm b/iphone/Maps/ActiveMapsVC.mm index 054f1d107f..2567b59729 100644 --- a/iphone/Maps/ActiveMapsVC.mm +++ b/iphone/Maps/ActiveMapsVC.mm @@ -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 diff --git a/iphone/Maps/Classes/Common.h b/iphone/Maps/Classes/Common.h index 294388c15e..2925701bd4 100644 --- a/iphone/Maps/Classes/Common.h +++ b/iphone/Maps/Classes/Common.h @@ -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]; } diff --git a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm index b22c61d2d3..9f8c81d587 100644 --- a/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm +++ b/iphone/Maps/Classes/CustomAlert/DownloadTransitMapsAlert/MWMDownloadTransitMapAlert.mm @@ -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; } diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 89c1e9a425..f981aa3fc9 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -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(opt));}]; diff --git a/iphone/Maps/CountryTreeVC.mm b/iphone/Maps/CountryTreeVC.mm index 49e812dd01..0f59ea6033 100644 --- a/iphone/Maps/CountryTreeVC.mm +++ b/iphone/Maps/CountryTreeVC.mm @@ -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); } } diff --git a/iphone/Maps/DownloaderParentVC.h b/iphone/Maps/DownloaderParentVC.h index f635b3daeb..1a3c5dc970 100644 --- a/iphone/Maps/DownloaderParentVC.h +++ b/iphone/Maps/DownloaderParentVC.h @@ -25,8 +25,6 @@ using namespace storage; @interface DownloaderParentVC : ViewController -- (NSString *)formattedMapSize:(uint64_t)size; - - (BOOL)canDownloadSelectedMap; - (UIActionSheet *)actionSheetToCancelDownloadingSelectedMap; - (UIActionSheet *)actionSheetToPerformActionOnSelectedMap; diff --git a/iphone/Maps/DownloaderParentVC.mm b/iphone/Maps/DownloaderParentVC.mm index 7bd11c75d1..387fce3ae7 100644 --- a/iphone/Maps/DownloaderParentVC.mm +++ b/iphone/Maps/DownloaderParentVC.mm @@ -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]; }