Abhishek Banthia
9 years ago
22 changed files with 844 additions and 743 deletions
Binary file not shown.
@ -0,0 +1,24 @@ |
|||||||
|
//
|
||||||
|
// CLTimezoneDataOperations.h
|
||||||
|
// Clocker
|
||||||
|
//
|
||||||
|
// Created by Abhishek Banthia on 7/24/16.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h> |
||||||
|
#import "CLTimezoneData.h" |
||||||
|
|
||||||
|
@interface CLTimezoneDataOperations : NSObject |
||||||
|
|
||||||
|
@property (readonly) CLTimezoneData *dataObject; |
||||||
|
|
||||||
|
- (instancetype)initWithTimezoneData:(CLTimezoneData *)timezoneData; |
||||||
|
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue; |
||||||
|
- (void)save; |
||||||
|
- (NSString *)getMenuTitle; |
||||||
|
- (NSString *)getFormattedSunriseOrSunsetTimeAndSliderValue:(NSInteger)sliderValue; |
||||||
|
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue |
||||||
|
andDisplayType:(CLDateDisplayType)type; |
||||||
|
|
||||||
|
@end |
@ -0,0 +1,393 @@ |
|||||||
|
// |
||||||
|
// CLTimezoneDataOperations.m |
||||||
|
// Clocker |
||||||
|
// |
||||||
|
// Created by Abhishek Banthia on 7/24/16. |
||||||
|
// |
||||||
|
// |
||||||
|
|
||||||
|
#import "CLTimezoneDataOperations.h" |
||||||
|
#import "CommonStrings.h" |
||||||
|
#import "PanelController.h" |
||||||
|
#import "DateTools.h" |
||||||
|
#include "EDSunriseSet.h" |
||||||
|
#import "CLAPIConnector.h" |
||||||
|
|
||||||
|
@interface CLTimezoneDataOperations () |
||||||
|
|
||||||
|
@property (strong, nonatomic) CLTimezoneData *dataObject; |
||||||
|
|
||||||
|
@end |
||||||
|
|
||||||
|
@implementation CLTimezoneDataOperations |
||||||
|
|
||||||
|
- (instancetype)initWithTimezoneData:(CLTimezoneData *)timezoneData |
||||||
|
{ |
||||||
|
self = [super init]; |
||||||
|
|
||||||
|
if (self) |
||||||
|
{ |
||||||
|
self.dataObject = timezoneData; |
||||||
|
} |
||||||
|
|
||||||
|
return self; |
||||||
|
} |
||||||
|
|
||||||
|
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue |
||||||
|
{ |
||||||
|
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar]; |
||||||
|
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitMinute |
||||||
|
value:futureSliderValue |
||||||
|
toDate:[NSDate date] |
||||||
|
options:kNilOptions]; |
||||||
|
NSDateFormatter *dateFormatter = [NSDateFormatter new]; |
||||||
|
dateFormatter.dateStyle = kCFDateFormatterNoStyle; |
||||||
|
|
||||||
|
NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey]; |
||||||
|
|
||||||
|
dateFormatter.dateFormat = is24HourFormatSelected.boolValue ? @"HH:mm" : @"hh:mm a"; |
||||||
|
|
||||||
|
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.dataObject.timezoneID]; |
||||||
|
//In the format 22:10 |
||||||
|
|
||||||
|
return [dateFormatter stringFromDate:newDate]; |
||||||
|
} |
||||||
|
|
||||||
|
- (NSString *)getMenuTitle |
||||||
|
{ |
||||||
|
NSMutableString *menuTitle = [NSMutableString new]; |
||||||
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
||||||
|
NSNumber *shouldCityBeShown = [userDefaults objectForKey:CLShowPlaceInMenu]; |
||||||
|
NSNumber *shouldDayBeShown = [userDefaults objectForKey:CLShowDayInMenu]; |
||||||
|
NSNumber *shouldDateBeShown = [userDefaults objectForKey:CLShowDateInMenu]; |
||||||
|
|
||||||
|
if (shouldCityBeShown.boolValue == 0) |
||||||
|
{ |
||||||
|
|
||||||
|
self.dataObject.customLabel.length > 0 ? |
||||||
|
[menuTitle appendString:self.dataObject.customLabel] : |
||||||
|
[menuTitle appendString:self.dataObject.formattedAddress]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
if (shouldDayBeShown.boolValue == 0) |
||||||
|
{ |
||||||
|
NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0 andDisplayType:CLMenuDisplay]; |
||||||
|
|
||||||
|
substring = [substring substringToIndex:3]; |
||||||
|
|
||||||
|
if (menuTitle.length > 0) |
||||||
|
{ |
||||||
|
[menuTitle appendFormat:@" %@",substring.capitalizedString]; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
[menuTitle appendString:substring.capitalizedString]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (shouldDateBeShown.boolValue == 0) |
||||||
|
{ |
||||||
|
NSString *date = [[NSDate date] formattedDateWithFormat:@"MMM dd" timeZone:[NSTimeZone timeZoneWithName:self.dataObject.timezoneID] locale:[NSLocale currentLocale]]; |
||||||
|
|
||||||
|
if (menuTitle.length > 0) |
||||||
|
{ |
||||||
|
[menuTitle appendFormat:@" %@",date]; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
[menuTitle appendString:date]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
menuTitle.length > 0 ? |
||||||
|
[menuTitle appendFormat:@" %@",[self getTimeForTimeZoneWithFutureSliderValue:0]] : |
||||||
|
[menuTitle appendString:[self getTimeForTimeZoneWithFutureSliderValue:0]]; |
||||||
|
|
||||||
|
return menuTitle; |
||||||
|
} |
||||||
|
|
||||||
|
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date |
||||||
|
{ |
||||||
|
NSDateFormatter *formatter = [NSDateFormatter new]; |
||||||
|
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy" |
||||||
|
options:0 |
||||||
|
locale:[NSLocale currentLocale]]; |
||||||
|
|
||||||
|
NSDate *localDate = [formatter dateFromString:systemDate]; |
||||||
|
NSDate *timezoneDate = [formatter dateFromString:date]; |
||||||
|
|
||||||
|
// Specify which units we would like to use |
||||||
|
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; |
||||||
|
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate]; |
||||||
|
|
||||||
|
if ([self.dataObject.nextUpdate isKindOfClass:[NSString class]]) |
||||||
|
{ |
||||||
|
|
||||||
|
NSUInteger units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; |
||||||
|
NSDateComponents *comps = [[NSCalendar currentCalendar] components:units fromDate:timezoneDate]; |
||||||
|
comps.day = comps.day + 1; |
||||||
|
NSDate *tomorrowMidnight = [[NSCalendar currentCalendar] dateFromComponents:comps]; |
||||||
|
|
||||||
|
NSDictionary *dictionary = @{CLTimezoneID : self.dataObject.timezoneID, @"latitude" : self.dataObject.latitude, |
||||||
|
@"longitude" : self.dataObject.longitude, CLCustomLabel : self.dataObject.customLabel, |
||||||
|
CLPlaceIdentifier : self.dataObject.place_id, CLTimezoneName : self.dataObject.formattedAddress}; |
||||||
|
|
||||||
|
|
||||||
|
CLTimezoneData *newDataObject = [[CLTimezoneData alloc] initWithDictionary:dictionary]; |
||||||
|
[newDataObject setNextUpdateForSunriseSet:tomorrowMidnight]; |
||||||
|
|
||||||
|
PanelController *panelController = [PanelController getPanelControllerInstance]; |
||||||
|
|
||||||
|
(panelController.defaultPreferences)[[panelController.defaultPreferences indexOfObject:self]] = newDataObject; |
||||||
|
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:panelController.defaultPreferences forKey:CLDefaultPreferenceKey]; |
||||||
|
} |
||||||
|
|
||||||
|
NSInteger daysApart = [timezoneDate daysFrom:localDate]; |
||||||
|
|
||||||
|
if (daysApart == 0) { |
||||||
|
return @"Today"; |
||||||
|
} |
||||||
|
else if (daysApart == -1) |
||||||
|
{ |
||||||
|
return @"Yesterday"; |
||||||
|
} |
||||||
|
else if (daysApart == 1) |
||||||
|
{ |
||||||
|
return @"Tomorrow"; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
return [self getWeekdayFromInteger:weekday+2]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue |
||||||
|
andDisplayType:(CLDateDisplayType)type |
||||||
|
{ |
||||||
|
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar]; |
||||||
|
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitMinute |
||||||
|
value:futureSliderValue |
||||||
|
toDate:[NSDate date] |
||||||
|
options:kNilOptions]; |
||||||
|
NSDateFormatter *dateFormatter = [NSDateFormatter new]; |
||||||
|
dateFormatter.dateStyle = kCFDateFormatterShortStyle; |
||||||
|
dateFormatter.timeStyle = kCFDateFormatterNoStyle; |
||||||
|
|
||||||
|
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.dataObject.timezoneID]; |
||||||
|
|
||||||
|
NSNumber *relativeDayPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey]; |
||||||
|
if (relativeDayPreference.integerValue == 0 && type == CLPanelDisplay) { |
||||||
|
return [self compareSystemDate:[self getLocalCurrentDate] |
||||||
|
toTimezoneDate:[dateFormatter stringFromDate:newDate]]; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
NSDateFormatter *formatter = [NSDateFormatter new]; |
||||||
|
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy" options:0 locale:[NSLocale currentLocale]]; |
||||||
|
|
||||||
|
NSDate *convertedDate = [formatter dateFromString:[dateFormatter stringFromDate:newDate]]; |
||||||
|
|
||||||
|
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; |
||||||
|
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:convertedDate]; |
||||||
|
return [self getWeekdayFromInteger:weekday]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
- (NSString *)getLocalCurrentDate |
||||||
|
{ |
||||||
|
NSDateFormatter *dateFormatter = [NSDateFormatter new]; |
||||||
|
dateFormatter.dateStyle = kCFDateFormatterShortStyle; |
||||||
|
dateFormatter.timeStyle = kCFDateFormatterNoStyle; |
||||||
|
dateFormatter.timeZone = [NSTimeZone systemTimeZone]; |
||||||
|
|
||||||
|
return [NSDateFormatter localizedStringFromDate:[NSDate date] |
||||||
|
dateStyle:NSDateFormatterShortStyle |
||||||
|
timeStyle:NSDateFormatterNoStyle]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
- (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger |
||||||
|
{ |
||||||
|
|
||||||
|
if (weekdayInteger > 7) { |
||||||
|
weekdayInteger = weekdayInteger - 7; |
||||||
|
} |
||||||
|
|
||||||
|
switch (weekdayInteger) { |
||||||
|
case 1: |
||||||
|
return @"Sunday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 2: |
||||||
|
return @"Monday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 3: |
||||||
|
return @"Tuesday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 4: |
||||||
|
return @"Wednesday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 5: |
||||||
|
return @"Thursday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 6: |
||||||
|
return @"Friday"; |
||||||
|
break; |
||||||
|
|
||||||
|
case 7: |
||||||
|
return @"Saturday"; |
||||||
|
break; |
||||||
|
|
||||||
|
default: |
||||||
|
return @"Error"; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
-(NSString *)getFormattedSunriseOrSunsetTimeAndSliderValue:(NSInteger)sliderValue |
||||||
|
{ |
||||||
|
/* We have to call this everytime so that we get an updated value everytime! */ |
||||||
|
|
||||||
|
[self initializeSunriseSunsetWithSliderValue:sliderValue]; |
||||||
|
|
||||||
|
if (!self.dataObject.sunriseTime && !self.dataObject.sunsetTime) |
||||||
|
{ |
||||||
|
return CLEmptyString; |
||||||
|
} |
||||||
|
|
||||||
|
[self.dataObject setSunriseOrSunsetForTimezone:[self.dataObject.sunriseTime isLaterThanOrEqualTo:[NSDate date]]]; |
||||||
|
|
||||||
|
NSDate *newDate = self.dataObject.sunriseOrSunset ? self.dataObject.sunriseTime : self.dataObject.sunsetTime; |
||||||
|
|
||||||
|
NSDateFormatter *dateFormatter = [NSDateFormatter new]; |
||||||
|
|
||||||
|
dateFormatter.dateStyle = kCFDateFormatterNoStyle; |
||||||
|
|
||||||
|
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.dataObject.timezoneID]; |
||||||
|
|
||||||
|
NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey]; |
||||||
|
|
||||||
|
dateFormatter.dateFormat = is24HourFormatSelected.boolValue ? @"HH:mm" : @"hh:mm a"; |
||||||
|
|
||||||
|
//In the format 22:10 |
||||||
|
|
||||||
|
return [dateFormatter stringFromDate:newDate]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
-(void)initializeSunriseSunsetWithSliderValue:(NSInteger)sliderValue |
||||||
|
{ |
||||||
|
|
||||||
|
if (!self.dataObject.latitude || !self.dataObject.longitude) |
||||||
|
{ |
||||||
|
//Retrieve the values using Google Places API |
||||||
|
|
||||||
|
if (self.dataObject.selectionType == CLTimezoneSelection) |
||||||
|
{ |
||||||
|
/* A timezone has been selected*/ |
||||||
|
|
||||||
|
NSLog(@"%@", self); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
[self retrieveLatitudeAndLongitudeWithSearchString:self.dataObject.formattedAddress]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
EDSunriseSet *sunriseSetObject = [EDSunriseSet sunrisesetWithDate:[[NSCalendar autoupdatingCurrentCalendar] |
||||||
|
dateByAddingUnit:NSCalendarUnitMinute |
||||||
|
value:sliderValue |
||||||
|
toDate:[NSDate date] |
||||||
|
options:kNilOptions] |
||||||
|
timezone:[NSTimeZone timeZoneWithName:self.dataObject.timezoneID] |
||||||
|
latitude:self.dataObject.latitude.doubleValue |
||||||
|
longitude:self.dataObject.longitude.doubleValue]; |
||||||
|
|
||||||
|
[self.dataObject setSunriseTimeForTimezone:sunriseSetObject.sunrise]; |
||||||
|
[self.dataObject setSunsetTimeForTimezone:sunriseSetObject.sunset]; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
- (void)retrieveLatitudeAndLongitudeWithSearchString:(NSString *)formattedString |
||||||
|
{ |
||||||
|
NSString *preferredLanguage = [NSLocale preferredLanguages][0]; |
||||||
|
|
||||||
|
if (![CLAPIConnector isUserConnectedToInternet]) |
||||||
|
{ |
||||||
|
/*Show some kind of information label*/ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
NSArray* words = [formattedString componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceAndNewlineCharacterSet]]; |
||||||
|
|
||||||
|
formattedString = [words componentsJoinedByString:CLEmptyString]; |
||||||
|
|
||||||
|
NSString *urlString = [NSString stringWithFormat:CLLocationSearchURL, formattedString, preferredLanguage]; |
||||||
|
|
||||||
|
[CLAPIConnector dataTaskWithServicePath:urlString |
||||||
|
bySender:self |
||||||
|
withCompletionBlock:^(NSError *error, NSDictionary *json) { |
||||||
|
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{ |
||||||
|
|
||||||
|
if (error || [json[@"status"] isEqualToString:@"ZERO_RESULTS"]) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[json[@"results"] enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dictionary, NSUInteger idx, BOOL * _Nonnull stop) |
||||||
|
{ |
||||||
|
|
||||||
|
if ([dictionary[CLPlaceIdentifier] isEqualToString:self.dataObject.place_id]) |
||||||
|
{ |
||||||
|
//We have a match |
||||||
|
|
||||||
|
NSDictionary *latLang = dictionary[@"geometry"][@"location"]; |
||||||
|
|
||||||
|
[self.dataObject setLatitudeForTimezone:[NSString stringWithFormat:@"%@", latLang[@"lat"]]]; |
||||||
|
[self.dataObject setLongitudeForTimezone:[NSString stringWithFormat:@"%@", latLang[@"lng"]]]; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
}]; |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
}]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
- (void)save |
||||||
|
{ |
||||||
|
NSArray *defaultPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey]; |
||||||
|
|
||||||
|
if (defaultPreference == nil) |
||||||
|
{ |
||||||
|
defaultPreference = [NSMutableArray new]; |
||||||
|
} |
||||||
|
|
||||||
|
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:self.dataObject]; |
||||||
|
|
||||||
|
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:defaultPreference]; |
||||||
|
|
||||||
|
[newArray addObject:encodedObject]; |
||||||
|
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey]; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@end |
@ -0,0 +1,15 @@ |
|||||||
|
//
|
||||||
|
// CLTableViewDataSource.h
|
||||||
|
// Clocker
|
||||||
|
//
|
||||||
|
// Created by Abhishek Banthia on 7/25/16.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h> |
||||||
|
|
||||||
|
@interface CLTableViewDataSource : NSObject <NSTableViewDataSource, NSTableViewDelegate> |
||||||
|
|
||||||
|
- (instancetype)initWithItems:(NSArray *)objects; |
||||||
|
|
||||||
|
@end |
@ -0,0 +1,190 @@ |
|||||||
|
// |
||||||
|
// CLTableViewDataSource.m |
||||||
|
// Clocker |
||||||
|
// |
||||||
|
// Created by Abhishek Banthia on 7/25/16. |
||||||
|
// |
||||||
|
// |
||||||
|
|
||||||
|
#import "CLTableViewDataSource.h" |
||||||
|
#import "CLTimezoneCellView.h" |
||||||
|
#import "CLTimezoneData.h" |
||||||
|
#import "CLTimezoneDataOperations.h" |
||||||
|
#import "CLRatingCellView.h" |
||||||
|
#import "CommonStrings.h" |
||||||
|
#import "CLOneWindowController.h" |
||||||
|
|
||||||
|
NSString *const CLRatingCellViewID = @"ratingCellView"; |
||||||
|
NSString *const CLTimezoneCellViewID = @"timeZoneCell"; |
||||||
|
|
||||||
|
@interface CLTableViewDataSource() |
||||||
|
|
||||||
|
@property (strong) NSMutableArray *timezoneObjects; |
||||||
|
@property (assign) BOOL showReviewCell; |
||||||
|
@property (assign) NSInteger futureSliderValue; |
||||||
|
|
||||||
|
@end |
||||||
|
|
||||||
|
@implementation CLTableViewDataSource |
||||||
|
|
||||||
|
-(instancetype)initWithItems:(NSMutableArray *)objects |
||||||
|
{ |
||||||
|
self = [super init]; |
||||||
|
|
||||||
|
if (self) { |
||||||
|
self.timezoneObjects = objects; |
||||||
|
} |
||||||
|
|
||||||
|
return self; |
||||||
|
} |
||||||
|
|
||||||
|
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView |
||||||
|
{ |
||||||
|
if (self.showReviewCell) { |
||||||
|
return self.timezoneObjects.count+1; |
||||||
|
} |
||||||
|
return self.timezoneObjects.count; |
||||||
|
} |
||||||
|
-(NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
||||||
|
{ |
||||||
|
if (self.showReviewCell && row == self.timezoneObjects.count) { |
||||||
|
CLRatingCellView *cellView = [tableView |
||||||
|
makeViewWithIdentifier:CLRatingCellViewID |
||||||
|
owner:self]; |
||||||
|
return cellView; |
||||||
|
} |
||||||
|
|
||||||
|
CLTimezoneCellView *cell = [tableView makeViewWithIdentifier:CLTimezoneCellViewID owner:self]; |
||||||
|
|
||||||
|
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.timezoneObjects[row]]; |
||||||
|
|
||||||
|
CLTimezoneDataOperations *dataOperation = [[CLTimezoneDataOperations alloc] initWithTimezoneData:dataObject]; |
||||||
|
|
||||||
|
cell.sunriseSetTime.stringValue = [dataOperation getFormattedSunriseOrSunsetTimeAndSliderValue:self.futureSliderValue]; |
||||||
|
|
||||||
|
cell.relativeDate.stringValue = [dataOperation getDateForTimeZoneWithFutureSliderValue:self.futureSliderValue andDisplayType:CLPanelDisplay]; |
||||||
|
|
||||||
|
cell.time.stringValue = [dataOperation getTimeForTimeZoneWithFutureSliderValue:self.futureSliderValue]; |
||||||
|
|
||||||
|
cell.rowNumber = row; |
||||||
|
|
||||||
|
cell.customName.stringValue = [dataObject getFormattedTimezoneLabel]; |
||||||
|
|
||||||
|
return cell; |
||||||
|
} |
||||||
|
|
||||||
|
-(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row |
||||||
|
{ |
||||||
|
NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey]; |
||||||
|
|
||||||
|
CLTimezoneCellView *cell = (CLTimezoneCellView *)[rowView viewAtColumn:0]; |
||||||
|
|
||||||
|
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.timezoneObjects[row]]; |
||||||
|
|
||||||
|
NSTextView *customLabel = (NSTextView*)[cell.relativeDate.window |
||||||
|
fieldEditor:YES |
||||||
|
forObject:cell.relativeDate]; |
||||||
|
|
||||||
|
if (theme.integerValue == 1) |
||||||
|
{ |
||||||
|
tableView.backgroundColor = [NSColor blackColor]; |
||||||
|
customLabel.insertionPointColor = [NSColor whiteColor]; |
||||||
|
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ? |
||||||
|
[NSImage imageNamed:@"White Sunrise"] : [NSImage imageNamed:@"White Sunset"]; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
|
||||||
|
tableView.backgroundColor = [NSColor whiteColor]; |
||||||
|
customLabel.insertionPointColor = [NSColor blackColor]; |
||||||
|
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ? |
||||||
|
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"Sunset"]; |
||||||
|
} |
||||||
|
|
||||||
|
NSNumber *displaySunriseSunsetTime = [[NSUserDefaults standardUserDefaults] objectForKey:CLSunriseSunsetTime]; |
||||||
|
|
||||||
|
cell.sunriseSetTime.hidden = ([displaySunriseSunsetTime isEqualToNumber:@(0)] && cell.sunriseSetTime.stringValue.length > 0) ? NO : YES; |
||||||
|
|
||||||
|
cell.sunriseSetImage.hidden = [displaySunriseSunsetTime isEqualToNumber:@(0)] && cell.sunriseSetTime.stringValue.length > 0 ? NO : YES; |
||||||
|
|
||||||
|
/*WE hide the Sunrise or set details because of chances of incorrect date calculations |
||||||
|
*/ |
||||||
|
|
||||||
|
if (self.futureSliderValue > 0) |
||||||
|
{ |
||||||
|
cell.sunriseSetImage.hidden = YES; |
||||||
|
cell.sunriseSetTime.hidden = YES; |
||||||
|
} |
||||||
|
|
||||||
|
[cell setUpLayout]; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard |
||||||
|
{ |
||||||
|
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes]; |
||||||
|
[pboard declareTypes:@[CLDragSessionKey] owner:self]; |
||||||
|
[pboard setData:data forType:CLDragSessionKey]; |
||||||
|
return YES; |
||||||
|
} |
||||||
|
|
||||||
|
-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row |
||||||
|
{ |
||||||
|
if ([object isKindOfClass:[NSString class]]) |
||||||
|
{ |
||||||
|
CLTimezoneData *dataObject = self.timezoneObjects[row]; |
||||||
|
|
||||||
|
if ([dataObject.formattedAddress isEqualToString:object]) |
||||||
|
{ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
[dataObject setLabelForTimezone:object]; |
||||||
|
(self.timezoneObjects)[row] = dataObject; |
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:self.timezoneObjects forKey:CLDefaultPreferenceKey]; |
||||||
|
[tableView reloadData]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
-(BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation |
||||||
|
{ |
||||||
|
|
||||||
|
if (row == self.timezoneObjects.count) |
||||||
|
{ |
||||||
|
row -= 1; |
||||||
|
} |
||||||
|
|
||||||
|
NSPasteboard *pBoard = [info draggingPasteboard]; |
||||||
|
|
||||||
|
NSData *data = [pBoard dataForType:CLDragSessionKey]; |
||||||
|
|
||||||
|
NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:data]; |
||||||
|
|
||||||
|
[self.timezoneObjects exchangeObjectAtIndex:rowIndexes.firstIndex |
||||||
|
withObjectAtIndex:row]; |
||||||
|
|
||||||
|
[[NSUserDefaults standardUserDefaults] setObject:self.timezoneObjects |
||||||
|
forKey:CLDefaultPreferenceKey]; |
||||||
|
|
||||||
|
|
||||||
|
[[NSApplication sharedApplication].windows enumerateObjectsUsingBlock:^(NSWindow * _Nonnull window, NSUInteger idx, BOOL * _Nonnull stop) { |
||||||
|
if ([window.windowController isMemberOfClass:[CLOneWindowController class]]) { |
||||||
|
CLOneWindowController *oneWindowController = (CLOneWindowController *) window.windowController; |
||||||
|
[oneWindowController.preferencesView refereshTimezoneTableView]; |
||||||
|
} |
||||||
|
|
||||||
|
}]; |
||||||
|
|
||||||
|
[tableView reloadData]; |
||||||
|
|
||||||
|
return YES; |
||||||
|
} |
||||||
|
|
||||||
|
-(NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation |
||||||
|
{ |
||||||
|
return NSDragOperationEvery; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@end |
Loading…
Reference in new issue