Browse Source

Nuking CLTimezoneData.

pull/92/head
Abhishek 4 years ago
parent
commit
5267bdf547
  1. 1
      Clocker/Clocker-Bridging-Header.h
  2. 6
      Clocker/Clocker.xcodeproj/project.pbxproj
  3. 1
      Clocker/ClockerUITests/ClockerUITests.m
  4. 3
      Clocker/ClockerUITests/FloatingWindowTests.swift
  5. 3
      Clocker/ClockerUITests/PreferencesTest.swift
  6. 2
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  7. 64
      Clocker/Panel/Data Layer/CLTimezoneData.h
  8. 334
      Clocker/Panel/Data Layer/CLTimezoneData.m
  9. 53
      Clocker/Panel/Data Layer/TimezoneData.swift
  10. 10
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  11. 2
      Clocker/Panel/ParentPanelController.swift
  12. 2
      Clocker/Panel/UI/TimezoneDataSource.swift
  13. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift

1
Clocker/Clocker-Bridging-Header.h

@ -5,7 +5,6 @@
// Created by Banthia, Abhishek on 12/22/17. // Created by Banthia, Abhishek on 12/22/17.
// //
#import "CLTimezoneData.h"
#import "iVersion.h" #import "iVersion.h"
#import <ShortcutRecorder/ShortcutRecorder.h> #import <ShortcutRecorder/ShortcutRecorder.h>
#import <PTHotKey/PTHotKeyCenter.h> #import <PTHotKey/PTHotKeyCenter.h>

6
Clocker/Clocker.xcodeproj/project.pbxproj

@ -77,7 +77,6 @@
35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */; }; 35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */; };
35C36F792259E1D0002FA5C6 /* String + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F762259E1CF002FA5C6 /* String + Additions.swift */; }; 35C36F792259E1D0002FA5C6 /* String + Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F762259E1CF002FA5C6 /* String + Additions.swift */; };
35C36F912259EAF4002FA5C6 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */; }; 35C36F912259EAF4002FA5C6 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */; };
35C36F942259EB87002FA5C6 /* CLTimezoneData.m in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F932259EB87002FA5C6 /* CLTimezoneData.m */; };
35C36F972259EBB1002FA5C6 /* AppFeedbackWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */; }; 35C36F972259EBB1002FA5C6 /* AppFeedbackWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */; };
35C36F982259EBB1002FA5C6 /* AppFeedbackWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */; }; 35C36F982259EBB1002FA5C6 /* AppFeedbackWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */; };
35C36FA02259ED6D002FA5C6 /* CalendarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */; }; 35C36FA02259ED6D002FA5C6 /* CalendarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */; };
@ -299,8 +298,6 @@
35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Foundation + Additions.swift"; sourceTree = "<group>"; }; 35C36F752259E1CF002FA5C6 /* Foundation + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Foundation + Additions.swift"; sourceTree = "<group>"; };
35C36F762259E1CF002FA5C6 /* String + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String + Additions.swift"; sourceTree = "<group>"; }; 35C36F762259E1CF002FA5C6 /* String + Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String + Additions.swift"; sourceTree = "<group>"; };
35C36F902259EAF4002FA5C6 /* Preferences.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = "<group>"; }; 35C36F902259EAF4002FA5C6 /* Preferences.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = "<group>"; };
35C36F922259EB87002FA5C6 /* CLTimezoneData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLTimezoneData.h; sourceTree = "<group>"; };
35C36F932259EB87002FA5C6 /* CLTimezoneData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLTimezoneData.m; sourceTree = "<group>"; };
35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AppFeedbackWindow.xib; sourceTree = "<group>"; }; 35C36F952259EBB1002FA5C6 /* AppFeedbackWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AppFeedbackWindow.xib; sourceTree = "<group>"; };
35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppFeedbackWindowController.swift; sourceTree = "<group>"; }; 35C36F962259EBB1002FA5C6 /* AppFeedbackWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppFeedbackWindowController.swift; sourceTree = "<group>"; };
35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarHandler.swift; sourceTree = "<group>"; }; 35C36F9D2259ED6D002FA5C6 /* CalendarHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarHandler.swift; sourceTree = "<group>"; };
@ -588,8 +585,6 @@
35C36F512259DC85002FA5C6 /* Data Layer */ = { 35C36F512259DC85002FA5C6 /* Data Layer */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
35C36F922259EB87002FA5C6 /* CLTimezoneData.h */,
35C36F932259EB87002FA5C6 /* CLTimezoneData.m */,
35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */, 35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */,
35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */, 35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */,
); );
@ -1231,7 +1226,6 @@
35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */, 35C36F782259E1D0002FA5C6 /* Foundation + Additions.swift in Sources */,
35C36F16225961DA002FA5C6 /* Date+Inits.swift in Sources */, 35C36F16225961DA002FA5C6 /* Date+Inits.swift in Sources */,
35C36F4F2259D981002FA5C6 /* AppDefaults.swift in Sources */, 35C36F4F2259D981002FA5C6 /* AppDefaults.swift in Sources */,
35C36F942259EB87002FA5C6 /* CLTimezoneData.m in Sources */,
35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */, 35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */,
3508CC942599FFEC000E3530 /* MenubarHandler.swift in Sources */, 3508CC942599FFEC000E3530 /* MenubarHandler.swift in Sources */,
35C36F14225961DA002FA5C6 /* Integer+DateTools.swift in Sources */, 35C36F14225961DA002FA5C6 /* Integer+DateTools.swift in Sources */,

