|
|
@ -1,7 +1,11 @@
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "CountryCodeTableViewCell.h"
|
|
|
|
#import "CountryCodeTableViewCell.h"
|
|
|
|
#import "CountryCodeViewController.h"
|
|
|
|
#import "CountryCodeViewController.h"
|
|
|
|
#import "PhoneNumberUtil.h"
|
|
|
|
#import "PhoneNumberUtil.h"
|
|
|
|
|
|
|
|
#import "FunctionalUtil.h"
|
|
|
|
|
|
|
|
|
|
|
|
static NSString *const CONTRY_CODE_TABLE_CELL_IDENTIFIER = @"CountryCodeTableViewCell";
|
|
|
|
static NSString *const CONTRY_CODE_TABLE_CELL_IDENTIFIER = @"CountryCodeTableViewCell";
|
|
|
|
static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryCodeWasSelectedSegue";
|
|
|
|
static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryCodeWasSelectedSegue";
|
|
|
@ -18,65 +22,9 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
|
|
|
_countryCodes = [self countryCodesForSearchTerm:nil];
|
|
|
|
_countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:nil];
|
|
|
|
self.title = NSLocalizedString(@"COUNTRYCODE_SELECT_TITLE", @"");
|
|
|
|
self.title = NSLocalizedString(@"COUNTRYCODE_SELECT_TITLE", @"");
|
|
|
|
}
|
|
|
|
self.searchBar.delegate = self;
|
|
|
|
|
|
|
|
|
|
|
|
- (NSArray *)countryCodesForSearchTerm:(NSString *)searchTerm {
|
|
|
|
|
|
|
|
NSMutableArray *result = [NSMutableArray array];
|
|
|
|
|
|
|
|
for (NSString *countryCode in [PhoneNumberUtil countryCodesForSearchTerm:nil]) {
|
|
|
|
|
|
|
|
NSString *callingCode = [self callingCodeFromCountryCode:countryCode];
|
|
|
|
|
|
|
|
if (callingCode != nil &&
|
|
|
|
|
|
|
|
![callingCode isEqualToString:@"+0"]) {
|
|
|
|
|
|
|
|
[result addObject:countryCode];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)callingCodeFromCountryCode:(NSString *)countryCode {
|
|
|
|
|
|
|
|
NSString *callingCode = [PhoneNumberUtil callingCodeFromCountryCode:countryCode];
|
|
|
|
|
|
|
|
if ([countryCode isEqualToString:@"AQ"]) {
|
|
|
|
|
|
|
|
// Antarctica
|
|
|
|
|
|
|
|
callingCode = @"+672";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"BV"]) {
|
|
|
|
|
|
|
|
// Bouvet Island
|
|
|
|
|
|
|
|
callingCode = @"+55";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"IC"]) {
|
|
|
|
|
|
|
|
// Canary Islands
|
|
|
|
|
|
|
|
callingCode = @"+34";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"EA"]) {
|
|
|
|
|
|
|
|
// Ceuta & Melilla
|
|
|
|
|
|
|
|
callingCode = @"+34";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"CP"]) {
|
|
|
|
|
|
|
|
// Clipperton Island
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// This country code should be filtered - it does not appear to have a calling code.
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"DG"]) {
|
|
|
|
|
|
|
|
// Diego Garcia
|
|
|
|
|
|
|
|
callingCode = @"+246";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"TF"]) {
|
|
|
|
|
|
|
|
// French Southern Territories
|
|
|
|
|
|
|
|
callingCode = @"+262";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"HM"]) {
|
|
|
|
|
|
|
|
// Heard & McDonald Islands
|
|
|
|
|
|
|
|
callingCode = @"+672";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"XK"]) {
|
|
|
|
|
|
|
|
// Kosovo
|
|
|
|
|
|
|
|
callingCode = @"+383";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"PN"]) {
|
|
|
|
|
|
|
|
// Pitcairn Islands
|
|
|
|
|
|
|
|
callingCode = @"+64";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"GS"]) {
|
|
|
|
|
|
|
|
// So. Georgia & So. Sandwich Isl.
|
|
|
|
|
|
|
|
callingCode = @"+500";
|
|
|
|
|
|
|
|
} else if ([countryCode isEqualToString:@"UM"]) {
|
|
|
|
|
|
|
|
// U.S. Outlying Islands
|
|
|
|
|
|
|
|
callingCode = @"+1";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return callingCode;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
@ -95,10 +43,10 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC
|
|
|
|
NSString *countryCode = _countryCodes[(NSUInteger)indexPath.row];
|
|
|
|
NSString *countryCode = _countryCodes[(NSUInteger)indexPath.row];
|
|
|
|
OWSAssert(countryCode.length > 0);
|
|
|
|
OWSAssert(countryCode.length > 0);
|
|
|
|
OWSAssert([PhoneNumberUtil countryNameFromCountryCode:countryCode].length > 0);
|
|
|
|
OWSAssert([PhoneNumberUtil countryNameFromCountryCode:countryCode].length > 0);
|
|
|
|
OWSAssert([self callingCodeFromCountryCode:countryCode].length > 0);
|
|
|
|
OWSAssert([PhoneNumberUtil callingCodeFromCountryCode:countryCode].length > 0);
|
|
|
|
OWSAssert(![[self callingCodeFromCountryCode:countryCode] isEqualToString:@"+0"]);
|
|
|
|
OWSAssert(![[PhoneNumberUtil callingCodeFromCountryCode:countryCode] isEqualToString:@"+0"]);
|
|
|
|
|
|
|
|
|
|
|
|
[cell configureWithCountryCode:[self callingCodeFromCountryCode:countryCode]
|
|
|
|
[cell configureWithCountryCode:[PhoneNumberUtil callingCodeFromCountryCode:countryCode]
|
|
|
|
andCountryName:[PhoneNumberUtil countryNameFromCountryCode:countryCode]];
|
|
|
|
andCountryName:[PhoneNumberUtil countryNameFromCountryCode:countryCode]];
|
|
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
return cell;
|
|
|
@ -106,7 +54,7 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC
|
|
|
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
NSString *countryCode = _countryCodes[(NSUInteger)indexPath.row];
|
|
|
|
NSString *countryCode = _countryCodes[(NSUInteger)indexPath.row];
|
|
|
|
_callingCodeSelected = [self callingCodeFromCountryCode:countryCode];
|
|
|
|
_callingCodeSelected = [PhoneNumberUtil callingCodeFromCountryCode:countryCode];
|
|
|
|
_countryNameSelected = [PhoneNumberUtil countryNameFromCountryCode:countryCode];
|
|
|
|
_countryNameSelected = [PhoneNumberUtil countryNameFromCountryCode:countryCode];
|
|
|
|
[self.searchBar resignFirstResponder];
|
|
|
|
[self.searchBar resignFirstResponder];
|
|
|
|
[self performSegueWithIdentifier:kUnwindToCountryCodeWasSelectedSegue sender:self];
|
|
|
|
[self performSegueWithIdentifier:kUnwindToCountryCodeWasSelectedSegue sender:self];
|
|
|
@ -119,12 +67,12 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC
|
|
|
|
#pragma mark - UISearchBarDelegate
|
|
|
|
#pragma mark - UISearchBarDelegate
|
|
|
|
|
|
|
|
|
|
|
|
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
|
|
|
|
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
|
|
|
|
_countryCodes = [self countryCodesForSearchTerm:searchText];
|
|
|
|
_countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:searchText];
|
|
|
|
[self.countryCodeTableView reloadData];
|
|
|
|
[self.countryCodeTableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope {
|
|
|
|
- (void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope {
|
|
|
|
_countryCodes = [self countryCodesForSearchTerm:searchText];
|
|
|
|
_countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:searchText];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|