Browse Source

Datasource formatting to be handled by Model class.

v1.2.2
Abhishek Banthia 9 years ago
parent
commit
8ff711dc3e
  1. BIN
      Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate
  2. 3
      Clocker.xcodeproj/xcuserdata/abhishekbanthia.xcuserdatad/xcschemes/Clocker.xcscheme
  3. 4
      Clocker/API/CLAPI.m
  4. 7
      Clocker/App Feedback/CLAppFeedbackWindow.xib
  5. 10
      Clocker/ApplicationDelegate.m
  6. 4
      Clocker/Clocker-Info.plist
  7. 11
      Clocker/Model/CLTimezoneData.h
  8. 90
      Clocker/Model/CLTimezoneData.m
  9. 2
      Clocker/PanelController.h
  10. 211
      Clocker/PanelController.m
  11. 22
      Clocker/Preferences/CLPreferencesView.xib
  12. 37
      Clocker/Preferences/CLPreferencesViewController.m

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

Binary file not shown.

3
Clocker.xcodeproj/xcuserdata/abhishekbanthia.xcuserdatad/xcschemes/Clocker.xcscheme

@ -51,8 +51,7 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
showNonLocalizedStrings = "YES"
language = "en">
showNonLocalizedStrings = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference

4
Clocker/API/CLAPI.m

@ -18,16 +18,12 @@
__block NSDictionary *responseDictionary = [NSDictionary dictionary];
NSView *currentView = [sender view];
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.timeoutIntervalForRequest = 20;
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig];
NSError *error;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", path]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

7
Clocker/App Feedback/CLAppFeedbackWindow.xib

@ -85,7 +85,6 @@
<rect key="frame" x="8" y="-3" width="273" height="45"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="dRi-pM-pWX"/>
<constraint firstAttribute="width" constant="269" id="xTs-u1-oid"/>
</constraints>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="center" title="Your contact information will let us contact you in case we need more information or can help!" placeholderString="" id="yEq-6I-HBq">
<font key="font" size="12" name="SFUIDisplay-Light"/>
@ -99,6 +98,7 @@
<constraint firstItem="Qzm-kE-Igl" firstAttribute="top" secondItem="moX-Vc-vMc" secondAttribute="top" constant="11" id="Dpz-4F-hN7"/>
<constraint firstItem="Qzm-kE-Igl" firstAttribute="leading" secondItem="moX-Vc-vMc" secondAttribute="leading" constant="10" id="GKZ-24-t7t"/>
<constraint firstItem="LVY-Qw-MYC" firstAttribute="top" secondItem="zlM-Cf-OxV" secondAttribute="bottom" constant="3" id="Xck-iy-cZk"/>
<constraint firstItem="LVY-Qw-MYC" firstAttribute="leading" secondItem="moX-Vc-vMc" secondAttribute="leading" constant="10" id="iLs-Ob-MZC"/>
<constraint firstItem="LVY-Qw-MYC" firstAttribute="centerX" secondItem="moX-Vc-vMc" secondAttribute="centerX" id="k3n-00-eiV"/>
<constraint firstItem="zlM-Cf-OxV" firstAttribute="leading" secondItem="moX-Vc-vMc" secondAttribute="leading" constant="10" id="u3y-gI-YeL"/>
</constraints>
@ -145,9 +145,8 @@ DQ
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="gej-YH-9dt">
<rect key="frame" x="10" y="351" width="139" height="17"/>
<rect key="frame" x="10" y="351" width="299" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="135" id="1Ix-I9-ymS"/>
<constraint firstAttribute="height" constant="17" id="a7O-DC-irX"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Tell us what you think!" id="oHe-hu-bQn">
@ -183,6 +182,7 @@ DQ
<constraint firstAttribute="trailing" secondItem="Qzm-kE-Igl" secondAttribute="trailing" constant="30" id="5UG-sC-szG"/>
<constraint firstItem="W3a-Hi-ryk" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="12" id="8UN-bn-s8Y"/>
<constraint firstAttribute="trailing" secondItem="zlM-Cf-OxV" secondAttribute="trailing" constant="30" id="Arj-b2-oje"/>
<constraint firstAttribute="trailing" secondItem="LVY-Qw-MYC" secondAttribute="trailing" constant="30" id="I39-jS-bL7"/>
<constraint firstAttribute="trailing" secondItem="oNX-kV-RGt" secondAttribute="trailing" constant="12" id="IqR-EG-ga3"/>
<constraint firstItem="sJq-1o-Bft" firstAttribute="leading" secondItem="szs-8j-SMN" secondAttribute="trailing" constant="8" id="JSB-K6-cbX"/>
<constraint firstAttribute="trailing" secondItem="sJq-1o-Bft" secondAttribute="trailing" constant="20" id="KuW-ez-Od9"/>
@ -196,6 +196,7 @@ DQ
<constraint firstItem="h17-og-9PU" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="12" id="iIH-oN-lBO"/>
<constraint firstAttribute="trailing" secondItem="W3a-Hi-ryk" secondAttribute="trailing" constant="22" id="j6H-0M-Cux"/>
<constraint firstAttribute="trailing" secondItem="JzF-Oq-qhW" secondAttribute="trailing" constant="22" id="leu-ZX-18k"/>
<constraint firstAttribute="trailing" secondItem="gej-YH-9dt" secondAttribute="trailing" constant="12" id="qjH-ND-NKx"/>
<constraint firstItem="gej-YH-9dt" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="12" id="tlA-wq-Gts"/>
<constraint firstItem="JzF-Oq-qhW" firstAttribute="top" secondItem="oNX-kV-RGt" secondAttribute="bottom" constant="13" id="w7P-k5-O59"/>
<constraint firstAttribute="bottom" secondItem="szs-8j-SMN" secondAttribute="bottom" constant="20" id="xos-N8-d1k"/>

