From ee9dd344b58ec6fb189211b6788c60d6e7f471a6 Mon Sep 17 00:00:00 2001 From: Nikolas Mayr Date: Sat, 22 Jan 2022 09:06:54 +0100 Subject: [PATCH 1/2] showing duration left and end time right --- AppController.h | 3 ++- AppController.m | 5 ++-- Base.lproj/MainMenu.xib | 23 +++++++++++++----- SCDurationSlider.h | 12 ++++++---- SCDurationSlider.m | 52 +++++++++++++++++++++++++++++++++++++---- TimerWindowController.m | 2 +- 6 files changed, 78 insertions(+), 19 deletions(-) diff --git a/AppController.h b/AppController.h index b613d7cf..6a073d25 100755 --- a/AppController.h +++ b/AppController.h @@ -36,7 +36,8 @@ // to handle command flow and acts as delegate for the initial window. @interface AppController : NSObject { IBOutlet SCDurationSlider* blockDurationSlider_; - IBOutlet NSTextField* blockSliderTimeDisplayLabel_; + IBOutlet NSTextField* blockSliderTimeDurationDisplayLabel_; + IBOutlet NSTextField* blockSliderTimeEndDisplayLabel_; IBOutlet NSTextField* blocklistTeaserLabel_; IBOutlet NSButton* submitButton_; IBOutlet NSWindow* initialWindow_; diff --git a/AppController.m b/AppController.m index 242bdabf..ce1e6aa0 100755 --- a/AppController.m +++ b/AppController.m @@ -73,7 +73,8 @@ - (IBAction)updateTimeSliderDisplay:(id)sender { numMinutes = [defaults_ integerForKey: @"BlockDuration"]; } - blockSliderTimeDisplayLabel_.stringValue = blockDurationSlider_.durationDescription; + blockSliderTimeDurationDisplayLabel_.stringValue = blockDurationSlider_.timeDurationDescription; + blockSliderTimeEndDisplayLabel_.stringValue = blockDurationSlider_.timeEndDescription; [submitButton_ setEnabled: (numMinutes > 0) && ([[defaults_ arrayForKey: @"Blocklist"] count] > 0)]; } @@ -144,7 +145,7 @@ - (BOOL)showLongBlockWarningsIfNecessary { NSAlert* alert = [[NSAlert alloc] init]; alert.messageText = NSLocalizedString(@"That's a long block!", "Long block warning title"); - alert.informativeText = [NSString stringWithFormat: NSLocalizedString(@"Remember that once you start the block, you can't turn it back off until the timer expires in %@ - even if you accidentally blocked a site you need. Consider starting a shorter block first, to test your list and make sure everything's working properly.", @"Long block warning message"), [SCDurationSlider timeSliderDisplayStringFromNumberOfMinutes: blockDuration]]; + alert.informativeText = [NSString stringWithFormat: NSLocalizedString(@"Remember that once you start the block, you can't turn it back off until the timer expires in %@ - even if you accidentally blocked a site you need. Consider starting a shorter block first, to test your list and make sure everything's working properly.", @"Long block warning message"), [SCDurationSlider timeSliderDurationDisplayStringFromNumberOfMinutes: blockDuration]]; [alert addButtonWithTitle: NSLocalizedString(@"Cancel", @"Button to cancel a long block")]; [alert addButtonWithTitle: NSLocalizedString(@"Start Block Anyway", "Button to start a long block despite warnings")]; alert.showsSuppressionButton = YES; diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 9acd0eda..feed3ea3 100755 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -295,8 +295,16 @@ DQ - - + + + + + + + + + + @@ -305,19 +313,21 @@ DQ + + + + - - - + @@ -328,7 +338,8 @@ DQ - + + diff --git a/SCDurationSlider.h b/SCDurationSlider.h index 4dc34a00..1517241d 100644 --- a/SCDurationSlider.h +++ b/SCDurationSlider.h @@ -13,14 +13,18 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) NSInteger maxDuration; @property (readonly) NSInteger durationValueMinutes; -@property (readonly) NSString* durationDescription; +@property (readonly) NSString* timeDurationDescription; +@property (readonly) NSString* timeEndDescription; - (NSInteger)durationValueMinutes; - (void)bindDurationToObject:(id)obj keyPath:(NSString*)keyPath; -- (NSString*)durationDescription; +- (NSString*)timeDurationDescription; +- (NSString*)timeEndDescription; -+ (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds; -+ (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes; ++ (NSString *)timeSliderDurationDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds; ++ (NSString *)timeSliderEndDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds; ++ (NSString *)timeSliderDurationDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes; ++ (NSString *)timeSliderEndDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes; @end diff --git a/SCDurationSlider.m b/SCDurationSlider.m index 25e75376..d4c45256 100644 --- a/SCDurationSlider.m +++ b/SCDurationSlider.m @@ -72,13 +72,17 @@ - (void)bindDurationToObject:(id)obj keyPath:(NSString*)keyPath { }]; } -- (NSString*)durationDescription { - return [SCDurationSlider timeSliderDisplayStringFromNumberOfMinutes: self.durationValueMinutes]; +- (NSString*)timeDurationDescription { + return [SCDurationSlider timeSliderDurationDisplayStringFromNumberOfMinutes: self.durationValueMinutes]; +} + +- (NSString*)timeEndDescription { + return [SCDurationSlider timeSliderEndDisplayStringFromNumberOfMinutes: self.durationValueMinutes]; } // String conversion utility methods -+ (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds { ++ (NSString *)timeSliderDurationDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds { static SCTimeIntervalFormatter* formatter = nil; if (formatter == nil) { formatter = [[SCTimeIntervalFormatter alloc] init]; @@ -88,7 +92,45 @@ + (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSe return formatted; } -+ (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes { ++ (NSString *)timeSliderEndDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds { + static NSDateFormatter* formatter = nil; + if (formatter == nil) { + formatter = [[NSDateFormatter alloc] init]; + } + formatter.timeStyle = NSDateFormatterNoStyle; + formatter.dateStyle = NSDateFormatterShortStyle; + NSString* todayDateStr = [formatter stringFromDate: [NSDate date]]; + NSDate* targetDate = [NSDate dateWithTimeIntervalSinceNow:numberOfSeconds]; + NSString* targetDateStr = [formatter stringFromDate: targetDate]; + + formatter.timeStyle = NSDateFormatterShortStyle; + formatter.dateStyle = [targetDateStr isEqual:todayDateStr] ? NSDateFormatterNoStyle : NSDateFormatterShortStyle; + + NSString* formatted = [formatter stringForObjectValue:targetDate]; + return formatted; +} + ++ (NSString *)timeSliderDurationDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes { + if (numberOfMinutes < 0) return @"Invalid duration"; + + static NSCalendar* gregorian = nil; + if (gregorian == nil) { + gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; + } + + NSRange secondsRangePerMinute = [gregorian + rangeOfUnit:NSCalendarUnitSecond + inUnit:NSCalendarUnitMinute + forDate:[NSDate date]]; + NSInteger numberOfSecondsPerMinute = (NSInteger)NSMaxRange(secondsRangePerMinute); + + NSTimeInterval numberOfSecondsSelected = (NSTimeInterval)(numberOfSecondsPerMinute * numberOfMinutes); + + NSString* displayString = [SCDurationSlider timeSliderDurationDisplayStringFromTimeInterval:numberOfSecondsSelected]; + return displayString; +} + ++ (NSString *)timeSliderEndDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes { if (numberOfMinutes < 0) return @"Invalid duration"; static NSCalendar* gregorian = nil; @@ -104,7 +146,7 @@ + (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinu NSTimeInterval numberOfSecondsSelected = (NSTimeInterval)(numberOfSecondsPerMinute * numberOfMinutes); - NSString* displayString = [SCDurationSlider timeSliderDisplayStringFromTimeInterval:numberOfSecondsSelected]; + NSString* displayString = [SCDurationSlider timeSliderEndDisplayStringFromTimeInterval:numberOfSecondsSelected]; return displayString; } diff --git a/TimerWindowController.m b/TimerWindowController.m index 03fcb6c2..32c07f05 100755 --- a/TimerWindowController.m +++ b/TimerWindowController.m @@ -272,7 +272,7 @@ - (IBAction)updateExtendSliderDisplay:(id)sender { extendDurationSlider_.integerValue = extendDurationSlider_.maxDuration; } - extendDurationLabel_.stringValue = extendDurationSlider_.durationDescription; + extendDurationLabel_.stringValue = extendDurationSlider_.timeDurationDescription; } - (IBAction) closeAddSheet:(id)sender { From 4e66039404c39387a5e07668d2196f40f92fa7fc Mon Sep 17 00:00:00 2001 From: Nikolas Mayr Date: Sat, 22 Jan 2022 09:09:40 +0100 Subject: [PATCH 2/2] fixed indentation to old style --- AppController.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AppController.h b/AppController.h index 6a073d25..45121f63 100755 --- a/AppController.h +++ b/AppController.h @@ -36,21 +36,21 @@ // to handle command flow and acts as delegate for the initial window. @interface AppController : NSObject { IBOutlet SCDurationSlider* blockDurationSlider_; - IBOutlet NSTextField* blockSliderTimeDurationDisplayLabel_; - IBOutlet NSTextField* blockSliderTimeEndDisplayLabel_; - IBOutlet NSTextField* blocklistTeaserLabel_; + IBOutlet NSTextField* blockSliderTimeDurationDisplayLabel_; + IBOutlet NSTextField* blockSliderTimeEndDisplayLabel_; + IBOutlet NSTextField* blocklistTeaserLabel_; IBOutlet NSButton* submitButton_; IBOutlet NSWindow* initialWindow_; IBOutlet NSMenuItem* domainListMenuItem_; - IBOutlet NSMenuItem* editBlocklistMenuItem_; - + IBOutlet NSMenuItem* editBlocklistMenuItem_; + IBOutlet NSButton* editBlocklistButton_; IBOutlet DomainListWindowController* domainListWindowController_; IBOutlet TimerWindowController* timerWindowController_; NSWindowController* preferencesWindowController_; NSUserDefaults* defaults_; - SCSettings* settings_; + SCSettings* settings_; NSLock* refreshUILock_; BOOL blockIsOn; BOOL addingBlock;