From 2e80813e1699a1b2a84a60d72ae21b957f3216b4 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia Date: Fri, 13 Jan 2017 15:40:50 -0500 Subject: [PATCH] Review Stack View Code Additions --- Clocker/CLParentPanelController.h | 10 ++ Clocker/CLParentPanelController.m | 167 +++++++++++++++++++++++++++--- 2 files changed, 165 insertions(+), 12 deletions(-) diff --git a/Clocker/CLParentPanelController.h b/Clocker/CLParentPanelController.h index aa96c88..40f860f 100644 --- a/Clocker/CLParentPanelController.h +++ b/Clocker/CLParentPanelController.h @@ -8,6 +8,7 @@ #import #import "CLOneWindowController.h" +#import "CLAppFeedbackWindowController.h" @interface CLParentPanelController : NSWindowController @@ -17,6 +18,9 @@ @property (nonatomic, assign) NSInteger futureSliderValue; @property (nonatomic) BOOL showReviewCell; +@property (weak) IBOutlet NSStackView *stackView; +@property (weak) IBOutlet NSView *reviewView; +@property (weak) IBOutlet NSView *futureSliderView; @property (weak) IBOutlet NSButton *shutdownButton; @property (weak) IBOutlet NSButton *preferencesButton; @property (weak) IBOutlet NSSlider *futureSlider; @@ -24,6 +28,12 @@ @property (weak) IBOutlet NSLayoutConstraint *scrollViewHeight; @property (nonatomic, strong) CLOneWindowController *oneWindow; +@property (weak, nonatomic) IBOutlet NSImageView *imageView; +@property (weak, nonatomic) IBOutlet NSTextField *leftField; +@property (weak, nonatomic) IBOutlet NSButton *leftButton; +@property (weak, nonatomic) IBOutlet NSButton *rightButton; +@property (strong, nonatomic) CLAppFeedbackWindowController *feedbackWindow; + - (void)updateDefaultPreferences; - (void)showOptions:(BOOL)value; - (void)removeContextHelpForSlider; diff --git a/Clocker/CLParentPanelController.m b/Clocker/CLParentPanelController.m index 25abdc5..2c27c87 100644 --- a/Clocker/CLParentPanelController.m +++ b/Clocker/CLParentPanelController.m @@ -7,13 +7,19 @@ // #import "CLParentPanelController.h" -#import "CLRatingCellView.h" #import "CLTimezoneData.h" #import "CommonStrings.h" #import "CLOneWindowController.h" #import +#import "iRate.h" #import "CLTableViewDataSource.h" +NSString *const CLNotReallyButtonTitle = @"Not Really"; +NSString *const CLFeedbackString = @"Mind giving feedback?"; +NSString *const CLNoThanksTitle = @"No, thanks"; +NSString *const CLYesWithQuestionMark = @"Yes?"; +NSString *const CLYesWithExclamation = @"Yes!"; + @interface CLParentPanelController () @property (strong) CLTableViewDataSource *timezoneDataSource; @end @@ -42,7 +48,54 @@ } self.mainTableview.selectionHighlightStyle = NSTableViewSelectionHighlightStyleNone; - + + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:CLDisplayFutureSliderKey options:NSKeyValueObservingOptionNew context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:CLUserFontSizePreference options:NSKeyValueObservingOptionNew context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:CLThemeKey options:NSKeyValueObservingOptionNew context:nil]; + [self updateReviewViewFontColor]; + + self.futureSliderView.wantsLayer = YES; + self.reviewView.wantsLayer = YES; + +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([keyPath isEqualToString:CLDisplayFutureSliderKey]) { + self.futureSlider.hidden = [change[@"new"] isEqualToNumber:@(1)] ? YES : NO; + } + else if([keyPath isEqualToString:CLUserFontSizePreference]) + { + NSNumber *userFontSize = [[NSUserDefaults standardUserDefaults] objectForKey:CLUserFontSizePreference]; + self.scrollViewHeight.constant = self.defaultPreferences.count * (self.mainTableview.rowHeight + userFontSize.integerValue*1.5); + [self.mainTableview reloadData]; + + } + else if([keyPath isEqualToString:CLThemeKey]) + { + [self updateReviewViewFontColor]; + } + else + { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + +- (void)updateReviewViewFontColor +{ + NSNumber *theme = [[NSUserDefaults standardUserDefaults] objectForKey:CLThemeKey]; + if (theme.integerValue == 0) { + self.leftField.textColor = [NSColor blackColor]; + self.futureSliderView.layer.backgroundColor = [NSColor whiteColor].CGColor; + } + else + { + self.futureSliderView.layer.backgroundColor = [NSColor blackColor].CGColor; + self.leftField.textColor = [NSColor whiteColor]; + } } - (void) updateDefaultPreferences @@ -51,25 +104,20 @@ self.defaultPreferences = self.defaultPreferences == nil ? [[NSMutableArray alloc] initWithArray:defaultZones] : [NSMutableArray arrayWithArray:defaultZones]; - self.scrollViewHeight.constant = self.showReviewCell ? - (self.defaultPreferences.count+1)*55+40 : self.defaultPreferences.count*55 + 30; - - NSNumber *displayFutureSlider = [[NSUserDefaults standardUserDefaults] objectForKey:CLDisplayFutureSliderKey]; + NSNumber *userFontSize = [[NSUserDefaults standardUserDefaults] objectForKey:CLUserFontSizePreference]; - /*No Future Slider when no timezones duh*/ - - self.futureSlider.hidden = [displayFutureSlider isEqualToNumber:@1] || (self.defaultPreferences.count == 0) ? YES : NO; + self.scrollViewHeight.constant = self.defaultPreferences.count * (self.mainTableview.rowHeight + userFontSize.integerValue*1.5); [self updatePanelColor]; if (!self.timezoneDataSource) { self.timezoneDataSource = [[CLTableViewDataSource alloc] initWithItems:self.defaultPreferences]; + self.timezoneDataSource.futureSliderValue = self.futureSliderValue; self.mainTableview.dataSource = self.timezoneDataSource; self.mainTableview.delegate = self.timezoneDataSource; } } - - (void)dealloc { self.timezoneDataSource = nil; @@ -81,7 +129,7 @@ if (theme.integerValue == 1) { (self.mainTableview).backgroundColor = [NSColor blackColor]; - self.window.alphaValue = 0.90; + self.window.alphaValue = 1; } else { @@ -131,6 +179,8 @@ [helpManager setContextHelp:attributedString forObject:self.futureSlider]; [helpManager showContextHelpForObject:self.futureSlider locationHint:pointInScreen]; + self.timezoneDataSource.futureSliderValue = self.futureSliderValue; + [self.mainTableview reloadData]; } @@ -186,7 +236,7 @@ - (void)performBoundsAnimationWithOldRect:(CGRect)fromRect andNewRect:(CGRect)newRect andShouldOpenTimezonePanel:(BOOL)shouldOpen { - [self.oneWindow.window setFrame:fromRect display:NO animate:NO]; + [self.oneWindow.window setFrame:fromRect display:NO animate:NO]; self.window.contentView.wantsLayer = YES; POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPWindowFrame]; @@ -208,5 +258,98 @@ [self.mainTableview reloadData]; } +- (IBAction)actionOnNegativeFeedback:(id)sender +{ + NSButton *leftButton = (NSButton *)sender; + + if ([leftButton.title isEqualToString:CLNotReallyButtonTitle]) { + [self setAnimatedStringValue:CLFeedbackString + andTextField:self.leftField + withLeftButtonTitle:CLNoThanksTitle + andRightButtonTitle:CLYesWithQuestionMark]; + } + else + { + [self updateReviewView]; + [[iRate sharedInstance] remindLater]; + } +} + +- (IBAction)actionOnPositiveFeedback:(id)sender +{ + NSButton *rightButton = (NSButton *)sender; + + if ([rightButton.title isEqualToString:CLYesWithExclamation]) { + [self setAnimatedStringValue:@"Mind rating us?" + andTextField:self.leftField + withLeftButtonTitle:CLNoThanksTitle + andRightButtonTitle:@"Yes"]; + } + else if ([rightButton.title isEqualToString:CLYesWithQuestionMark]) + { + [self updateReviewView]; + self.feedbackWindow = [CLAppFeedbackWindowController sharedWindow]; + [self.feedbackWindow showWindow:nil]; + [NSApp activateIgnoringOtherApps:YES]; + } + else + { + [[iRate sharedInstance] rate]; + [self updateReviewView]; + } +} + +- (void)updateReviewView +{ + self.reviewView.hidden = YES; + self.showReviewCell = NO; + self.leftField.stringValue = @"Enjoy using Clocker?"; + self.leftButton.title = @"Not Really"; + self.rightButton.title = @"Yes!"; +} + +- (void) setAnimatedStringValue:(NSString *)aString + andTextField:(NSTextField *)textfield + withLeftButtonTitle:(NSString *)leftTitle + andRightButtonTitle:(NSString *)rightTitle +{ + if ([textfield.stringValue isEqual: aString]) + { + return; + } + + [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { + context.duration = 1.0; + context.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut]; + (self.imageView.animator).alphaValue = 0.0; + (self.leftButton.animator).alphaValue = 0.0; + (self.rightButton.animator).alphaValue = 0.0; + (textfield.animator).alphaValue = 0.0; + } + completionHandler:^{ + textfield.stringValue = aString; + [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { + context.duration = 1.0; + context.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn]; + (self.imageView.animator).alphaValue = 1.0; + (textfield.animator).alphaValue = 1.0; + (self.leftButton.animator).alphaValue = 1.0; + (self.rightButton.animator).alphaValue = 1.0; + if ([self.leftButton.title isEqualToString:@"Not Really"]) { + (self.leftButton.animator).title = CLNoThanksTitle; + } + if ([self.rightButton.title isEqualToString:CLYesWithExclamation]) { + (self.rightButton.animator).title = @"Yes, sure"; + } + + (self.leftButton.animator).title = leftTitle; + (self.rightButton.animator).title = rightTitle; + + } completionHandler: ^{ + }]; + }]; +} + + @end