From 44128df784d4f9faa3af56d6269e8def737c22fd Mon Sep 17 00:00:00 2001 From: Abhishek Banthia Date: Sat, 26 Mar 2016 16:00:51 -0400 Subject: [PATCH] Changes to accommodate new data handler class! --- .../CLTimezoneCellView.m | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/Clocker/Custom Table Cell Views/CLTimezoneCellView.m b/Clocker/Custom Table Cell Views/CLTimezoneCellView.m index 98a0c02..1af2202 100644 --- a/Clocker/Custom Table Cell Views/CLTimezoneCellView.m +++ b/Clocker/Custom Table Cell Views/CLTimezoneCellView.m @@ -34,34 +34,42 @@ NSString *originalValue = customLabelCell.stringValue; NSString *customLabelValue = [originalValue stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]]; - - - if ([[sender superview] isKindOfClass:[self class]]) { - CLTimezoneCellView *cellView = (CLTimezoneCellView *)[sender superview]; - NSData *dataObject = panelController.defaultPreferences[cellView.rowNumber]; - CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject]; + + + if ([[sender superview] isKindOfClass:[self class]]) { + CLTimezoneCellView *cellView = (CLTimezoneCellView *)[sender superview]; + NSData *dataObject = panelController.defaultPreferences[cellView.rowNumber]; + CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject]; + + [panelController.defaultPreferences enumerateObjectsUsingBlock:^(id _Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) { - [panelController.defaultPreferences enumerateObjectsUsingBlock:^(id _Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) { - - CLTimezoneData *timeObject = [CLTimezoneData getCustomObject:object]; - if ([timeObject.formattedAddress isEqualToString:customLabelValue]) { - timeObject.customLabel = CLEmptyString; - } - - - }]; + CLTimezoneData *timeObject = [CLTimezoneData getCustomObject:object]; + if ([timeObject.formattedAddress isEqualToString:customLabelValue]) { + timeObject.customLabel = CLEmptyString; + } - timezoneObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString; - NSData *newObject = [NSKeyedArchiver archivedDataWithRootObject:timezoneObject]; - [panelController.defaultPreferences replaceObjectAtIndex:cellView.rowNumber withObject:newObject]; - [[NSUserDefaults standardUserDefaults] setObject:panelController.defaultPreferences forKey:CLDefaultPreferenceKey]; - - [panelController updateDefaultPreferences]; - [panelController.mainTableview reloadData]; - [[NSNotificationCenter defaultCenter] - postNotificationName:CLCustomLabelChangedNotification - object:nil]; + }]; + + timezoneObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString; + + if ([timezoneObject.isFavourite isEqualToNumber:@1]) + { + NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezoneObject]; + [[NSUserDefaults standardUserDefaults] setObject:encodedObject + forKey:@"favouriteTimezone"]; + } + + NSData *newObject = [NSKeyedArchiver archivedDataWithRootObject:timezoneObject]; + [panelController.defaultPreferences replaceObjectAtIndex:cellView.rowNumber withObject:newObject]; + [[NSUserDefaults standardUserDefaults] setObject:panelController.defaultPreferences forKey:CLDefaultPreferenceKey]; + + [panelController updateDefaultPreferences]; + [panelController.mainTableview reloadData]; + + [[NSNotificationCenter defaultCenter] + postNotificationName:CLCustomLabelChangedNotification + object:nil]; } } @@ -84,7 +92,7 @@ { constraint.constant = width+8; } - + }]; }