Browse Source

Separation of concerns.

v1.2.4
Abhishek Banthia 8 years ago
parent
commit
11edf3c04d
  1. 12
      Clocker.xcodeproj/project.pbxproj
  2. BIN
      Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate
  3. 14
      Clocker.xcodeproj/xcuserdata/abhishekbanthia.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
  4. 58
      Clocker/ApplicationDelegate.m
  5. 18
      Clocker/CLParentPanelController.m
  6. 6
      Clocker/Custom Table Cell Views/CLTimezoneCellView.m
  7. 161
      Clocker/Floating Window/CLFloatingWindowController.m
  8. 4
      Clocker/Floating Window/en.lproj/CLFloatingWindow.xib
  9. 4
      Clocker/Floating Window/ja.lproj/CLFloatingWindow.xib
  10. 4
      Clocker/Floating Window/zh-Hans.lproj/CLFloatingWindow.xib
  11. 4
      Clocker/Floating Window/zh-Hant.lproj/CLFloatingWindow.xib
  12. 6
      Clocker/MenubarController.m
  13. 43
      Clocker/Model/CLTimezoneData.h
  14. 376
      Clocker/Model/CLTimezoneData.m
  15. 24
      Clocker/Model/CLTimezoneDataOperations.h
  16. 393
      Clocker/Model/CLTimezoneDataOperations.m
  17. 20
      Clocker/Onboarding/CLIntroViewController.m
  18. 137
      Clocker/PanelController.m
  19. 92
      Clocker/Preferences/CLPreferencesViewController.m
  20. 6
      Clocker/StatusItemView.m
  21. 15
      Clocker/Utilities/CLTableViewDataSource.h
  22. 190
      Clocker/Utilities/CLTableViewDataSource.m

12
Clocker.xcodeproj/project.pbxproj

@ -43,6 +43,8 @@
9A5951FD1C1D592D009C17AA /* iVersion.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 9A5951FC1C1D592D009C17AA /* iVersion.bundle */; };
9A5B6C6E1D3DF6E4000EAAF1 /* CLParentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B6C6D1D3DF6E4000EAAF1 /* CLParentViewController.m */; };
9A5B6C711D4087A5000EAAF1 /* NSString+CLStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B6C701D4087A5000EAAF1 /* NSString+CLStringAdditions.m */; };
9A5B6C781D459438000EAAF1 /* CLTimezoneDataOperations.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B6C771D459438000EAAF1 /* CLTimezoneDataOperations.m */; };
9A5B6C7C1D470ECB000EAAF1 /* CLTableViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A5B6C7B1D470ECB000EAAF1 /* CLTableViewDataSource.m */; };
9A5E6BAB1CAF8DFA006E7C5C /* iRate.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 9A5E6BAA1CAF8DFA006E7C5C /* iRate.bundle */; };
9A63620A1C432F68004AD010 /* CLAPIConnector.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A6362091C432F68004AD010 /* CLAPIConnector.m */; };
9A6D93371CF3E82F005A8690 /* CoreImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A6D93361CF3E82F005A8690 /* CoreImage.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
@ -255,6 +257,10 @@
9A5B6C6D1D3DF6E4000EAAF1 /* CLParentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLParentViewController.m; path = Clocker/CLParentViewController.m; sourceTree = "<group>"; };
9A5B6C6F1D4087A5000EAAF1 /* NSString+CLStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+CLStringAdditions.h"; path = "Clocker/Utilities/NSString+CLStringAdditions.h"; sourceTree = "<group>"; };
9A5B6C701D4087A5000EAAF1 /* NSString+CLStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+CLStringAdditions.m"; path = "Clocker/Utilities/NSString+CLStringAdditions.m"; sourceTree = "<group>"; };
9A5B6C761D459438000EAAF1 /* CLTimezoneDataOperations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CLTimezoneDataOperations.h; path = Clocker/Model/CLTimezoneDataOperations.h; sourceTree = "<group>"; };
9A5B6C771D459438000EAAF1 /* CLTimezoneDataOperations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLTimezoneDataOperations.m; path = Clocker/Model/CLTimezoneDataOperations.m; sourceTree = "<group>"; };
9A5B6C7A1D470ECB000EAAF1 /* CLTableViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CLTableViewDataSource.h; path = Clocker/Utilities/CLTableViewDataSource.h; sourceTree = "<group>"; };
9A5B6C7B1D470ECB000EAAF1 /* CLTableViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CLTableViewDataSource.m; path = Clocker/Utilities/CLTableViewDataSource.m; sourceTree = "<group>"; };
9A5E6B9F1CAF71C1006E7C5C /* libicucore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.tbd; path = usr/lib/libicucore.tbd; sourceTree = SDKROOT; };
9A5E6BA11CAF794D006E7C5C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
9A5E6BA21CAF794D006E7C5C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
@ -397,6 +403,8 @@
9A10C68E1CDAC8B500D474F1 /* CLPanelTextField.m */,
9A5B6C6F1D4087A5000EAAF1 /* NSString+CLStringAdditions.h */,
9A5B6C701D4087A5000EAAF1 /* NSString+CLStringAdditions.m */,
9A5B6C7A1D470ECB000EAAF1 /* CLTableViewDataSource.h */,
9A5B6C7B1D470ECB000EAAF1 /* CLTableViewDataSource.m */,
);
name = Utilties;
sourceTree = "<group>";
@ -598,6 +606,8 @@
children = (
9ABF58701C29A80600BD0187 /* CLTimezoneData.h */,
9ABF58711C29A80600BD0187 /* CLTimezoneData.m */,
9A5B6C761D459438000EAAF1 /* CLTimezoneDataOperations.h */,
9A5B6C771D459438000EAAF1 /* CLTimezoneDataOperations.m */,
);
name = Model;
sourceTree = "<group>";
@ -876,6 +886,7 @@
9A79E9901CB34B6800BA7916 /* CLParentPanelController.m in Sources */,
9A87DAC51C358FA800A8CF3B /* DTConstants.m in Sources */,
9AB9357B1C1AD8F7001285A0 /* CLRatingCellView.m in Sources */,
9A5B6C781D459438000EAAF1 /* CLTimezoneDataOperations.m in Sources */,
9A63620A1C432F68004AD010 /* CLAPIConnector.m in Sources */,
9A87DAC81C358FA800A8CF3B /* DTTimePeriodChain.m in Sources */,
9A87DAC71C358FA800A8CF3B /* DTTimePeriod.m in Sources */,
@ -886,6 +897,7 @@
9A5951FA1C1D5214009C17AA /* iVersion.m in Sources */,
9A87DAC61C358FA800A8CF3B /* DTError.m in Sources */,
9A20A0781C4EA53600FB45AB /* CLOnboardingWindowController.m in Sources */,
9A5B6C7C1D470ECB000EAAF1 /* CLTableViewDataSource.m in Sources */,
9AA4AC8D1CEC0FA60054ACB7 /* CLShortcutAnimatedView.m in Sources */,
9A87DACA1C358FA800A8CF3B /* DTTimePeriodGroup.m in Sources */,
9AA4AC8E1CEC0FA60054ACB7 /* CLFavouriteAnimatedView.m in Sources */,

