Browse Source

New data handler class!

v1.2.3
Abhishek Banthia 9 years ago
parent
commit
a1f52ce832
  1. 125
      Clocker/Model/CLTimezoneData.m

125
Clocker/Model/CLTimezoneData.m

@ -6,15 +6,16 @@
// //
// //
#import "CLAPI.h"
#import "CLTimezoneData.h" #import "CLTimezoneData.h"
#import "CommonStrings.h" #import "CommonStrings.h"
#import "DateTools.h" #import "DateTools.h"
#import "CLAPI.h"
#import "PanelController.h" #import "PanelController.h"
#import <Parse/Parse.h> #import <Parse/Parse.h>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
@implementation CLTimezoneData @implementation CLTimezoneData
-(instancetype)initWithDictionary:(NSDictionary *)dictionary -(instancetype)initWithDictionary:(NSDictionary *)dictionary
@ -58,13 +59,21 @@
+ (instancetype)getCustomObject:(NSData *)encodedData + (instancetype)getCustomObject:(NSData *)encodedData
{ {
if ([encodedData isKindOfClass:[NSDictionary class]])
if (encodedData)
{ {
CLTimezoneData *newObject = [[self alloc] initWithDictionary:(NSDictionary *)encodedData]; if ([encodedData isKindOfClass:[NSDictionary class]])
return newObject; {
CLTimezoneData *newObject = [[self alloc] initWithDictionary:(NSDictionary *)encodedData];
return newObject;
}
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData];
return object;
} }
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData];
return object; return nil;
} }
@ -136,45 +145,45 @@
} }
/* /*
- (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell - (NSString *)getFormattedSunriseOrSunsetTimeAndSunImage:(CLTimezoneCellView *)cell
{ {
if (!self.shouldFetchSunTimings) { if (!self.shouldFetchSunTimings) {
return CLEmptyString; return CLEmptyString;
} }
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm"; formatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *sunTime = [formatter dateFromString:self.sunriseTime]; NSDate *sunTime = [formatter dateFromString:self.sunriseTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID]; dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateFormatter.dateStyle = kCFDateFormatterShortStyle; dateFormatter.dateStyle = kCFDateFormatterShortStyle;
dateFormatter.timeStyle = kCFDateFormatterShortStyle; dateFormatter.timeStyle = kCFDateFormatterShortStyle;
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm"; dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *newDate = [dateFormatter stringFromDate:[NSDate date]]; NSString *newDate = [dateFormatter stringFromDate:[NSDate date]];
NSDateFormatter *dateConversion = [[NSDateFormatter alloc] init]; NSDateFormatter *dateConversion = [[NSDateFormatter alloc] init];
dateConversion.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID]; dateConversion.timeZone = [NSTimeZone timeZoneWithName:self.timezoneID];
dateConversion.dateStyle = kCFDateFormatterShortStyle; dateConversion.dateStyle = kCFDateFormatterShortStyle;
dateConversion.timeStyle = kCFDateFormatterShortStyle; dateConversion.timeStyle = kCFDateFormatterShortStyle;
dateConversion.dateFormat = @"yyyy-MM-dd HH:mm"; dateConversion.dateFormat = @"yyyy-MM-dd HH:mm";
NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey]; NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey];
if ([sunTime laterDate:[dateConversion dateFromString:newDate]] == sunTime) if ([sunTime laterDate:[dateConversion dateFromString:newDate]] == sunTime)
{ {
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ? cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"White Sunrise"]; [NSImage imageNamed:@"Sunrise"] : [NSImage imageNamed:@"White Sunrise"];
return [self.sunriseTime substringFromIndex:11]; return [self.sunriseTime substringFromIndex:11];
} }
else else
{ {
cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ? cell.sunImage.image = theme.length > 0 && [theme isEqualToString:@"Default"] ?
[NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"]; [NSImage imageNamed:@"Sunset"] : [NSImage imageNamed:@"White Sunset"];
return [self.sunsetTime substringFromIndex:11]; return [self.sunsetTime substringFromIndex:11];
} }
}*/ }*/
- (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue - (NSString *)getTimeForTimeZoneWithFutureSliderValue:(NSInteger)futureSliderValue
{ {
@ -211,6 +220,9 @@
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date - (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date
{ {
NSParameterAssert(systemDate);
NSParameterAssert(date);
NSDateFormatter *formatter = [NSDateFormatter new]; NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy" formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy"
options:0 options:0
@ -219,9 +231,8 @@
NSDate *localDate = [formatter dateFromString:systemDate]; NSDate *localDate = [formatter dateFromString:systemDate];
NSDate *timezoneDate = [formatter dateFromString:date]; NSDate *timezoneDate = [formatter dateFromString:date];
if (localDate == nil || timezoneDate == nil) { NSAssert(localDate != nil, @"Local date cannot be nil");
return @"Today"; NSAssert(timezoneDate != nil, @"Local date cannot be nil");
}
// Specify which units we would like to use // Specify which units we would like to use
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
@ -310,6 +321,7 @@
- (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger - (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger
{ {
if (weekdayInteger > 7) { if (weekdayInteger > 7) {
weekdayInteger = weekdayInteger - 7; weekdayInteger = weekdayInteger - 7;
} }
@ -359,12 +371,17 @@
if (shouldCityBeShown.boolValue == 0) if (shouldCityBeShown.boolValue == 0)
{ {
self.customLabel.length > 0 ?
[menuTitle appendString:self.customLabel] :
[menuTitle appendString:self.formattedAddress]; [menuTitle appendString:self.formattedAddress];
} }
if (shouldDayBeShown.boolValue == 0) if (shouldDayBeShown.boolValue == 0)
{ {
NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0 andDisplayType:CLMenuDisplay]; NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0 andDisplayType:CLMenuDisplay];
substring = [substring substringToIndex:3]; substring = [substring substringToIndex:3];
if (menuTitle.length > 0) if (menuTitle.length > 0)
@ -406,10 +423,20 @@
- (void)sendAnalyticsData - (void)sendAnalyticsData
{ {
NSAssert(self.formattedAddress != nil, @"Formatted Address cannot be nil before sending analytics");
NSAssert(self.timezoneID != nil, @"Timezone ID cannot be nil before sending analytics");
NSString *uniqueIdentifier = [self getSerialNumber];
if (uniqueIdentifier == nil)
{
uniqueIdentifier = @"N/A";
}
PFObject *feedbackObject = [PFObject objectWithClassName:@"CLTimezoneData"]; PFObject *feedbackObject = [PFObject objectWithClassName:@"CLTimezoneData"];
feedbackObject[@"formattedAddress"] = self.formattedAddress; feedbackObject[@"formattedAddress"] = self.formattedAddress;
feedbackObject[@"timezoneID"] = self.timezoneID; feedbackObject[@"timezoneID"] = self.timezoneID;
feedbackObject[@"uniqueID"] = [self getSerialNumber]; feedbackObject[@"uniqueID"] = uniqueIdentifier;
[feedbackObject saveEventually]; [feedbackObject saveEventually];
} }

Loading…
Cancel
Save