Browse Source

Local language search and indentation!

v1.2.3
Abhishek Banthia 9 years ago
parent
commit
c2a154139a
  1. 54
      Clocker/Preferences/CLPreferencesViewController.m

54
Clocker/Preferences/CLPreferencesViewController.m

@ -31,7 +31,7 @@ NSString *const CLParseTimezoneSelectionClassIdentifier = @"CLTimezoneSelection"
NSString *const CLParseTimezoneNameProperty = @"areaName";
NSString *const CLMaxCharactersReachedError = @"Only 50 characters allowed!";
NSString *const CLNoInternetConnectivityError = @"You're offline, maybe?";
NSString *const CLLocationSearchURL = @"https://maps.googleapis.com/maps/api/geocode/json?address=%@&key=AIzaSyCyf2knCi6KiKuDJLYDBD3Odq5dt4c-_KI";
NSString *const CLLocationSearchURL = @"https://maps.googleapis.com/maps/api/geocode/json?address=%@&key=AIzaSyCyf2knCi6KiKuDJLYDBD3Odq5dt4c-_KI&language=%@";
NSString *const CLTimezoneSearchURL = @"https://maps.googleapis.com/maps/api/timezone/json?location=%@&timestamp=%f&key=AIzaSyCyf2knCi6KiKuDJLYDBD3Odq5dt4c-_KI";
NSString *const CLTryAgainMessage = @"Try again, maybe?";
@ -115,7 +115,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
NSInteger searchCriteria = [self.searchCriteria selectedSegment];
if (searchCriteria == 0) {
return self.filteredArray.count;
return self.filteredArray.count;
}
else
{
@ -197,7 +197,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
if (self.timeZoneArray.count > row)
{
return [NSTimeZone timeZoneWithName:self.timeZoneArray[row]].abbreviation;
return [NSTimeZone timeZoneWithName:self.timeZoneArray[row]].abbreviation;
}
@ -214,7 +214,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
NSString *originalValue = (NSString *)object;
NSString *customLabelValue = [originalValue stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
[NSCharacterSet whitespaceCharacterSet]];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.selectedTimeZones[row]];
dataObject.customLabel = customLabelValue.length > 0 ? customLabelValue : CLEmptyString;
@ -222,6 +222,13 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[self.selectedTimeZones replaceObjectAtIndex:row withObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTimeZones forKey:CLDefaultPreferenceKey];
if ([dataObject.isFavourite isEqualToNumber:@1])
{
[[NSUserDefaults standardUserDefaults] setObject:encodedObject
forKey:@"favouriteTimezone"];
}
[self refreshMainTableview];
}
else
@ -229,19 +236,19 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
NSMutableArray *newArray = [NSMutableArray new];
[self.selectedTimeZones enumerateObjectsUsingBlock:^(NSData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
{
CLTimezoneData *timezone = [CLTimezoneData getCustomObject:object];
timezone.isFavourite = [NSNumber numberWithInt:0];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezone];
[newArray addObject:encodedObject];
{
CLTimezoneData *timezone = [CLTimezoneData getCustomObject:obj];
timezone.isFavourite = [NSNumber numberWithInt:0];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezone];
[newArray addObject:encodedObject];
}];
}];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:newArray[row]];
dataObject.isFavourite = object;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:dataObject];
[newArray replaceObjectAtIndex:row withObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
(dataObject.isFavourite.integerValue == 1) ?
@ -441,11 +448,11 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
- (IBAction)filterTimezoneArray:(id)sender
{
if (self.searchField.stringValue.length > 0) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:CLSearchPredicateKey, self.searchField.stringValue];
NSPredicate *predicate = [NSPredicate predicateWithFormat:CLSearchPredicateKey, self.searchField.stringValue];
self.timeZoneFilteredArray = [NSMutableArray arrayWithArray:[self.timeZoneArray filteredArrayUsingPredicate:predicate]];
self.timeZoneFilteredArray = [NSMutableArray arrayWithArray:[self.timeZoneArray filteredArrayUsingPredicate:predicate]];
[self.availableTimezoneTableView reloadData];
[self.availableTimezoneTableView reloadData];
}
}
@ -492,14 +499,14 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
- (void)refereshTimezoneTableView
{
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *defaultTimeZones = [[NSUserDefaults standardUserDefaults]
objectForKey:CLDefaultPreferenceKey];
NSMutableArray *defaultTimeZones = [[NSUserDefaults standardUserDefaults]
objectForKey:CLDefaultPreferenceKey];
self.selectedTimeZones = [[NSMutableArray alloc] initWithArray:defaultTimeZones];
self.selectedTimeZones = [[NSMutableArray alloc] initWithArray:defaultTimeZones];
[self.timezoneTableView reloadData];
[self.timezoneTableView reloadData];
});
}
@ -570,9 +577,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[self.dataTask cancel];
}
NSString *preferredLanguage = [[[NSBundle mainBundle]preferredLocalizations][0] substringToIndex:2];
NSLog(@"Preferred Language:%@", preferredLanguage);
NSString *preferredLanguage = [NSLocale preferredLanguages][0];
dispatch_async(dispatch_get_main_queue(), ^{
@ -589,7 +594,6 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
return;
}
});
self.activityInProgress = YES;
@ -599,7 +603,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
NSArray* words = [searchString componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceAndNewlineCharacterSet]];
searchString = [words componentsJoinedByString:CLEmptyString];
NSString *urlString = [NSString stringWithFormat:CLLocationSearchURL, searchString];
NSString *urlString = [NSString stringWithFormat:CLLocationSearchURL, searchString, preferredLanguage];
[CLAPI dataTaskWithServicePath:urlString
bySender:self
@ -808,7 +812,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
}
else
{
self.searchField.placeholderString = @"Enter a timezone name";
self.searchField.placeholderString = @"Enter a timezone name";
self.columnName = @"Timezone(s)";
self.abbreviation.hidden = NO;
self.timeZoneArray = [NSMutableArray arrayWithArray:[NSTimeZone knownTimeZoneNames]];

Loading…
Cancel
Save