BIN
Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate generated

Binary file not shown.

14
Clocker.xcodeproj/xcuserdata/abhishekbanthia.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@ -4,19 +4,13 @@
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Clocker/Preferences/CLPreferencesViewController.m"
timestampString = "491092836.331017"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "174"
endingLineNumber = "174"
landmarkName = "-acceptsFirstResponder"
landmarkType = "5">
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>

58
Clocker/ApplicationDelegate.m

@ -110,74 +110,80 @@ void *kContextActivePanel = &kContextActivePanel;
- (void)initializeDefaults
{
NSString *defaultTheme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *defaultTheme = [userDefaults objectForKey:CLThemeKey];
if (defaultTheme == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLThemeKey];
[userDefaults setObject:@0 forKey:CLThemeKey];
}
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
NSNumber *displayFutureSlider = [userDefaults objectForKey:CLDisplayFutureSliderKey];
if (displayFutureSlider == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLDisplayFutureSliderKey];
[userDefaults setObject:@0 forKey:CLDisplayFutureSliderKey];
}
NSNumber *defaultTimeFormat = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey];
NSNumber *defaultTimeFormat = [userDefaults objectForKey:CL24hourFormatSelectedKey];
if (defaultTimeFormat == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CL24hourFormatSelectedKey];
[userDefaults setObject:@1 forKey:CL24hourFormatSelectedKey];
}
NSNumber *relativeDate = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey];
NSNumber *relativeDate = [userDefaults objectForKey:CLRelativeDateKey];
if (relativeDate == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLRelativeDateKey];
[userDefaults setObject:@0 forKey:CLRelativeDateKey];
}
NSNumber *showDayInMenuBar = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowDayInMenu];
NSNumber *showDayInMenuBar = [userDefaults objectForKey:CLShowDayInMenu];
if (showDayInMenuBar == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowDayInMenu];
[userDefaults setObject:@0 forKey:CLShowDayInMenu];
}
NSNumber *showDateInMenu = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowDateInMenu];
NSNumber *showDateInMenu = [userDefaults objectForKey:CLShowDateInMenu];
if (showDateInMenu == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CLShowDateInMenu];
[userDefaults setObject:@1 forKey:CLShowDateInMenu];
}
NSNumber *showCityInMenu = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowPlaceInMenu];
NSNumber *showCityInMenu = [userDefaults objectForKey:CLShowPlaceInMenu];
if (showCityInMenu == nil)
{
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowPlaceInMenu];
[userDefaults setObject:@0 forKey:CLShowPlaceInMenu];
}
NSNumber *startClockerAtLogin = [[NSUserDefaults standardUserDefaults] objectForKey:CLStartAtLogin];
NSNumber *startClockerAtLogin = [userDefaults objectForKey:CLStartAtLogin];
if (startClockerAtLogin == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLStartAtLogin];
[userDefaults setObject:@0 forKey:CLStartAtLogin];
}
NSNumber *displayMode = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowAppInForeground];
NSNumber *displayMode = [userDefaults objectForKey:CLShowAppInForeground];
if (displayMode == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:CLShowAppInForeground];
[userDefaults setObject:@0 forKey:CLShowAppInForeground];
}
NSNumber *showSunriseSunsetTime = [[NSUserDefaults standardUserDefaults] objectForKey:CLSunriseSunsetTime];
NSNumber *showSunriseSunsetTime = [userDefaults objectForKey:CLSunriseSunsetTime];
if (showSunriseSunsetTime == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@1 forKey:CLSunriseSunsetTime];
[userDefaults setObject:@1 forKey:CLSunriseSunsetTime];
}
//If mode selected is 1, then show the window when the app starts
if (displayMode.integerValue == 1)
{
self.floatingWindow = [CLFloatingWindowController sharedFloatingWindow];
[self.floatingWindow showWindow:nil];
[self.floatingWindow updateTableContent];
[self.floatingWindow startWindowTimer];
[NSApp activateIgnoringOtherApps:YES];
[self showFloatingWindow];
}
}
- (void)showFloatingWindow
{
self.floatingWindow = [CLFloatingWindowController sharedFloatingWindow];
[self.floatingWindow showWindow:nil];
[self.floatingWindow updateTableContent];
[self.floatingWindow startWindowTimer];
[NSApp activateIgnoringOtherApps:YES];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{

18
Clocker/CLParentPanelController.m

@ -12,9 +12,10 @@
#import "CommonStrings.h"
#import "CLOneWindowController.h"
#import <pop/POP.h>
#import "CLTableViewDataSource.h"
@interface CLParentPanelController ()
@property (strong) CLTableViewDataSource *timezoneDataSource;
@end
@implementation CLParentPanelController
@ -41,13 +42,11 @@
}
self.mainTableview.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone;
}
- (void) updateDefaultPreferences
{
NSArray *defaultZones = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey];
self.defaultPreferences = self.defaultPreferences == nil ? [[NSMutableArray alloc] initWithArray:defaultZones] : [NSMutableArray arrayWithArray:defaultZones];
@ -62,6 +61,18 @@
self.futureSlider.hidden = [displayFutureSlider isEqualToNumber:@1] || (self.defaultPreferences.count == 0) ? YES : NO;
[self updatePanelColor];
if (!self.timezoneDataSource) {
self.timezoneDataSource = [[CLTableViewDataSource alloc] initWithItems:self.defaultPreferences];
self.mainTableview.dataSource = self.timezoneDataSource;
self.mainTableview.delegate = self.timezoneDataSource;
}
}
- (void)dealloc
{
self.timezoneDataSource = nil;
}
- (void)updatePanelColor
@ -91,7 +102,6 @@
dispatch_async(dispatch_get_main_queue(), ^{
self.shutdownButton.hidden = !value;
self.preferencesButton.hidden = !value;
});
}

