From a491f9bdafe67c344c4cebbb59e26fb6665352b4 Mon Sep 17 00:00:00 2001 From: kenny Date: Sun, 29 May 2016 21:51:25 -0400 Subject: [PATCH 1/2] Time estimator class added --- Phoenix.xcodeproj/project.pbxproj | 6 ++++++ Phoenix/Phoenix.m | 8 ++++++++ Shared Code/KATimeEstimator.h | 17 ++++++++++++++++ Shared Code/KATimeEstimator.m | 33 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 Shared Code/KATimeEstimator.h create mode 100644 Shared Code/KATimeEstimator.m diff --git a/Phoenix.xcodeproj/project.pbxproj b/Phoenix.xcodeproj/project.pbxproj index 71dd8d5..87bee9a 100644 --- a/Phoenix.xcodeproj/project.pbxproj +++ b/Phoenix.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ B9B6A2501C5D422F009205B2 /* Property.m in Sources */ = {isa = PBXBuildFile; fileRef = B9B6A2461C5D422F009205B2 /* Property.m */; }; B9B6A2511C5D422F009205B2 /* PropertyParser.m in Sources */ = {isa = PBXBuildFile; fileRef = B9B6A2481C5D422F009205B2 /* PropertyParser.m */; }; B9B6A26F1C5D42D1009205B2 /* Phoenix.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = B9B6A26E1C5D42D1009205B2 /* Phoenix.xcscheme */; }; + B9F1A9741CFBCF3000F45FC5 /* KATimeEstimator.m in Sources */ = {isa = PBXBuildFile; fileRef = B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -52,6 +53,8 @@ B9B6A2471C5D422F009205B2 /* PropertyParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyParser.h; sourceTree = ""; }; B9B6A2481C5D422F009205B2 /* PropertyParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PropertyParser.m; sourceTree = ""; }; B9B6A26E1C5D42D1009205B2 /* Phoenix.xcscheme */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Phoenix.xcscheme; sourceTree = ""; }; + B9F1A9721CFBCF3000F45FC5 /* KATimeEstimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KATimeEstimator.h; sourceTree = ""; }; + B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KATimeEstimator.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -136,6 +139,8 @@ B9B6A2461C5D422F009205B2 /* Property.m */, B9B6A2471C5D422F009205B2 /* PropertyParser.h */, B9B6A2481C5D422F009205B2 /* PropertyParser.m */, + B9F1A9721CFBCF3000F45FC5 /* KATimeEstimator.h */, + B9F1A9731CFBCF3000F45FC5 /* KATimeEstimator.m */, ); path = "Shared Code"; sourceTree = SOURCE_ROOT; @@ -219,6 +224,7 @@ B9B6A24D1C5D422F009205B2 /* KAWarning+Properties.m in Sources */, B9B6A2191C5D40CC009205B2 /* Phoenix.m in Sources */, B9B6A24B1C5D422F009205B2 /* KAPropertyWarningGenerator.m in Sources */, + B9F1A9741CFBCF3000F45FC5 /* KATimeEstimator.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Phoenix/Phoenix.m b/Phoenix/Phoenix.m index 4bcb96a..ff1de0c 100755 --- a/Phoenix/Phoenix.m +++ b/Phoenix/Phoenix.m @@ -10,6 +10,7 @@ #import "Property.h" #import "PropertyParser.h" #import "KAInitializerWriterFactory.h" +#import "KATimeEstimator.h" @interface Phoenix() @@ -87,9 +88,16 @@ - (void)doMenuAction { NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; [pasteboard clearContents]; [pasteboard writeObjects:@[initializer]]; + + KATimeEstimator *timeEstimator = [[KATimeEstimator alloc] initWithNumberOfProperties:properties.count]; + + const NSInteger seconds = [timeEstimator estimatedSecondsSaved]; + + [[NSUserDefaults standardUserDefaults] setInteger:seconds forKey:@"seconds_saved"]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } + @end diff --git a/Shared Code/KATimeEstimator.h b/Shared Code/KATimeEstimator.h new file mode 100644 index 0000000..b888a9a --- /dev/null +++ b/Shared Code/KATimeEstimator.h @@ -0,0 +1,17 @@ +// +// KATimeEstimator.h +// Phoenix +// +// Created by Kenneth Parker Ackerson on 5/29/16. +// Copyright © 2016 Kenneth Ackerson. All rights reserved. +// + +#import + +@interface KATimeEstimator : NSObject + +- (nonnull instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties; + +- (NSInteger)estimatedSecondsSaved; + +@end diff --git a/Shared Code/KATimeEstimator.m b/Shared Code/KATimeEstimator.m new file mode 100644 index 0000000..54cba89 --- /dev/null +++ b/Shared Code/KATimeEstimator.m @@ -0,0 +1,33 @@ +// +// KATimeEstimator.m +// Phoenix +// +// Created by Kenneth Parker Ackerson on 5/29/16. +// Copyright © 2016 Kenneth Ackerson. All rights reserved. +// + +#import "KATimeEstimator.h" + +@interface KATimeEstimator () + +@property (nonatomic, readonly) NSInteger numberOfProperties; + +@end + +@implementation KATimeEstimator + +- (instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties { + self = [super init]; + + if (self) { + _numberOfProperties = numberOfProperties; + } + + return self; +} + +- (NSInteger)estimatedSecondsSaved { + return self.numberOfProperties * 4; // 4 seconds per property. +} + +@end From f50942b443f1a43380a65ad65e78f89ee9aa4f28 Mon Sep 17 00:00:00 2001 From: kenny Date: Sun, 29 May 2016 22:44:30 -0400 Subject: [PATCH 2/2] updating --- Phoenix/Phoenix.m | 35 ++++++++++++++++++++++++++++++++++- Shared Code/KATimeEstimator.m | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Phoenix/Phoenix.m b/Phoenix/Phoenix.m index ff1de0c..0667cba 100755 --- a/Phoenix/Phoenix.m +++ b/Phoenix/Phoenix.m @@ -67,9 +67,39 @@ - (void)didApplicationFinishLaunchingNotification:(NSNotification *)noti { [actionMenuItem setTarget:self]; [[menuItem submenu] addItem:actionMenuItem]; + + NSMenuItem *secondsActionMenuItem = [[NSMenuItem alloc] initWithTitle:@"Phoenix stats" action:@selector(seconds) keyEquivalent:@""]; + + [secondsActionMenuItem setTarget:self]; + [[menuItem submenu] addItem:secondsActionMenuItem]; } } +- (void)seconds { + NSAlert *alert = [[NSAlert alloc] init]; + + const NSInteger seconds = [[NSUserDefaults standardUserDefaults] integerForKey:@"seconds_saved"]; + + NSString *displayString = [NSString stringWithFormat:@"Time saved: %ld seconds", seconds]; + + // This is super shitty code /shrug + + if (seconds > 60) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f minutes", seconds / 60.0]; + } + + if (seconds > 60 * 60) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f hours", (seconds / 60.0) / 60]; + } + + if (seconds > 60 * 60 * 24) { + displayString = [NSString stringWithFormat:@"Time saved: %0.2f day", ((seconds / 60.0) / 60) / 24]; + } + + [alert setMessageText:displayString]; + [alert runModal]; +} + - (void)doMenuAction { const PropertyParser *parser = [[PropertyParser alloc] initWithString:self.currentlySelectedText]; NSArray *properties = [parser properties]; @@ -91,9 +121,12 @@ - (void)doMenuAction { KATimeEstimator *timeEstimator = [[KATimeEstimator alloc] initWithNumberOfProperties:properties.count]; + const NSInteger currentSeconds = [[NSUserDefaults standardUserDefaults] integerForKey:@"seconds_saved"]; + const NSInteger seconds = [timeEstimator estimatedSecondsSaved]; - [[NSUserDefaults standardUserDefaults] setInteger:seconds forKey:@"seconds_saved"]; + [[NSUserDefaults standardUserDefaults] setInteger:currentSeconds + seconds forKey:@"seconds_saved"]; + [[NSUserDefaults standardUserDefaults] synchronize]; } - (void)dealloc { diff --git a/Shared Code/KATimeEstimator.m b/Shared Code/KATimeEstimator.m index 54cba89..08855d0 100644 --- a/Shared Code/KATimeEstimator.m +++ b/Shared Code/KATimeEstimator.m @@ -27,7 +27,7 @@ - (instancetype)initWithNumberOfProperties:(NSInteger)numberOfProperties { } - (NSInteger)estimatedSecondsSaved { - return self.numberOfProperties * 4; // 4 seconds per property. + return self.numberOfProperties * 4; // 4 seconds per property - probably low, but this is just estimated. } @end