1
Clocker/ClockerUITests/ClockerUITests.m

@ -1,7 +1,6 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "CLTimezoneData.h"
#import "CommonStrings.h" #import "CommonStrings.h"
@interface ClockerUITests : XCTestCase @interface ClockerUITests : XCTestCase

3
Clocker/ClockerUITests/FloatingWindowTests.swift

@ -25,11 +25,8 @@ class FloatingWindowTests: XCTestCase {
} }
addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in addUIInterruptionMonitor(withDescription: "Reminders Access") { (alert) -> Bool in
Logger.info("Interruption Handler called")
Logger.info(alert.description)
let alertButton = alert.buttons["OK"] let alertButton = alert.buttons["OK"]
if alertButton.exists { if alertButton.exists {
Logger.info("Okay button found")
alertButton.tap() alertButton.tap()
return true return true
} }

3
Clocker/ClockerUITests/PreferencesTest.swift

@ -392,8 +392,7 @@ extension XCTestCase {
let isHittable = NSPredicate(format: "exists == true", "") let isHittable = NSPredicate(format: "exists == true", "")
let addExpectation = expectation(for: isHittable, let addExpectation = expectation(for: isHittable,
evaluatedWith: results.firstMatch) { () -> Bool in evaluatedWith: results.firstMatch) { () -> Bool in
Logger.info("Handler called") true
return true
} }
waiter.wait(for: [addExpectation], timeout: 5) waiter.wait(for: [addExpectation], timeout: 5)

2
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -156,7 +156,7 @@ class ClockerUnitTests: XCTestCase {
let dataObject = TimezoneData(with: mumbai) let dataObject = TimezoneData(with: mumbai)
let operations = TimezoneDataOperations(with: dataObject) let operations = TimezoneDataOperations(with: dataObject)
XCTAssertNotNil(operations.date(with: 0, displayType: .menuDisplay)) XCTAssertNotNil(operations.date(with: 0, displayType: .menu))
} }
func testTimezoneFormat() { func testTimezoneFormat() {

64
Clocker/Panel/Data Layer/CLTimezoneData.h

@ -1,64 +0,0 @@
// Copyright © 2015 Abhishek Banthia
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, CLDateDisplayType) {
CLPanelDisplay,
CLMenuDisplay
};
typedef NS_ENUM(NSUInteger, CLSelection) {
CLCitySelection,
CLTimezoneSelection
};
typedef NS_ENUM(NSUInteger, CLTimezoneOverride) {
CL12HourFormat,
CL24HourFormat,
CLGlobalFormat
};
@interface CLTimezoneData : NSObject<NSCoding>
@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) NSNumber *latitude;
@property (copy, nonatomic, readonly) NSNumber *longitude;
@property (copy, nonatomic, readonly) NSString *note;
@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;
@property (assign, nonatomic, readonly) BOOL isSystemTimezone; //Used for figuring out if we want to show a home indicator
@property (assign, nonatomic, readonly) CLTimezoneOverride overrideFormat;
+ (instancetype)getCustomObject:(NSData *)encodedData;
- (instancetype)initWithTimezoneInfo:(NSDictionary *)dictionary;
- (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;
- (void)setLocationIndicator:(BOOL)isCurrentLocation;
- (void)setShouldOverrideGlobalTimeFormat:(NSNumber *)shouldOverride;
- (void)setNoteForTimezone:(NSString *)note;
- (NSString *)timezoneFormat;
- (NSString *)getFormattedTimezoneLabel;
- (NSString *)getTimezone;
- (BOOL)isEmpty;
@end

334
Clocker/Panel/Data Layer/CLTimezoneData.m

@ -1,334 +0,0 @@
// Copyright © 2015 Abhishek Banthia
#import "CLTimezoneData.h"
#import "CommonStrings.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#import "Clocker-Swift.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) NSNumber *latitude;
@property (copy, nonatomic) NSNumber *longitude;
@property (copy, nonatomic) NSString *note;
@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 (assign, nonatomic) BOOL isSystemTimezone;
@property (assign, nonatomic) CLTimezoneOverride overrideFormat;
@end
@implementation CLTimezoneData
-(instancetype)initWithTimezoneInfo:(NSDictionary *)dictionary
{
self = [super init];
if (self)
{
self.customLabel = dictionary[CLCustomLabel];
self.timezoneID = dictionary[CLTimezoneID];
self.latitude = dictionary[@"latitude"];
self.longitude = dictionary[@"longitude"];
self.place_id = dictionary[CLPlaceIdentifier];
self.formattedAddress = dictionary[CLTimezoneName];
self.isFavourite = @(NSOffState);
self.selectionType = CLCitySelection;
self.note = dictionary[@"note"];
self.isSystemTimezone = NO;
self.overrideFormat = CLGlobalFormat;
}
return self;
}
-(instancetype)init
{
self = [super init];
if (self)
{
self.selectionType = CLTimezoneSelection;
self.isFavourite = @(NSOffState);
self.note = CLEmptyString;
self.isSystemTimezone = NO;
self.overrideFormat = CLGlobalFormat;
}
return self;
}
+ (instancetype)getCustomObject:(NSData *)encodedData
{
if (encodedData)
{
if ([encodedData isKindOfClass:[NSDictionary class]])
{
CLTimezoneData *newObject = [[self alloc] initWithTimezoneInfo:(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"];
[coder encodeInteger:self.selectionType forKey:@"selectionType"];
[coder encodeObject:self.note forKey:@"note"];
[coder encodeBool:self.isSystemTimezone forKey:@"isSystemTimezone"];
[coder encodeInteger:self.overrideFormat forKey:@"overrideFormat"];
}
- (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.note = [coder decodeObjectForKey:@"note"];
self.longitude = [coder decodeObjectForKey:@"longitude"];
self.isFavourite = [coder decodeObjectForKey:@"isFavourite"];
self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"];
self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"];
self.selectionType = [coder decodeIntegerForKey:@"selectionType"];
self.isSystemTimezone = NO;
self.overrideFormat = [coder decodeIntegerForKey:@"overrideFormat"];
}
return self;
}
-(NSString *)description
{
return [NSString stringWithFormat:@"TimezoneID: %@\nFormatted Address: %@\nCustom Label: %@\nLatitude: %@\nLongitude:%@\nPlaceID: %@\nisFavourite: %@\nSunrise Time: %@\nSunset Time: %@\nSelection Type: %zd\nNote: %@\nSystemTimezone: %hhd\nOverride: %zd", self.timezoneID,
self.formattedAddress,
self.customLabel,
self.latitude,
self.longitude,
self.place_id,
self.isFavourite,
self.sunriseTime,
self.sunsetTime,
self.selectionType,
self.note,
self.isSystemTimezone,
self.overrideFormat];
}
- (NSString *)getFormattedTimezoneLabel
{
if (self.customLabel.length > 0)
{
return self.customLabel;
}
if ([self.formattedAddress length] > 0)
{
return self.formattedAddress;
}
else if (self.timezoneID)
{
NSString *timezoneID = self.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";
}
}
- (void)setLabelForTimezone:(NSString *)customLabel
{
self.customLabel = customLabel.length > 0 ? customLabel : CLEmptyString;
}
- (void)setIDForTimezone:(NSString *)uniqueID
{
self.timezoneID = uniqueID;
}
- (void)setLocationIndicator:(BOOL)isCurrentLocation {
self.isSystemTimezone = isCurrentLocation;
}
-(void)setFormattedAddressForTimezone:(NSString *)address
{
self.formattedAddress = address;
}
-(void)setFavouriteValueForTimezone:(NSNumber *)favouriteValue
{
self.isFavourite = favouriteValue;
}
-(void)setNextUpdateForSunriseSet:(NSDate *)nextUpdate
{
self.nextUpdate = nextUpdate;
}
-(void)setSunsetTimeForTimezone:(NSDate *)sunsetTime
{
self.sunsetTime = sunsetTime;
}
-(void)setSunriseTimeForTimezone:(NSDate *)sunriseTime
{
self.sunriseTime = sunriseTime;
}
-(void)setShouldOverrideGlobalTimeFormat:(NSNumber *)shouldOverride
{
if ([shouldOverride isEqualToNumber:@(0)]) {
NSLog(@"Updated to 12 Hour Format");
self.overrideFormat = CL12HourFormat;
} else if ([shouldOverride isEqualToNumber:@(1)]) {
NSLog(@"Updated to 24 Hour Format");
self.overrideFormat = CL24HourFormat;
} else {
NSLog(@"Updated to Global Hour Format");
self.overrideFormat = CLGlobalFormat;
}
}
- (NSString *)timezoneFormat {
NSString *dateFormat = nil;
NSNumber *is24HourFormatSelected = [[NSUserDefaults standardUserDefaults] objectForKey:CL24hourFormatSelectedKey];
NSNumber *showSeconds = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowSecondsInMenubar];
if([showSeconds isEqualToNumber:@(0)])
{
if (self.overrideFormat == CLGlobalFormat) {
dateFormat = [is24HourFormatSelected isEqualToNumber:@(0)] ? @"h:mm:ss a" : @"H:mm:ss";
} else if (self.overrideFormat == CL12HourFormat) {
dateFormat = @"h:mm:ss a";
} else if (self.overrideFormat == CL24HourFormat) {
dateFormat = @"H:mm:ss";
} else {
assert("Something's wrong here.");
}
}
else
{
if (self.overrideFormat == CLGlobalFormat) {
dateFormat = [is24HourFormatSelected isEqualToNumber:@(0)] ? @"h:mm a" : @"H:mm";
} else if (self.overrideFormat == CL12HourFormat) {
dateFormat = @"h:mm a";
} else if (self.overrideFormat == CL24HourFormat) {
dateFormat = @"H:mm";
} else {
assert("Something's wrong here.");
}
}
return dateFormat;
}
- (void)setSunriseOrSunsetForTimezone:(BOOL)sunriseOrSunset
{
self.sunriseOrSunset = sunriseOrSunset;
}
- (void)setLatitudeForTimezone:(NSNumber *)latitude
{
self.latitude = latitude;
}
- (void)setLongitudeForTimezone:(NSNumber *)longitude
{
self.longitude = longitude;
}
- (void)setNoteForTimezone:(NSString *)note
{
self.note = note;
}
- (NSString *)getTimezone {
if (self.isSystemTimezone == YES) {
[NSTimeZone resetSystemTimeZone];
[self setTimezoneID:[[NSTimeZone systemTimeZone] name]];
[self setFormattedAddress:[[NSTimeZone systemTimeZone] name]];
return [[NSTimeZone systemTimeZone] name];
} else {
return self.timezoneID;
}
}
- (BOOL)isEmpty
{
if ([self checkPropertyForNil:self.timezoneID] || [self checkPropertyForNil:self.place_id] ||
[self checkPropertyForNil:self.formattedAddress] || [self checkPropertyForNil:self.latitude] || [self checkPropertyForNil:self.longitude]) {
return YES;
}
return NO;
}
- (BOOL)checkPropertyForNil:(id)property
{
if (property == nil || property == [NSNull null]) {
return YES;
}
return NO;
}
- (BOOL)isEqual:(id)object {
if (![self isKindOfClass:[self class]] || ![object isKindOfClass:[self class]]) {
return NO;
}
CLTimezoneData *comparisonObject = (CLTimezoneData *)object;
return [self.place_id isEqualToString:comparisonObject.place_id];
}
- (NSUInteger)hash{
return self.place_id.hash ^ self.timezoneID.hash;
}
@end

53
Clocker/Panel/Data Layer/TimezoneData.swift

@ -80,31 +80,6 @@ class TimezoneData: NSObject, NSCoding {
placeID = UUID().uuidString placeID = UUID().uuidString
} }
init(with originalTimezone: CLTimezoneData) {
customLabel = originalTimezone.customLabel
formattedAddress = originalTimezone.formattedAddress
placeID = originalTimezone.place_id
timezoneID = originalTimezone.timezoneID
if originalTimezone.latitude != nil {
latitude = originalTimezone.latitude.doubleValue
}
if originalTimezone.longitude != nil {
longitude = originalTimezone.longitude.doubleValue
}
note = originalTimezone.note
nextUpdate = originalTimezone.nextUpdate
sunriseTime = originalTimezone.sunriseTime
sunsetTime = originalTimezone.sunsetTime
isFavourite = originalTimezone.isFavourite.intValue
isSunriseOrSunset = originalTimezone.sunriseOrSunset
selectionType = originalTimezone.selectionType == CLSelection.citySelection ? .city : .timezone
isSystemTimezone = originalTimezone.isSystemTimezone
overrideFormat = .globalFormat
}
init(with dictionary: [String: Any]) { init(with dictionary: [String: Any]) {
if let label = dictionary[CLCustomLabel] as? String { if let label = dictionary[CLCustomLabel] as? String {
customLabel = label customLabel = label
@ -196,32 +171,11 @@ class TimezoneData: NSObject, NSCoding {
if let timezoneObject = NSKeyedUnarchiver.unarchiveObject(with: dataObject) as? TimezoneData { if let timezoneObject = NSKeyedUnarchiver.unarchiveObject(with: dataObject) as? TimezoneData {
return timezoneObject return timezoneObject
} else if let originalTimezoneObject = NSKeyedUnarchiver.unarchiveObject(with: dataObject) as? CLTimezoneData {
logOldModelUsage()
return TimezoneData(with: originalTimezoneObject)
} }
return nil return nil
} }
private class func logOldModelUsage() {
guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String,
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else {
return
}
let operatingSystem = ProcessInfo.processInfo.operatingSystemVersion
let osVersion = "\(operatingSystem.majorVersion).\(operatingSystem.minorVersion).\(operatingSystem.patchVersion)"
let versionInfo = "Clocker \(shortVersion) (\(appVersion))"
let feedbackInfo = [
AppFeedbackConstants.CLOperatingSystemVersion: osVersion,
AppFeedbackConstants.CLClockerVersion: versionInfo,
]
Logger.log(object: feedbackInfo, for: "CLTimezoneData is still being used!")
}
/// Converts the Obj-C model objects into Swift /// Converts the Obj-C model objects into Swift
class func convert() { class func convert() {
if let timezones = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data], !timezones.isEmpty { if let timezones = DataStore.shared().retrieve(key: CLDefaultPreferenceKey) as? [Data], !timezones.isEmpty {
@ -243,12 +197,7 @@ class TimezoneData: NSObject, NSCoding {
for timezone in timezones { for timezone in timezones {
// Get the old (aka CLTimezoneData) model object // Get the old (aka CLTimezoneData) model object
let old = NSKeyedUnarchiver.unarchiveObject(with: timezone) let old = NSKeyedUnarchiver.unarchiveObject(with: timezone)
if let oldModel = old as? CLTimezoneData { if let newModel = old as? Clocker.TimezoneData {
// Convert it to new model and add it
Logger.info("We're still using old Objective-C models")
let newTimezone = TimezoneData(with: oldModel)
newModels.append(newTimezone)
} else if let newModel = old as? TimezoneData {
if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil { if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil {
print("Resetting Global Format") print("Resetting Global Format")
newModel.setShouldOverrideGlobalTimeFormat(0) newModel.setShouldOverrideGlobalTimeFormat(0)

10
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -100,7 +100,7 @@ extension TimezoneDataOperations {
let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar) let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar)
if shouldDayBeShown, shouldLabelBeShownAlongWithTime { if shouldDayBeShown, shouldLabelBeShownAlongWithTime {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) let substring = date(with: 0, displayType: .menu)
subtitle.append(substring) subtitle.append(substring)
} }
@ -120,7 +120,7 @@ extension TimezoneDataOperations {
let shouldLabelsNotBeShownAlongWithTime = DataStore.shared().shouldDisplay(.placeInMenubar) let shouldLabelsNotBeShownAlongWithTime = DataStore.shared().shouldDisplay(.placeInMenubar)
if shouldDayBeShown, shouldLabelsNotBeShownAlongWithTime { if shouldDayBeShown, shouldLabelsNotBeShownAlongWithTime {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) let substring = date(with: 0, displayType: .menu)
subtitle.append(substring) subtitle.append(substring)
} }
@ -162,7 +162,7 @@ extension TimezoneDataOperations {
} }
if shouldDayBeShown { if shouldDayBeShown {
var substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) var substring = date(with: 0, displayType: .menu)
if substring.count > 3 { if substring.count > 3 {
let endIndex = substring.index(substring.startIndex, offsetBy: 2) let endIndex = substring.index(substring.startIndex, offsetBy: 2)
@ -214,7 +214,7 @@ extension TimezoneDataOperations {
to: Date()) ?? Date() to: Date()) ?? Date()
} }
func date(with sliderValue: Int, displayType: CLDateDisplayType) -> String { func date(with sliderValue: Int, displayType: TimezoneData.DateDisplayType) -> String {
guard let relativeDayPreference = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber else { guard let relativeDayPreference = DataStore.shared().retrieve(key: CLRelativeDateKey) as? NSNumber else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
return CLEmptyString return CLEmptyString
@ -229,7 +229,7 @@ extension TimezoneDataOperations {
let convertedDate = timezoneDate(with: sliderValue, currentCalendar) let convertedDate = timezoneDate(with: sliderValue, currentCalendar)
if displayType == CLDateDisplayType.panelDisplay { if displayType == .panel {
// Yesterday, tomorrow, etc // Yesterday, tomorrow, etc
if relativeDayPreference.intValue == 0 { if relativeDayPreference.intValue == 0 {
let localFormatter = DateFormatterManager.localizedSimpleFormatter("EEEE") let localFormatter = DateFormatterManager.localizedSimpleFormatter("EEEE")

2
Clocker/Panel/ParentPanelController.swift

@ -563,7 +563,7 @@ class ParentPanelController: NSWindowController {
cellView.time.stringValue = dataOperation.time(with: futureSliderValue) cellView.time.stringValue = dataOperation.time(with: futureSliderValue)
cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue) cellView.sunriseSetTime.stringValue = dataOperation.formattedSunriseTime(with: futureSliderValue)
cellView.sunriseSetTime.lineBreakMode = .byClipping cellView.sunriseSetTime.lineBreakMode = .byClipping
cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panelDisplay) cellView.relativeDate.stringValue = dataOperation.date(with: futureSliderValue, displayType: .panel)
cellView.currentLocationIndicator.isHidden = !model.isSystemTimezone cellView.currentLocationIndicator.isHidden = !model.isSystemTimezone
cellView.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() cellView.sunriseImage.image = model.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage()
if let note = model.note, !note.isEmpty { if let note = model.note, !note.isEmpty {

2
Clocker/Panel/UI/TimezoneDataSource.swift

@ -54,7 +54,7 @@ extension TimezoneDataSource: NSTableViewDataSource, NSTableViewDelegate {
cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: sliderValue) cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: sliderValue)
cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage()
cellView.relativeDate.stringValue = operation.date(with: sliderValue, displayType: .panelDisplay) cellView.relativeDate.stringValue = operation.date(with: sliderValue, displayType: .panel)
cellView.rowNumber = row cellView.rowNumber = row
cellView.customName.stringValue = currentModel.formattedTimezoneLabel() cellView.customName.stringValue = currentModel.formattedTimezoneLabel()
cellView.time.stringValue = operation.time(with: sliderValue) cellView.time.stringValue = operation.time(with: sliderValue)

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -371,7 +371,7 @@ extension AppearanceViewController: NSTableViewDataSource, NSTableViewDelegate {
cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: 0) cellView.sunriseSetTime.stringValue = operation.formattedSunriseTime(with: 0)
cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage() cellView.sunriseImage.image = currentModel.isSunriseOrSunset ? Themer.shared().sunriseImage() : Themer.shared().sunsetImage()
cellView.relativeDate.stringValue = operation.date(with: 0, displayType: .panelDisplay) cellView.relativeDate.stringValue = operation.date(with: 0, displayType: .panel)
cellView.rowNumber = row cellView.rowNumber = row
cellView.customName.stringValue = currentModel.formattedTimezoneLabel() cellView.customName.stringValue = currentModel.formattedTimezoneLabel()
cellView.time.stringValue = operation.time(with: 0) cellView.time.stringValue = operation.time(with: 0)

Loading…
Cancel
Save