6
Clocker/Custom Table Cell Views/CLTimezoneCellView.m

@ -72,7 +72,7 @@
CLTimezoneData *timeObject = [CLTimezoneData getCustomObject:object];
if ([timeObject.formattedAddress isEqualToString:customLabelValue]) {
timeObject.customLabel = CLEmptyString;
[timeObject setLabelForTimezone:CLEmptyString];
}
}];
}
@ -82,12 +82,12 @@
CLTimezoneData *timeObject = [CLTimezoneData getCustomObject:object];
if ([timeObject.formattedAddress isEqualToString:customLabelValue]) {
timeObject.customLabel = CLEmptyString;
[timeObject setLabelForTimezone:CLEmptyString];
}
}];
}
timezoneObject.customLabel = (customLabelValue.length > 0) ? customLabelValue : CLEmptyString;
[timezoneObject setLabelForTimezone:customLabelValue];
if ([timezoneObject.isFavourite isEqualToNumber:@1])
{

161
Clocker/Floating Window/CLFloatingWindowController.m

@ -7,8 +7,6 @@
//
#import "CLFloatingWindowController.h"
#import "CLRatingCellView.h"
#import "CLTimezoneData.h"
#import "CommonStrings.h"
#import "CLOneWindowController.h"
@ -20,6 +18,10 @@ static CLFloatingWindowController *sharedFloatingWindow = nil;
NSString *const CLRatingCellIdentifier = @"ratingCellView";
NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
@interface CLFloatingWindowController()
@end
@implementation CLFloatingWindowController
- (void)awakeFromNib
@ -66,8 +68,6 @@ NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
self.window.titlebarAppearsTransparent = YES;
self.window.titleVisibility = NSWindowTitleHidden;
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
@ -86,159 +86,6 @@ NSString *const CLTimezoneCellIdentifier = @"timeZoneCell";
return sharedFloatingWindow;
}
#pragma mark -
#pragma mark NSTableview Datasource
#pragma mark -
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if (self.showReviewCell) {
return self.defaultPreferences.count+1;
}
return self.defaultPreferences.count;
}
-(NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if (self.showReviewCell && row == self.defaultPreferences.count) {
CLRatingCellView *cellView = [self.mainTableview
makeViewWithIdentifier:CLRatingCellIdentifier
owner:self];
return cellView;
}
CLTimezoneCellView *cell = [tableView makeViewWithIdentifier:CLTimezoneCellIdentifier owner:self];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.defaultPreferences[row]];
cell.sunriseSetTime.stringValue = [dataObject getFormattedSunriseOrSunsetTimeAndSliderValue:self.futureSliderValue];
NSTextView *customLabel = (NSTextView*)[cell.relativeDate.window
fieldEditor:YES
forObject:cell.relativeDate];
NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if (theme.integerValue == 1)
{
(self.mainTableview).backgroundColor = [NSColor blackColor];
self.window.alphaValue = 0.90;
customLabel.insertionPointColor = [NSColor whiteColor];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"White Sunrise"] : [NSImage imageNamed:@"White Sunset"];
}
else
{
(self.mainTableview).backgroundColor = [NSColor whiteColor];
self.window.alphaValue = 1;
customLabel.insertionPointColor = [NSColor blackColor];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"Sunset"];
}
cell.relativeDate.stringValue = [dataObject getDateForTimeZoneWithFutureSliderValue:self.futureSliderValue andDisplayType:CLPanelDisplay];
cell.time.stringValue = [dataObject getTimeForTimeZoneWithFutureSliderValue:self.futureSliderValue];
cell.rowNumber = row;
cell.customName.stringValue = [dataObject formatStringShouldContainCity:YES];
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
self.futureSlider.hidden = [displayFutureSlider isEqualToNumber:@1] ? YES : NO;
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];
return cell;
}
#pragma mark -
#pragma mark NSTableview Drag and Drop
#pragma mark -
- (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.defaultPreferences[row];
if ([dataObject.formattedAddress isEqualToString:object])
{
return;
}
dataObject.customLabel = object;
(self.defaultPreferences)[row] = dataObject;
[[NSUserDefaults standardUserDefaults] setObject:self.defaultPreferences forKey:CLDefaultPreferenceKey];
[self.mainTableview reloadData];
}
}
-(BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
{
if (row == self.defaultPreferences.count)
{
row -= 1;
}
NSPasteboard *pBoard = [info draggingPasteboard];
NSData *data = [pBoard dataForType:CLDragSessionKey];
NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self.defaultPreferences exchangeObjectAtIndex:rowIndexes.firstIndex
withObjectAtIndex:row];
[[NSUserDefaults standardUserDefaults] setObject:self.defaultPreferences
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];
}
}];
[self.mainTableview reloadData];
return YES;
}
-(NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
{
return NSDragOperationEvery;
}
- (void) updateDefaultPreferences
{
[super updateDefaultPreferences];

4
Clocker/Floating Window/en.lproj/CLFloatingWindow.xib

@ -207,10 +207,6 @@
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="-2" id="sdp-E0-ew9"/>
<outlet property="delegate" destination="-2" id="xWJ-Wh-Aqu"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>

4
Clocker/Floating Window/ja.lproj/CLFloatingWindow.xib

@ -206,10 +206,6 @@
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="-2" id="sdp-E0-ew9"/>
<outlet property="delegate" destination="-2" id="xWJ-Wh-Aqu"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>

4
Clocker/Floating Window/zh-Hans.lproj/CLFloatingWindow.xib

@ -206,10 +206,6 @@
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="-2" id="sdp-E0-ew9"/>
<outlet property="delegate" destination="-2" id="xWJ-Wh-Aqu"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>

4
Clocker/Floating Window/zh-Hant.lproj/CLFloatingWindow.xib

@ -207,10 +207,6 @@
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>
<outlet property="dataSource" destination="-2" id="sdp-E0-ew9"/>
<outlet property="delegate" destination="-2" id="xWJ-Wh-Aqu"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>

6
Clocker/MenubarController.m

@ -4,6 +4,7 @@
#import "StatusItemView.h"
#import "CLTimezoneData.h"
#import "ApplicationDelegate.h"
#import "CLTimezoneDataOperations.h"
@implementation MenubarController
@ -25,7 +26,10 @@
if (dataObject)
{
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject];
NSString *menuTitle = [timezoneObject getMenuTitle];
CLTimezoneDataOperations *operationObject = [[CLTimezoneDataOperations alloc] initWithTimezoneData:timezoneObject];
NSString *menuTitle = [operationObject getMenuTitle];
textField = [self setUpTextfieldForMenubar];
textField.stringValue = (menuTitle.length > 0) ? menuTitle : @"Icon";

43
Clocker/Model/CLTimezoneData.h

@ -21,28 +21,31 @@ typedef NS_ENUM(NSUInteger, CLSelection) {
@interface CLTimezoneData : NSObject<NSCoding>
@property (copy, nonatomic) NSString *customLabel;
@property (copy, nonatomic) NSString *formattedAddress;
@property (copy, nonatomic) NSString *place_id;
@property (copy, nonatomic) NSString *timezoneID;
@property (copy, nonatomic) NSString *latitude;
@property (copy, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSDate *nextUpdate;
@property (strong, nonatomic) NSNumber *isFavourite;
@property (strong, nonatomic) NSDate *sunriseTime;
@property (strong, nonatomic) NSDate *sunsetTime;
@property (assign, nonatomic) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset
@property (assign, nonatomic) CLSelection selectionType;
@property (copy, nonatomic, readonly) NSString *customLabel;
@property (copy, nonatomic, readonly) NSString *formattedAddress;
@property (copy, nonatomic, readonly) NSString *place_id;
@property (copy, nonatomic, readonly) NSString *timezoneID;
@property (copy, nonatomic, readonly) NSString *latitude;
@property (copy, nonatomic, readonly) NSString *longitude;
@property (strong, nonatomic, readonly) NSDate *nextUpdate;
@property (strong, nonatomic, readonly) NSNumber *isFavourite;
@property (strong, nonatomic, readonly) NSDate *sunriseTime;
@property (strong, nonatomic, readonly) NSDate *sunsetTime;
@property (assign, nonatomic, readonly) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset
@property (assign, nonatomic,readonly) CLSelection selectionType;
+ (instancetype)getCustomObject:(NSData *)encodedData;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue;
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date;
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue andDisplayType:(CLDateDisplayType)type;
- (NSString *)formatStringShouldContainCity:(BOOL)value;
@property (NS_NONATOMIC_IOSONLY, getter=getMenuTitle, readonly, copy) NSString *menuTitle;
-(NSString *)getFormattedSunriseOrSunsetTimeAndSliderValue:(NSInteger)sliderValue;
- (void)save;
- (void)setLabelForTimezone:(NSString *)customLabel;
- (void)setIDForTimezone:(NSString *)uniqueID;
- (void)setFormattedAddressForTimezone:(NSString *)address;
- (void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue;
- (void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate;
- (void)setSunsetTimeForTimezone:(NSDate *)sunsetTime;
- (void)setSunriseTimeForTimezone:(NSDate *)sunriseTime;
- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset;
- (void)setLatitudeForTimezone:(NSString *)latitude;
- (void)setLongitudeForTimezone:(NSString *)longitude;
- (NSString *)getFormattedTimezoneLabel;
@end

376
Clocker/Model/CLTimezoneData.m

@ -13,7 +13,24 @@
#import "PanelController.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include "EDSunriseSet.h"
#import "CLTimezoneDataOperations.h"
@interface CLTimezoneData ()
@property (copy, nonatomic) NSString *customLabel;
@property (copy, nonatomic) NSString *formattedAddress;
@property (copy, nonatomic) NSString *place_id;
@property (copy, nonatomic) NSString *timezoneID;
@property (copy, nonatomic) NSString *latitude;
@property (copy, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSDate *nextUpdate;
@property (strong, nonatomic) NSNumber *isFavourite;
@property (strong, nonatomic) NSDate *sunriseTime;
@property (strong, nonatomic) NSDate *sunsetTime;
@property (assign, nonatomic) BOOL sunriseOrSunset; //YES for Sunrise, NO for Sunset
@property (assign, nonatomic) CLSelection selectionType;
@end
@implementation CLTimezoneData
@ -36,6 +53,19 @@
return self;
}
-(instancetype)init
{
self = [super init];
if (self)
{
self.selectionType = CLTimezoneSelection;
self.isFavourite = @(NSOffState);
}
return self;
}
+ (instancetype)getCustomObject:(NSData *)encodedData
{
@ -106,7 +136,7 @@
self.selectionType];
}
- (NSString *)formatStringShouldContainCity:(BOOL)value
- (NSString *)getFormattedTimezoneLabel
{
if (self.customLabel.length > 0)
{
@ -135,354 +165,54 @@
}
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
- (void)setLabelForTimezone:(NSString *)customLabel
{
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.timezoneID];
//In the format 22:10
return [dateFormatter stringFromDate:newDate];
self.customLabel = customLabel.length > 0 ? customLabel : CLEmptyString;
}
- (void)retrieveLatitudeAndLongitudeWithSearchString:(NSString *)formattedString
- (void)setIDForTimezone:(NSString *)uniqueID
{
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.place_id])
{
//We have a match
NSDictionary *latLang = dictionary[@"geometry"][@"location"];
self.latitude = [NSString stringWithFormat:@"%@", latLang[@"lat"]];
self.longitude = [NSString stringWithFormat:@"%@", latLang[@"lng"]];
}
}];
});
}];
self.timezoneID = uniqueID;
}
- (NSString *)getLocalCurrentDate
-(void)setFormattedAddressForTimezone:(NSString *)address
{
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterNoStyle;
dateFormatter.timeZone = [NSTimeZone systemTimeZone];
return [NSDateFormatter localizedStringFromDate:[NSDate date]
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterNoStyle];
self.formattedAddress = address;
}
- (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.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];
CLTimezoneData *newDataObject = [CLTimezoneData new];
newDataObject.timezoneID = self.timezoneID;
newDataObject.formattedAddress = self.formattedAddress;
newDataObject.latitude = self.latitude;
newDataObject.longitude = self.longitude;
newDataObject.customLabel = self.customLabel;
newDataObject.place_id = self.place_id;
newDataObject.nextUpdate = tomorrowMidnight;
newDataObject.isFavourite = @(NSOffState);
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];
}
-(void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue
{
self.isFavourite = favouriteValue;
}
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
andDisplayType:(CLDateDisplayType)type
-(void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate
{
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.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];
}
self.nextUpdate = nextUpdate;
}
- (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger
-(void)setSunsetTimeForTimezone:(NSDate *)sunsetTime
{
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;
}
self.sunsetTime = sunsetTime;
}
- (NSString *)getMenuTitle
-(void)setSunriseTimeForTimezone:(NSDate *)sunriseTime
{
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.customLabel.length > 0 ?
[menuTitle appendString:self.customLabel] :
[menuTitle appendString:self.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.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;
self.sunriseTime = sunriseTime;
}
-(void)initializeSunriseSunsetWithSliderValue:(NSInteger)sliderValue
- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset
{
if (!self.latitude || !self.longitude)
{
//Retrieve the values using Google Places API
if (self.selectionType == CLTimezoneSelection)
{
/* A timezone has been selected*/
NSLog(@"%@", self);
return;
}
[self retrieveLatitudeAndLongitudeWithSearchString:self.formattedAddress];
}
EDSunriseSet *sunriseSetObject = [EDSunriseSet sunrisesetWithDate:[[NSCalendar autoupdatingCurrentCalendar]
dateByAddingUnit:NSCalendarUnitMinute
value:sliderValue
toDate:[NSDate date]
options:kNilOptions]
timezone:[NSTimeZone timeZoneWithName:self.timezoneID]
latitude:self.latitude.doubleValue
longitude:self.longitude.doubleValue];
self.sunriseTime = sunriseSetObject.sunrise;
self.sunsetTime = sunriseSetObject.sunset;
self.sunriseOrSunset = sunriseOrSunset;
}
-(NSString *)getFormattedSunriseOrSunsetTimeAndSliderValue:(NSInteger)sliderValue
- (void)setLatitudeForTimezone:(NSString *)latitude
{
/* We have to call this everytime so that we get an updated value everytime! */
[self initializeSunriseSunsetWithSliderValue:sliderValue];
if (!self.sunriseTime && !self.sunsetTime)
{
return CLEmptyString;
}
self.sunriseOrSunset = [self.sunriseTime isLaterThanOrEqualTo:[NSDate date]];
NSDate *newDate = self.sunriseOrSunset ? self.sunriseTime : self.sunsetTime;
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = kCFDateFormatterNoStyle;
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.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];
self.latitude = latitude;
}
- (void)save
- (void)setLongitudeForTimezone:(NSString *)longitude
{
NSArray *defaultPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLDefaultPreferenceKey];
if (defaultPreference == nil)
{
defaultPreference = [NSMutableArray new];
}
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:self];
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:defaultPreference];
[newArray addObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
self.longitude = longitude;
}
@end