10
Clocker/ApplicationDelegate.m

@ -65,12 +65,12 @@ void *kContextActivePanel = &kContextActivePanel;
+ (void)initialize
{
//Configure iRate
[iRate sharedInstance].appStoreID = 1056643111;
[iVersion sharedInstance].appStoreID = 1056643111;
[iRate sharedInstance].appStoreID = (NSInteger)nil;
[iVersion sharedInstance].appStoreID = (NSInteger)nil;
[iRate sharedInstance].useAllAvailableLanguages = NO;
[iVersion sharedInstance].useAllAvailableLanguages = NO;
[[iRate sharedInstance] setVerboseLogging:YES];
[[iVersion sharedInstance] setVerboseLogging:NO];
[[iVersion sharedInstance] setVerboseLogging:YES];
}
#pragma mark - NSApplicationDelegate
@ -78,10 +78,6 @@ void *kContextActivePanel = &kContextActivePanel;
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[[NSUserDefaults standardUserDefaults] setObject:[NSMutableArray array]
forKey:CLDefaultPreferenceKey];
NSString *defaultTheme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if (defaultTheme == nil) {
[[NSUserDefaults standardUserDefaults] setObject:@"Default" forKey:CLThemeKey];

4
Clocker/Clocker-Info.plist

@ -13,11 +13,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>1.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>18</string>
<string>19</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>

11
Clocker/Model/CLTimezoneData.h

@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import "CLTimezoneCellView.h"
@interface CLTimezoneData : NSObject<NSCoding>
@ -20,7 +21,15 @@
@property (strong, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSDate *nextUpdate;
-(instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (instancetype)initWithDictionary:(NSDictionary *)dictionary;
- (BOOL)saveObjectToPreferences:(CLTimezoneData *)object;
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue;
- (NSString *)getLocalCurrentDate;
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date;
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue;
- (void)getTimeZoneForLatitude:(NSString *)latitude andLongitude:(NSString *)longitude andDataObject:(CLTimezoneData *)dataObject;
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell;
- (NSString *)formatStringShouldContainCity:(BOOL)value;
+ (instancetype)getCustomObject:(NSData *)encodedData;
@end

90
Clocker/Model/CLTimezoneData.m

@ -10,7 +10,6 @@
#import "CommonStrings.h"
#import "DateTools.h"
#import "CLAPI.h"
#import "CLTimezoneCellView.h"
#import "PanelController.h"
@implementation CLTimezoneData
@ -22,7 +21,7 @@
self.customLabel = dictionary[CLCustomLabel];
self.sunriseTime = CLEmptyString;
self.sunsetTime = CLEmptyString;
self.timezoneID = dictionary[CLTimezoneName];
self.timezoneID = dictionary[CLTimezoneID];
self.latitude = dictionary[@"latitude"];
self.longitude = dictionary[@"longitude"];
self.place_id = dictionary[CLPlaceIdentifier];
@ -39,19 +38,15 @@
NSMutableArray *array = [NSMutableArray new];
[array addObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"checking"];
[self getCustomObject];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:CLDefaultPreferenceKey];
return YES;
}
- (void)getCustomObject
+ (instancetype)getCustomObject:(NSData *)encodedData
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *encodedObject = [defaults objectForKey:@"checking"];
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject[0]];
NSLog(@"Object:%@", object.place_id);
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData];
return object;
}
@ -95,23 +90,20 @@
self.place_id];
}
- (NSString *)formatStringShouldContainCity:(BOOL)value withTimezoneName:(NSMutableDictionary *)timeZoneDictionary
- (NSString *)formatStringShouldContainCity:(BOOL)value
{
if (timeZoneDictionary[CLCustomLabel]) {
NSString *customLabel = timeZoneDictionary[CLCustomLabel];
if (customLabel.length > 0)
{
return customLabel;
}
if (self.customLabel.length > 0)
{
return self.customLabel;
}
if ([timeZoneDictionary[CLTimezoneName] length] > 0)
if ([self.formattedAddress length] > 0)
{
return timeZoneDictionary[CLTimezoneName];
return self.formattedAddress;
}
else if (timeZoneDictionary[CLTimezoneID])
else if (self.timezoneID)
{
NSString *timezoneID = timeZoneDictionary[CLTimezoneID];
NSString *timezoneID = self.timezoneID;
NSRange range = [timezoneID rangeOfString:@"/"];
if (range.location != NSNotFound)
@ -127,22 +119,21 @@
}
- (NSString *)getFormattedSunriseOrSunsetTime:(NSMutableDictionary *)originalTime
andSunImage:(CLTimezoneCellView *)cell
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *sunTime = [formatter dateFromString:originalTime[@"sunriseTime"]];
NSDate *sunTime = [formatter dateFromString:self.sunriseTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:originalTime[CLTimezoneID]];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterShortStyle;
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDate = [dateFormatter stringFromDate:[NSDate date]];
NSDateFormatter *dateConversion = [[NSDateFormatter alloc] init];
dateConversion.timeZone = [NSTimeZone timeZoneWithName:originalTime[CLTimezoneID]];
dateConversion.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateConversion.dateStyle = kCFDateFormatterShortStyle;
dateConversion.timeStyle = kCFDateFormatterShortStyle;
dateConversion.dateFormat = @"yyyy-MM-dd HH:mm";
@ -153,17 +144,17 @@
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"White Sunrise"];
return [originalTime[@"sunriseTime"] substringFromIndex:11];
return [self.sunriseTime substringFromIndex:11];
}
else
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"];
return [originalTime[@"sunsetTime"] substringFromIndex:11];
return [self.sunsetTime substringFromIndex:11];
}
}
- (NSString *)getTimeForTimeZone:(NSString *)timezoneID withFutureSliderValue:(NSInteger)futureSliderValue
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
{
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitHour
@ -177,7 +168,7 @@
is24HourFormatSelected.boolValue ? [dateFormatter setDateFormat:@"HH:mm"] : [dateFormatter setDateFormat:@"hh:mm a"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:timezoneID];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
//In the format 22:10
return [dateFormatter stringFromDate:newDate];
@ -196,7 +187,7 @@
}
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date andDataObject:(CLTimezoneData *)dataObject
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy"
@ -214,7 +205,7 @@
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate];
if ([dataObject.nextUpdate isKindOfClass:[NSString class]])
if ([self.nextUpdate isKindOfClass:[NSString class]])
{
NSUInteger units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
@ -223,14 +214,14 @@
NSDate *tomorrowMidnight = [[NSCalendar currentCalendar] dateFromComponents:comps];
CLTimezoneData *newDataObject = [[CLTimezoneData alloc] init];
newDataObject.timezoneID = dataObject.timezoneID;
newDataObject.formattedAddress = dataObject.formattedAddress;
newDataObject.latitude = dataObject.latitude;
newDataObject.longitude = dataObject.longitude;
newDataObject.sunriseTime = dataObject.sunriseTime;
newDataObject.sunsetTime = dataObject.sunsetTime;
newDataObject.customLabel = dataObject.customLabel;
newDataObject.place_id = dataObject.place_id;
newDataObject.timezoneID = self.timezoneID;
newDataObject.formattedAddress = self.formattedAddress;
newDataObject.latitude = self.latitude;
newDataObject.longitude = self.longitude;
newDataObject.sunriseTime = self.sunriseTime;
newDataObject.sunsetTime = self.sunsetTime;
newDataObject.customLabel = self.customLabel;
newDataObject.place_id = self.place_id;
newDataObject.nextUpdate = tomorrowMidnight;
@ -247,15 +238,15 @@
[panelController.defaultPreferences replaceObjectAtIndex:[panelController.defaultPreferences indexOfObject:dataObject] withObject:newDataObject];
[panelController.defaultPreferences replaceObjectAtIndex:[panelController.defaultPreferences indexOfObject:self] withObject:newDataObject];
[[NSUserDefaults standardUserDefaults] setObject:panelController.defaultPreferences forKey:CLDefaultPreferenceKey];
}
else if ([dataObject.nextUpdate isKindOfClass:[NSDate class]] &&
[dataObject.nextUpdate isEarlierThanOrEqualTo:timezoneDate])
else if ([self.nextUpdate isKindOfClass:[NSDate class]] &&
[self.nextUpdate isEarlierThanOrEqualTo:timezoneDate])
{
[self getTimeZoneForLatitude:dataObject.latitude
andLongitude:dataObject.longitude
andDataObject:dataObject];
[self getTimeZoneForLatitude:self.latitude
andLongitude:self.longitude
andDataObject:self];
}
NSInteger daysApart = [timezoneDate daysFrom:localDate];
@ -277,7 +268,7 @@
}
}
- (NSString *)getDateForTimeZone:(CLTimezoneData *)dataObject withFutureSliderValue:(NSInteger)futureSliderValue
- (NSString *)getDateForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
{
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitHour
@ -288,13 +279,12 @@
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterNoStyle;
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:dataObject.timezoneID];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
NSNumber *relativeDayPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey];
if (relativeDayPreference.integerValue == 0) {
return [self compareSystemDate:[self getLocalCurrentDate]
toTimezoneDate:[dateFormatter stringFromDate:newDate]
andDataObject:dataObject];
toTimezoneDate:[dateFormatter stringFromDate:newDate]];
}
else
{

2
Clocker/PanelController.h

@ -54,7 +54,7 @@
@property (nonatomic, strong) CLOneWindowController *oneWindow;
@property (nonatomic, strong) NSMutableArray<CLTimezoneData*> *defaultPreferences;
@property (nonatomic, strong) NSMutableArray *defaultPreferences;
@property (nonatomic, strong) NSDateFormatter *dateFormatter;
@property (nonatomic, assign) NSInteger futureSliderValue;
@property (nonatomic) BOOL hasActivePanel;

211
Clocker/PanelController.m

@ -303,7 +303,7 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
CLTimezoneCellView *cell = [tableView makeViewWithIdentifier:CLTimezoneCellViewIdentifier owner:self];
CLTimezoneData *dataObject = self.defaultPreferences[row];
CLTimezoneData *dataObject = [CLTimezoneData getCustomObject:self.defaultPreferences[row]];
NSTextView *customLabel = (NSTextView*)[cell.relativeDate.window fieldEditor:YES
forObject:cell.relativeDate];
@ -328,18 +328,17 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
customLabel.insertionPointColor = [NSColor blackColor];
}
cell.relativeDate.stringValue = [self getDateForTimeZone:self.defaultPreferences[row]];
cell.relativeDate.stringValue = [dataObject getDateForTimeZoneWithFutureSliderValue:self.futureSliderValue];
cell.time.stringValue = [self getTimeForTimeZone:dataObject.timezoneID];
cell.time.stringValue = [dataObject getTimeForTimeZoneWithFutureSliderValue:self.futureSliderValue];
cell.rowNumber = row;
cell.customName.stringValue = [self formatStringShouldContainCity:YES
withTimezoneName:dataObject];
cell.customName.stringValue = [dataObject formatStringShouldContainCity:YES];
NSNumber *displaySuntimings = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplaySunTimingKey];
if ([displaySuntimings isEqualToNumber:[NSNumber numberWithInteger:0]] && dataObject.sunriseTime && dataObject.sunsetTime) {
cell.sunTime.stringValue = [self getFormattedSunriseOrSunsetTime:dataObject andSunImage:cell];
cell.sunTime.stringValue = [dataObject getFormattedSunriseOrSunsetTimeAndSunImage:cell];
}
else
{
@ -364,205 +363,6 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
return cell;
}
#pragma mark -
#pragma mark Datasource formatting
#pragma mark -
- (NSString *)formatStringShouldContainCity:(BOOL)value withTimezoneName:(CLTimezoneData *)dataObject
{
if (dataObject.customLabel) {
NSString *customLabel = dataObject.customLabel;
if (customLabel.length > 0)
{
return customLabel;
}
}
if ([dataObject.formattedAddress length] > 0)
{
return dataObject.formattedAddress;
}
else if (dataObject.timezoneID.length > 0)
{
NSString *timezoneID = dataObject.timezoneID;
NSRange range = [timezoneID rangeOfString:@"/"];
if (range.location != NSNotFound)
{
timezoneID = [timezoneID substringWithRange:NSMakeRange(range.location+1, timezoneID.length-1 - range.location)];
}
return timezoneID;
}
else
{
return @"Error";
}
}
- (NSString *)getFormattedSunriseOrSunsetTime:(CLTimezoneData *)dataObject
andSunImage:(CLTimezoneCellView *)cell
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *sunTime = [formatter dateFromString:dataObject.sunriseTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:dataObject.timezoneID];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterShortStyle;
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDate = [dateFormatter stringFromDate:[NSDate date]];
NSDateFormatter *dateConversion = [[NSDateFormatter alloc] init];
dateConversion.timeZone = [NSTimeZone timeZoneWithName:dataObject.timezoneID];
dateConversion.dateStyle = kCFDateFormatterShortStyle;
dateConversion.timeStyle = kCFDateFormatterShortStyle;
dateConversion.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if ([sunTime laterDate:[dateConversion dateFromString:newDate]] == sunTime)
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"White Sunrise"];
return [dataObject.sunriseTime substringFromIndex:11];
}
else
{
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"];
return [dataObject.sunsetTime substringFromIndex:11];
}
}
- (NSString *)getTimeForTimeZone:(NSString *)timezoneID
{
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitHour
value:self.futureSliderValue
toDate:[NSDate date]
options:kNilOptions];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = kCFDateFormatterNoStyle;
NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey];
is24HourFormatSelected.boolValue ? [dateFormatter setDateFormat:@"HH:mm"] : [dateFormatter setDateFormat:@"hh:mm a"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:timezoneID];
//In the format 22:10
return [dateFormatter stringFromDate:newDate];
}
- (NSString *)getLocalCurrentDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterNoStyle;
dateFormatter.timeZone = [NSTimeZone systemTimeZone];
return [NSDateFormatter localizedStringFromDate:[NSDate date]
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterNoStyle];
}
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date andDataObject:(CLTimezoneData *)dataObject
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy"
options:0
locale:[NSLocale currentLocale]];
NSDate *localDate = [formatter dateFromString:systemDate];
NSDate *timezoneDate = [formatter dateFromString:date];
if (localDate == nil || timezoneDate == nil) {
[CrashlyticsKit setUserEmail:systemDate];
[CrashlyticsKit setUserIdentifier:date];
return @"Today";
}
// Specify which units we would like to use
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate];
if ([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];
CLTimezoneData *newDataObject = [dataObject mutableCopy];
newDataObject.nextUpdate = tomorrowMidnight;
[self.defaultPreferences replaceObjectAtIndex:[self.defaultPreferences indexOfObject:dataObject] withObject:newDataObject];
[[NSUserDefaults standardUserDefaults] setObject:self.defaultPreferences forKey:CLDefaultPreferenceKey];
}
else if ([dataObject.nextUpdate isKindOfClass:[NSDate class]] &&
[dataObject.nextUpdate isEarlierThanOrEqualTo:timezoneDate])
{
[self getTimeZoneForLatitude:dataObject.latitude
andLongitude:dataObject.longitude
andDataObject:dataObject];
}
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 *)getDateForTimeZone:(CLTimezoneData *)dataObject
{
NSCalendar *currentCalendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *newDate = [currentCalendar dateByAddingUnit:NSCalendarUnitHour
value:self.futureSliderValue
toDate:[NSDate date]
options:kNilOptions];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterNoStyle;
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:dataObject.timezoneID];
NSNumber *relativeDayPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey];
if (relativeDayPreference.integerValue == 0) {
return [self compareSystemDate:[self getLocalCurrentDate]
toTimezoneDate:[dateFormatter stringFromDate:newDate] andDataObject:dataObject] ;;
}
else
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
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];
}
}
#pragma mark -
#pragma mark NSTableview Drag and Drop
#pragma mark -
@ -810,7 +610,6 @@ NSString *const CLTimezoneCellViewIdentifier = @"timeZoneCell";
return;
}
CLTimezoneData *newDataObject = [[CLTimezoneData alloc] init];
newDataObject.timezoneID = dataObject.timezoneID;
newDataObject.formattedAddress = dataObject.formattedAddress;

