From f4d68b9aa2267d792c83784a28bb0f46dee83409 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 9 Dec 2010 18:10:46 +0000 Subject: [PATCH] [iPhone] Countries list scrolling speed improvements [iPhone] Added custom warning dialogs for big amounts of data --- iphone/Maps/Maps.xcodeproj/project.pbxproj | 4 + .../Maps/Settings/CountriesViewController.mm | 129 ++++++++++++++++-- 2 files changed, 119 insertions(+), 14 deletions(-) diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index a2dc8e18c0..1bd9cc16f9 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ FA5005661287BFCE002961F0 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = FA5005601287BFCE002961F0 /* Icon.png */; }; FA5005671287BFCE002961F0 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA5005611287BFCE002961F0 /* Icon@2x.png */; }; FA500588128907F0002961F0 /* visibility.txt in Resources */ = {isa = PBXBuildFile; fileRef = FA500587128907F0002961F0 /* visibility.txt */; }; + FA87151B12B1518F00592DAF /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA87151A12B1518F00592DAF /* SystemConfiguration.framework */; }; FAF37EFF126DCE6F005EA154 /* IPhoneDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFA126DCE6F005EA154 /* IPhoneDownload.mm */; }; FAF37F00126DCE6F005EA154 /* IPhoneDownloadManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFB126DCE6F005EA154 /* IPhoneDownloadManager.mm */; }; FAF37F01126DCE6F005EA154 /* IPhonePlatform.mm in Sources */ = {isa = PBXBuildFile; fileRef = FAF37EFD126DCE6F005EA154 /* IPhonePlatform.mm */; }; @@ -125,6 +126,7 @@ FA5005601287BFCE002961F0 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = SOURCE_ROOT; }; FA5005611287BFCE002961F0 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = SOURCE_ROOT; }; FA500587128907F0002961F0 /* visibility.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = visibility.txt; path = ../../data/visibility.txt; sourceTree = SOURCE_ROOT; }; + FA87151A12B1518F00592DAF /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; FAF37EFA126DCE6F005EA154 /* IPhoneDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = IPhoneDownload.mm; path = Platform/IPhoneDownload.mm; sourceTree = SOURCE_ROOT; }; FAF37EFB126DCE6F005EA154 /* IPhoneDownloadManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = IPhoneDownloadManager.mm; path = Platform/IPhoneDownloadManager.mm; sourceTree = SOURCE_ROOT; }; FAF37EFD126DCE6F005EA154 /* IPhonePlatform.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = IPhonePlatform.mm; path = Platform/IPhonePlatform.mm; sourceTree = SOURCE_ROOT; }; @@ -150,6 +152,7 @@ EE12020F11CD464100ABDD5D /* libindexer.a in Frameworks */, EE12021011CD464100ABDD5D /* libmap.a in Frameworks */, EE12021211CD464100ABDD5D /* libyg.a in Frameworks */, + FA87151B12B1518F00592DAF /* SystemConfiguration.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -237,6 +240,7 @@ 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 1D30AB110D05D00D00671497 /* Foundation.framework */, 288765070DF74369002DB57D /* CoreGraphics.framework */, + FA87151A12B1518F00592DAF /* SystemConfiguration.framework */, ); name = Frameworks; sourceTree = ""; diff --git a/iphone/Maps/Settings/CountriesViewController.mm b/iphone/Maps/Settings/CountriesViewController.mm index 6389c104b0..671d706294 100644 --- a/iphone/Maps/Settings/CountriesViewController.mm +++ b/iphone/Maps/Settings/CountriesViewController.mm @@ -1,10 +1,16 @@ #import "CountriesViewController.h" #import "SettingsManager.h" +#include +#include +#import + #include "../../../map/storage.hpp" #include #define NAVIGATION_BAR_HEIGHT 44 +#define MAX_3G_MEGABYTES 100 + ///////////////////////////////////////////////////////////////// // needed for trick with back button @@ -111,9 +117,26 @@ - (void) UpdateCell: (UITableViewCell *) cell forCountry: (mapinfo::TIndex const &) countryIndex { - uint64_t size = g_pStorage->CountrySizeInBytes(countryIndex); - char const * kBOrMB = (size > 1000 * 1000) ? "MB" : "kB"; - size = (size > 1000 * 1000) ? (size / 1000 / 1000) : (size + 999) / 1000; +// uint64_t size = g_pStorage->CountrySizeInBytes(countryIndex); +// // convert size to human readable values +// uint64_t const GB = 1000 * 1000 * 1000; +// uint64_t const MB = 1000 * 1000; +// char const * sizeStr = "kB"; +// if (size > GB) +// { +// sizeStr = "GB"; +// size /= GB; +// } +// else if (size > MB) +// { +// sizeStr = "MB"; +// size /= MB; +// } +// else +// { +// sizeStr = "kB"; +// size = (size + 999) / 1000; +// } UIActivityIndicatorView * indicator = (UIActivityIndicatorView *)cell.accessoryView; @@ -122,7 +145,8 @@ case mapinfo::EOnDisk: { cell.textLabel.textColor = [UIColor greenColor]; - cell.detailTextLabel.text = [NSString stringWithFormat: @"Takes %qu %s on disk", size, kBOrMB]; +// cell.detailTextLabel.text = [NSString stringWithFormat: @"Takes %qu %s on disk", size, kBOrMB]; + cell.detailTextLabel.text = [NSString stringWithFormat: @"Downloaded, touch to delete"]; cell.accessoryView = nil; } break; @@ -147,7 +171,8 @@ case mapinfo::EInQueue: { cell.textLabel.textColor = [UIColor lightGrayColor]; - cell.detailTextLabel.text = [NSString stringWithFormat: @"Waiting to download %qu %s", size, kBOrMB]; +// cell.detailTextLabel.text = [NSString stringWithFormat: @"Waiting to download %qu %s", size, kBOrMB]; + cell.detailTextLabel.text = [NSString stringWithFormat: @"Marked for downloading, touch to cancel"]; if (!indicator) { indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray]; @@ -160,7 +185,8 @@ break; case mapinfo::ENotDownloaded: cell.textLabel.textColor = [UIColor blackColor]; - cell.detailTextLabel.text = [NSString stringWithFormat: @"Click to download %qu %s", size, kBOrMB]; +// cell.detailTextLabel.text = [NSString stringWithFormat: @"Click to download %qu %s", size, kBOrMB]; + cell.detailTextLabel.text = [NSString stringWithFormat: @"Touch to download"]; cell.accessoryView = nil; break; } @@ -183,15 +209,47 @@ // stores clicked country index when confirmation dialog is displayed mapinfo::TIndex g_clickedIndex; -// User confirmation for delete +// User confirmation after touching country - (void) actionSheet: (UIActionSheet *) actionSheet clickedButtonAtIndex: (NSInteger) buttonIndex { if (buttonIndex == 0) { // Delete country - g_pStorage->DeleteCountry(g_clickedIndex); + switch (g_pStorage->CountryStatus(g_clickedIndex)) + { + case mapinfo::ENotDownloaded: + case mapinfo::EDownloadFailed: + g_pStorage->DownloadCountry(g_clickedIndex); + break; + default: + g_pStorage->DeleteCountry(g_clickedIndex); + } } } +// return NO if not connected or using 3G ++ (BOOL) IsUsingWIFI +{ + // Create zero addy + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + // Recover reachability flags + SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); + SCNetworkReachabilityFlags flags; + BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); + CFRelease(defaultRouteReachability); + if (!didRetrieveFlags) + return NO; + + BOOL isReachable = flags & kSCNetworkFlagsReachable; + BOOL isWifi = !(flags & kSCNetworkReachabilityFlagsIsWWAN); + BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; + BOOL isConnected = isReachable && !needsConnection; + return isWifi && isConnected; +} + - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { // deselect the current row (don't keep the table selection persistent) @@ -214,12 +272,55 @@ mapinfo::TIndex g_clickedIndex; [popupQuery release]; } break; - case mapinfo::ENotDownloaded: - case mapinfo::EDownloadFailed: - g_pStorage->DownloadCountry(g_clickedIndex); + case mapinfo::ENotDownloaded: + case mapinfo::EDownloadFailed: + { // display confirmation popup with country size + BOOL isWifiConnected = [CountriesViewController IsUsingWIFI]; + + uint64_t size = g_pStorage->CountrySizeInBytes(g_clickedIndex); + // convert size to human readable values + uint64_t const GB = 1000 * 1000 * 1000; + uint64_t const MB = 1000 * 1000; + NSString * strTitle = nil; + NSString * strDownload = nil; + if (size > GB) + { + size /= GB; + if (isWifiConnected) + strTitle = [NSString stringWithFormat:@"%@", countryName]; + else + strTitle = [NSString stringWithFormat:@"We strongly recommend using WIFI for downloading %@", countryName]; + strDownload = [NSString stringWithFormat:@"Download %qu GB", size]; + } + else if (size > MB) + { + size /= MB; + if (isWifiConnected || size < MAX_3G_MEGABYTES) + strTitle = [NSString stringWithFormat:@"%@", countryName]; + else + strTitle = [NSString stringWithFormat:@"We strongly recommend using WIFI for downloading %@", countryName]; + strDownload = [NSString stringWithFormat:@"Download %qu MB", size]; + } + else + { + size = (size + 999) / 1000; + strTitle = [NSString stringWithFormat:@"%@", countryName]; + strDownload = [NSString stringWithFormat:@"Download %qu kB", size]; + } + + UIActionSheet * popupQuery = [[UIActionSheet alloc] + initWithTitle: strTitle + delegate: self + cancelButtonTitle: @"Cancel" + destructiveButtonTitle: strDownload + otherButtonTitles: nil]; + [popupQuery showFromRect: [cell frame] inView: tableView animated: YES]; + [popupQuery release]; +// g_pStorage->DownloadCountry(g_clickedIndex); + } break; - case mapinfo::EDownloading: - case mapinfo::EInQueue: + case mapinfo::EDownloading: + case mapinfo::EInQueue: // cancel download g_pStorage->DeleteCountry(g_clickedIndex); break; @@ -239,7 +340,7 @@ mapinfo::TIndex g_clickedIndex; UITableView * tableView = (UITableView *)[self.view.subviews objectAtIndex: 1]; UITableViewCell * cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: index.second inSection: index.first]]; if (cell) - cell.detailTextLabel.text = [NSString stringWithFormat: @"Downloaded %qu%%", progress.first * 100 / progress.second]; + cell.detailTextLabel.text = [NSString stringWithFormat: @"Downloading %qu%%, touch to cancel", progress.first * 100 / progress.second]; } @end