24
Clocker/Model/CLTimezoneDataOperations.h

@ -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

393
Clocker/Model/CLTimezoneDataOperations.m

@ -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

20
Clocker/Onboarding/CLIntroViewController.m

@ -24,7 +24,7 @@
@property (strong) CLShortcutAnimatedView *shortCutView;
@property (strong) CLFavouriteAnimatedView *favouriteView;
@property (strong) NSString *informativeText;
@property (strong) NSArray *headerLabelString;
@property (strong) NSArray<NSString *> *headerLabelString;
@property (weak) IBOutlet NSButton *nextActionButton;
@end
@ -35,20 +35,24 @@
{
[super viewDidLoad];
self.headerLabelString = @[@"Now, Clocker stays on top of all the windows", @"Access Clocker through keyboard shortcuts", @"Customize your menubar with Favourites"];
[self.headerView setWantsLayer:YES];
self.view.window.styleMask = NSFullSizeContentViewWindowMask;
[self setUpDefaults];
[self initializeViews];
self.nextActionButton.hidden = YES;
[self addAnimationInOrderWithTag:CLFloatingViewFeature];
}
- (void)setUpDefaults
{
self.headerLabelString = @[@"Now, Clocker stays on top of all the windows", @"Access Clocker through keyboard shortcuts", @"Customize your menubar with Favourites"];
[self.headerView setWantsLayer:YES];
self.view.window.styleMask = NSFullSizeContentViewWindowMask;
self.nextActionButton.hidden = YES;
}
- (void)initializeViews
{
self.floatingView = [[FloatingView alloc] initWithFrame:self.customView.frame];

137
Clocker/PanelController.m

@ -31,11 +31,8 @@
#import "StatusItemView.h"
#import "MenubarController.h"
#import <Crashlytics/Crashlytics.h>
#import "CLRatingCellView.h"
#import "CommonStrings.h"
#import "CLTimezoneCellView.h"
#import "DateTools.h"
#import "CLTimezoneData.h"
#import "Panel.h"
#define OPEN_DURATION .15
@ -57,8 +54,6 @@
#import "Reachability.h"
NSString *const CLPanelNibIdentifier = @"Panel";
NSString *const CLRatingCellViewIdentifier = @"ratingCellView";
NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
static PanelController *sharedPanel = nil;
@ -258,138 +253,6 @@ static PanelController *sharedPanel = nil;
});
}
#pragma mark -
#pragma mark NSTableview Datasource
#pragma mark -
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if (self.showReviewCell) {
return self.defaultPreferences.count+1;
}
return self.defaultPreferences.count;
}
-(NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if (self.showReviewCell && row == self.defaultPreferences.count) {
CLRatingCellView *cellView = [self.mainTableview
makeViewWithIdentifier:CLRatingCellViewIdentifier
owner:self];
return cellView;
}
CLTimezoneCellView *cell = [tableView makeViewWithIdentifier:CLTimezoneCellViewIdentifier owner:self];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.defaultPreferences[row]];
cell.sunriseSetTime.stringValue = [dataObject getFormattedSunriseOrSunsetTimeAndSliderValue:self.futureSliderValue];
NSTextView *customLabel = (NSTextView*)[cell.relativeDate.window
fieldEditor:YES
forObject:cell.relativeDate];
NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if (theme.integerValue == 1)
{
(self.mainTableview).backgroundColor = [NSColor blackColor];
self.window.alphaValue = 0.90;
customLabel.insertionPointColor = [NSColor whiteColor];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"White Sunrise"] : [NSImage imageNamed:@"White Sunset"];
}
else
{
(self.mainTableview).backgroundColor = [NSColor whiteColor];
self.window.alphaValue = 1;
customLabel.insertionPointColor = [NSColor blackColor];
cell.sunriseSetImage.image = dataObject.sunriseOrSunset ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"Sunset"];
}
cell.relativeDate.stringValue = [dataObject
getDateForTimeZoneWithFutureSliderValue:self.futureSliderValue andDisplayType:CLPanelDisplay];
cell.time.stringValue = [dataObject getTimeForTimeZoneWithFutureSliderValue:self.futureSliderValue];
cell.rowNumber = row;
cell.customName.stringValue = [dataObject formatStringShouldContainCity:YES];
NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey];
self.futureSlider.hidden = [displayFutureSlider isEqualToNumber:@1] ? YES : NO;
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];
return cell;
}
#pragma mark -
#pragma mark NSTableview Drag and Drop
#pragma mark -
-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if ([object isKindOfClass:[NSString class]])
{
CLTimezoneData *dataObject = self.defaultPreferences[row];
if ([dataObject.formattedAddress isEqualToString:object])
{
return;
}
dataObject.customLabel = object;
(self.defaultPreferences)[row] = dataObject;
[[NSUserDefaults standardUserDefaults] setObject:self.defaultPreferences forKey:CLDefaultPreferenceKey];
[self.mainTableview reloadData];
}
}
-(BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation
{
if (row == self.defaultPreferences.count) {
row--;
}
NSPasteboard *pBoard = [info draggingPasteboard];
NSData *data = [pBoard dataForType:CLDragSessionKey];
NSIndexSet *rowIndexes = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self.defaultPreferences exchangeObjectAtIndex:rowIndexes.firstIndex withObjectAtIndex:row];
[[NSUserDefaults standardUserDefaults] setObject:self.defaultPreferences forKey:CLDefaultPreferenceKey];
[self.mainTableview reloadData];
return YES;
}
-(NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
{
return NSDragOperationEvery;
}
#pragma mark -
#pragma mark Preferences Target-Action
#pragma mark -

92
Clocker/Preferences/CLPreferencesViewController.m

@ -16,7 +16,7 @@
#import "CLAPIConnector.h"
#import "EDSunriseSet.h"
#import "NSString+CLStringAdditions.h"
#import "CLTimezoneDataOperations.h"
NSString *const CLSearchPredicateKey = @"SELF CONTAINS[cd]%@";
NSString *const CLPreferencesTimezoneNameIdentifier = @"formattedAddress";
@ -177,16 +177,18 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
NSInteger numberOfRows = 0;
if (tableView == self.timezoneTableView)
{
return self.selectedTimeZones.count;
numberOfRows = self.selectedTimeZones.count;
}
else
{
return [self numberOfSearchResults];
numberOfRows = [self numberOfSearchResults];
}
return 0;
return numberOfRows;
}
- (NSInteger)numberOfSearchResults
@ -290,44 +292,33 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[NSCharacterSet whitespaceCharacterSet]];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.selectedTimeZones[row]];
dataObject.customLabel = formattedValue.length > 0 ? formattedValue : CLEmptyString;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:dataObject];
(self.selectedTimeZones)[row] = encodedObject;
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTimeZones forKey:CLDefaultPreferenceKey];
[dataObject setLabelForTimezone:formattedValue];
[self insertTimezoneInDefaultPreferences:dataObject atIndex:row];
if ([dataObject.isFavourite isEqualToNumber:@1])
{
[[NSUserDefaults standardUserDefaults] setObject:encodedObject
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dataObject]
forKey:@"favouriteTimezone"];
}
[self refreshMainTableview];
}
else
{
NSMutableArray *newArray = [NSMutableArray new];
[self resetAllFavouriteValues];
NSNumber *isFavouriteValue = (NSNumber *)object;
[self.selectedTimeZones enumerateObjectsUsingBlock:^(NSData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
{
CLTimezoneData *timezone = [CLTimezoneData getCustomObject:obj];
timezone.isFavourite = @0;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezone];
[newArray addObject:encodedObject];
}];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:newArray[row]];
dataObject.isFavourite = isFavouriteValue;
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:dataObject];
newArray[row] = encodedObject;
[[NSUserDefaults standardUserDefaults] setObject:newArray forKey:CLDefaultPreferenceKey];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.selectedTimeZones[row]];
[dataObject setFavouriteValueForTimezone:isFavouriteValue];
[self insertTimezoneInDefaultPreferences:dataObject atIndex:row];
ApplicationDelegate *appDelegate = (ApplicationDelegate*)[NSApplication sharedApplication].delegate;
if (dataObject.isFavourite.integerValue == 1)
{
[[NSUserDefaults standardUserDefaults] setObject:encodedObject
[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dataObject]
forKey:@"favouriteTimezone"];
[appDelegate.menubarController setUpTimerForUpdatingMenubar];
@ -341,8 +332,32 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[self refereshTimezoneTableView];
[self refreshMainTableview];
}
[self refreshMainTableview];
}
- (void)resetAllFavouriteValues
{
NSMutableArray *newArray = [NSMutableArray new];
[self.selectedTimeZones enumerateObjectsUsingBlock:^(NSData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
{
CLTimezoneData *timezone = [CLTimezoneData getCustomObject:obj];
[timezone setFavouriteValueForTimezone:@0];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezone];
[newArray addObject:encodedObject];
}];
self.selectedTimeZones = [NSMutableArray arrayWithArray:newArray];
}
- (void)insertTimezoneInDefaultPreferences:(CLTimezoneData *)timezoneObject atIndex:(NSInteger)index
{
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:timezoneObject];
self.selectedTimeZones[index] = encodedObject;
[[NSUserDefaults standardUserDefaults] setObject:self.selectedTimeZones forKey:CLDefaultPreferenceKey];
}
- (IBAction)addTimeZone:(id)sender
@ -392,7 +407,6 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[self.selectedTimeZones enumerateObjectsUsingBlock:^(NSData * _Nonnull encodedData, NSUInteger idx, BOOL * _Nonnull stop) {
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:encodedData];
timezoneObject.selectionType = CLCitySelection;
NSString *name = timezoneObject.place_id;
NSString *selectedPlaceID = dataObject.place_id;
@ -421,22 +435,23 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
else
{
CLTimezoneData *data = [CLTimezoneData new];
data.selectionType = CLTimezoneSelection;
data.isFavourite = @(NSOffState);
data.customLabel = CLEmptyString;
[data setLabelForTimezone:CLEmptyString];
if (self.searchField.stringValue.length > 0)
{
data.timezoneID = self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow];
data.formattedAddress = self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow];
[data setIDForTimezone:self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow]];
[data setFormattedAddressForTimezone:self.timeZoneFilteredArray[self.availableTimezoneTableView.selectedRow]];
}
else
{
data.timezoneID = self.timeZoneArray[self.availableTimezoneTableView.selectedRow];
data.formattedAddress = self.timeZoneArray[self.availableTimezoneTableView.selectedRow];
[data setIDForTimezone:self.timeZoneArray[self.availableTimezoneTableView.selectedRow]];
[data setFormattedAddressForTimezone:self.timeZoneArray[self.availableTimezoneTableView.selectedRow]];
}
[data save];
CLTimezoneDataOperations *operationObject = [[CLTimezoneDataOperations alloc] initWithTimezoneData:data];
[operationObject save];
self.timeZoneFilteredArray = [NSMutableArray array];
@ -681,6 +696,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
self.placeholderLabel.placeholderString = [NSString stringWithFormat:@"Searching for '%@'", searchString];
NSArray* words = [searchString componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceAndNewlineCharacterSet]];
searchString = [words componentsJoinedByString:CLEmptyString];
NSString *urlString = [NSString stringWithFormat:CLLocationSearchURL, searchString, userPreferredLanguage];
@ -793,7 +809,9 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
CLTimezoneData *timezoneObject = [[CLTimezoneData alloc] initWithDictionary:newTimezone];
[timezoneObject save];
CLTimezoneDataOperations *operationObject = [[CLTimezoneDataOperations alloc] initWithTimezoneData:timezoneObject];
[operationObject save];
}

6
Clocker/StatusItemView.m

@ -30,6 +30,7 @@
#import "CommonStrings.h"
#import "CLTimezoneData.h"
#import "DateTools.h"
#import "CLTimezoneDataOperations.h"
@implementation StatusItemView
@ -73,7 +74,10 @@
if (dataObject)
{
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:dataObject];
textField.stringValue = [timezoneObject getMenuTitle];
CLTimezoneDataOperations *operationObject = [[CLTimezoneDataOperations alloc] initWithTimezoneData:timezoneObject];
textField.stringValue = [operationObject getMenuTitle];
// Set up dark mode for icon
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] isEqualToString:@"Dark"])

15
Clocker/Utilities/CLTableViewDataSource.h

@ -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

190
Clocker/Utilities/CLTableViewDataSource.m

@ -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…
Cancel
Save