22
Clocker/Preferences/CLPreferencesView.xib

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
@ -199,14 +200,13 @@ CA
</tableHeaderView>
</scrollView>
<searchField toolTip="Search a timezone" wantsLayer="YES" focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="biT-6m-ElR">
<rect key="frame" x="8" y="288" width="329" height="24"/>
<rect key="frame" x="8" y="288" width="283" height="24"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" focusRingType="none" placeholderString="Enter a city, state, country name" drawsBackground="YES" usesSingleLineMode="YES" id="ijc-z6-99E">
<font key="font" size="13" name="SFUIDisplay-Light"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</searchFieldCell>
<connections>
<action selector="filterArray:" target="-2" id="f8p-qF-cfD"/>
<binding destination="-2" name="editable" keyPath="self.activityInProgress" id="qG8-46-bev">
<dictionary key="options">
<string key="NSValueTransformerName">NSNegateBoolean</string>
@ -280,14 +280,27 @@ CA
</binding>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2ez-Np-rIM">
<rect key="frame" x="288" y="283" width="58" height="32"/>
<buttonCell key="cell" type="push" title="Go" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="sbL-Gc-NTj">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="filterArray:" target="-2" id="KTU-QP-smI"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="KFC-NV-5A3" firstAttribute="leading" secondItem="cyZ-cL-S7a" secondAttribute="trailing" constant="4" id="1i8-FW-qYz"/>
<constraint firstAttribute="trailing" secondItem="biT-6m-ElR" secondAttribute="trailing" constant="8" id="23X-dw-hpU"/>
<constraint firstAttribute="trailing" secondItem="KFC-NV-5A3" secondAttribute="trailing" constant="15" id="B6V-vn-THO"/>
<constraint firstItem="LM9-75-vkc" firstAttribute="top" secondItem="biT-6m-ElR" secondAttribute="bottom" constant="3" id="DZR-XO-6sm"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="13" id="Ezn-kD-zu1"/>
<constraint firstAttribute="bottom" secondItem="KFC-NV-5A3" secondAttribute="bottom" constant="4" id="FWx-F1-VK8"/>
<constraint firstItem="85y-4a-860" firstAttribute="top" secondItem="2ez-Np-rIM" secondAttribute="bottom" constant="5" id="Gft-hZ-8vM"/>
<constraint firstItem="hp6-CH-WJs" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="Oir-hL-Og8"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="top" secondItem="ifx-PO-gfq" secondAttribute="bottom" constant="5" id="Pha-iy-RTE"/>
<constraint firstItem="ifx-PO-gfq" firstAttribute="centerX" secondItem="Q0t-hQ-orw" secondAttribute="centerX" id="QOS-0E-N10"/>
@ -295,9 +308,12 @@ CA
<constraint firstAttribute="trailing" secondItem="Wb6-yr-Pw4" secondAttribute="trailing" constant="15" id="RgE-qx-qrq"/>
<constraint firstItem="biT-6m-ElR" firstAttribute="top" secondItem="kXo-nl-oxR" secondAttribute="top" constant="8" id="Y7N-oR-3KY"/>
<constraint firstItem="LM9-75-vkc" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="ZJc-ws-AZR"/>
<constraint firstItem="2ez-Np-rIM" firstAttribute="top" secondItem="kXo-nl-oxR" secondAttribute="top" constant="9" id="fdw-te-IzK"/>
<constraint firstItem="cyZ-cL-S7a" firstAttribute="leading" secondItem="hp6-CH-WJs" secondAttribute="trailing" constant="2" id="g8m-TW-fLo"/>
<constraint firstAttribute="bottom" secondItem="hp6-CH-WJs" secondAttribute="bottom" constant="5" id="hEn-h1-my5"/>
<constraint firstItem="2ez-Np-rIM" firstAttribute="leading" secondItem="biT-6m-ElR" secondAttribute="trailing" constant="3" id="hq2-I2-ol4"/>
<constraint firstItem="biT-6m-ElR" firstAttribute="leading" secondItem="kXo-nl-oxR" secondAttribute="leading" constant="8" id="nhU-xR-AW2"/>
<constraint firstAttribute="trailing" secondItem="2ez-Np-rIM" secondAttribute="trailing" constant="5" id="p9u-rt-s1o"/>
<constraint firstAttribute="trailing" secondItem="LM9-75-vkc" secondAttribute="trailing" constant="8" id="pMs-Ol-hsh"/>
<constraint firstItem="Wb6-yr-Pw4" firstAttribute="centerY" secondItem="Q0t-hQ-orw" secondAttribute="centerY" id="uio-eQ-cpc"/>
</constraints>

