You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.9 KiB

9 years ago
//
// CLTimezoneData.m
// Clocker
//
// Created by Abhishek Banthia on 12/22/15.
//
//
#import "CLAPIConnector.h"
9 years ago
#import "CLTimezoneData.h"
9 years ago
#import "CommonStrings.h"
9 years ago
#import "DateTools.h"
#import "PanelController.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.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
9 years ago
@implementation CLTimezoneData
9 years ago
-(instancetype)initWithDictionary:(NSDictionary *)dictionary
9 years ago
{
self = [super init];
if (self)
9 years ago
{
self.customLabel = dictionary[CLCustomLabel];
self.timezoneID = dictionary[CLTimezoneID];
9 years ago
self.latitude = dictionary[@"latitude"];
self.longitude = dictionary[@"longitude"];
self.place_id = dictionary[CLPlaceIdentifier];
self.formattedAddress = dictionary[CLTimezoneName];
self.isFavourite = @(NSOffState);
9 years ago
self.selectionType = CLCitySelection;
9 years ago
}
9 years ago
9 years ago
return self;
9 years ago
}
-(instancetype)init
{
self = [super init];
if (self)
{
self.selectionType = CLTimezoneSelection;
self.isFavourite = @(NSOffState);
}
return self;
}
+ (instancetype)getCustomObject:(NSData *)encodedData
{
if (encodedData)
{
if ([encodedData isKindOfClass:[NSDictionary class]])
{
CLTimezoneData *newObject = [[self alloc] initWithDictionary:(NSDictionary *)encodedData];
return newObject;
}
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedData];
return object;
}
return nil;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.place_id forKey:@"place_id"];
[coder encodeObject:self.formattedAddress forKey:@"formattedAddress"];
[coder encodeObject:self.customLabel forKey:@"customLabel"];
[coder encodeObject:self.timezoneID forKey:@"timezoneID"];
[coder encodeObject:self.nextUpdate forKey:@"nextUpdate"];
[coder encodeObject:self.latitude forKey:@"latitude"];
[coder encodeObject:self.longitude forKey:@"longitude"];
[coder encodeObject:self.isFavourite forKey:@"isFavourite"];
[coder encodeObject:self.sunriseTime forKey:@"sunriseTime"];
[coder encodeObject:self.sunsetTime forKey:@"sunsetTime"];
9 years ago
[coder encodeInteger:self.selectionType forKey:@"selectionType"];
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super init];
if (self)
{
self.place_id = [coder decodeObjectForKey:@"place_id"];
self.formattedAddress = [coder decodeObjectForKey:@"formattedAddress"];
self.customLabel = [coder decodeObjectForKey:@"customLabel"];
self.timezoneID = [coder decodeObjectForKey:@"timezoneID"];
self.nextUpdate = [coder decodeObjectForKey:@"nextUpdate"];
self.latitude = [coder decodeObjectForKey:@"latitude"];
self.longitude = [coder decodeObjectForKey:@"longitude"];
self.isFavourite = [coder decodeObjectForKey:@"isFavourite"];
self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"];
self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"];
9 years ago
self.selectionType = [coder decodeIntegerForKey:@"selectionType"];
}
return self;
}
9 years ago
-(NSString *)description
{
9 years ago
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@\nSunrise Time: %@\nSunset Time: %@\nSelection Type: %zd", self.timezoneID,
9 years ago
self.formattedAddress,
self.customLabel,
self.latitude,
self.longitude,
self.place_id,
self.isFavourite,
self.sunriseTime,
9 years ago
self.sunsetTime,
self.selectionType];
9 years ago
}
- (NSString *)getFormattedTimezoneLabel
9 years ago
{
if (self.customLabel.length > 0)
{
return self.customLabel;
9 years ago
}
if ([self.formattedAddress length] > 0)
9 years ago
{
return self.formattedAddress;
9 years ago
}
else if (self.timezoneID)
9 years ago
{
NSString *timezoneID = self.timezoneID;
9 years ago
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";
}
}
- (void)setLabelForTimezone:(NSString *)customLabel
9 years ago
{
self.customLabel = customLabel.length > 0 ? customLabel : CLEmptyString;
9 years ago
}
- (void)setIDForTimezone:(NSString *)uniqueID
{
self.timezoneID = uniqueID;
}
-(void)setFormattedAddressForTimezone:(NSString *)address
9 years ago
{
self.formattedAddress = address;
9 years ago
}
-(void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue
{
self.isFavourite = favouriteValue;
9 years ago
}
-(void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate
9 years ago
{
self.nextUpdate = nextUpdate;
9 years ago
}
-(void)setSunsetTimeForTimezone:(NSDate *)sunsetTime
9 years ago
{
self.sunsetTime = sunsetTime;
9 years ago
}
-(void)setSunriseTimeForTimezone:(NSDate *)sunriseTime
{
self.sunriseTime = sunriseTime;
}
- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset
{
self.sunriseOrSunset = sunriseOrSunset;
}
- (void)setLatitudeForTimezone:(NSString *)latitude
{
self.latitude = latitude;
}
9 years ago
- (void)setLongitudeForTimezone:(NSString *)longitude
{
self.longitude = longitude;
}
9 years ago
@end