37
Clocker/Preferences/CLPreferencesViewController.m

@ -30,6 +30,7 @@ NSString *const CLParseTimezoneNameProperty = @"areaName";
NSString *const CLMaxCharactersReachedError = @"Only 50 characters allowed!";
NSString *const CLNoInternetConnectivityError = @"You're offline, maybe?";
NSString *const CLLocationSearchURL = @"https://maps.googleapis.com/maps/api/geocode/json?address=%@&key=AIzaSyCyf2knCi6KiKuDJLYDBD3Odq5dt4c-_KI";
NSString *const CLTimezoneSearchURL = @"https://maps.googleapis.com/maps/api/timezone/json?location=%@&timestamp=%f&key=AIzaSyCyf2knCi6KiKuDJLYDBD3Odq5dt4c-_KI";
NSString *const CLTryAgainMessage = @"Try again, maybe?";
@interface CLPreferencesViewController ()
@ -108,21 +109,25 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
- (nullable id)tableView:(NSTableView *)tableView objectValueForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row
{
CLTimezoneData *dataSource;
CLTimezoneData *dataSource, *selectedDataSource;
if (self.filteredArray.count > 0)
{
dataSource = self.filteredArray[row];
}
if (self.selectedTimeZones.count > row) {
selectedDataSource = [CLTimezoneData getCustomObject:self.selectedTimeZones[row]];
}
if ([[tableColumn identifier] isEqualToString:CLPreferencesTimezoneNameIdentifier])
{
if ([self.selectedTimeZones[row][CLTimezoneName] length] > 0) {
return self.selectedTimeZones[row][CLTimezoneName];
if ([selectedDataSource.formattedAddress length] > 0) {
return selectedDataSource.formattedAddress;
}
return self.selectedTimeZones[row][CLTimezoneID];
return selectedDataSource.timezoneID;
}
else if([[tableColumn identifier] isEqualToString:CLPreferencesAvailableTimezoneIdentifier])
{
@ -135,7 +140,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
}
else if([[tableColumn identifier] isEqualToString:CLPreferencesCustomLabelIdentifier])
{
return self.selectedTimeZones[row][CLCustomLabel];
return selectedDataSource.customLabel;
}
return nil;
@ -194,11 +199,11 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
CLTimezoneData *dataObject = self.filteredArray[self.availableTimezoneTableView.selectedRow];
for (NSMutableDictionary *timezoneDictionary in self.selectedTimeZones)
for (NSData *encodedData in self.selectedTimeZones)
{
NSString *name = timezoneDictionary[CLPlaceIdentifier];
CLTimezoneData *timezoneObject = [CLTimezoneData getCustomObject:encodedData];
NSString *name = timezoneObject.place_id;
NSString *selectedPlaceID = dataObject.place_id;
if (self.searchField.stringValue.length > 0) {
@ -473,7 +478,11 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
self.availableTimezoneTableView.hidden = YES;
NSString *urlString = [NSString stringWithFormat:@"http://api.geonames.org/timezoneJSON?lat=%@&lng=%@&username=abhishaker17", latitude, longitude];
NSString *tuple = [NSString stringWithFormat:@"%@,%@", latitude, longitude];
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
NSString *urlString = [NSString stringWithFormat:CLTimezoneSearchURL, tuple, timestamp];
[CLAPI dataTaskWithServicePath:urlString
bySender:self
@ -489,11 +498,9 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
return;
}
if ([json[@"status"][@"message"] isEqualToString:@"the hourly limit of 2000 credits for abhishaker17 has been exceeded. Please throttle your requests or use the commercial service."])
{
if ([json[@"status"] isEqualToString:@"ZERO_RESULTS"]) {
self.placeholderLabel.placeholderString = @"No results! 😔 Try entering the exact name.";
self.activityInProgress = NO;
self.placeholderLabel.placeholderString = @"API limit reached. Try again in an hour.?";
self.searchField.placeholderString = @"We rely on free APIs which have limits.";
return;
}
@ -515,7 +522,7 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?";
[newTimezone setObject:json[@"sunset"] forKey:@"sunsetTime"];
}
[newTimezone setObject:json[@"timezoneId"] forKey:CLTimezoneID];
[newTimezone setObject:json[@"timeZoneId"] forKey:CLTimezoneID];
[newTimezone setObject:filteredAddress forKey:CLTimezoneName];

Loading…
Cancel
Save