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.

185 lines
6.4 KiB

9 years ago
//
// CLAppearanceViewController.m
// Clocker
//
// Created by Abhishek Banthia on 12/19/15.
//
//
#import "CLAppearanceViewController.h"
#import "ApplicationDelegate.h"
#import "PanelController.h"
#import "CommonStrings.h"
#import "CLTimezoneData.h"
#import "CLFloatingWindowController.h"
#import <Crashlytics/Crashlytics.h>
9 years ago
typedef NS_ENUM(NSUInteger, CLClockerMode) {
CLMenubarMode = 0,
CLFloatingMode
};
9 years ago
@interface CLAppearanceViewController ()
@property (weak) IBOutlet NSSegmentedControl *timeFormat;
@property (weak) IBOutlet NSSegmentedControl *theme;
@property (weak) IBOutlet NSTextField *informationLabel;
@property (assign, nonatomic) BOOL enableOptions;
9 years ago
@end
@implementation CLAppearanceViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.informationLabel.stringValue = @"Select a favourite timezone to enable menubar display options.";
self.informationLabel.textColor = [NSColor secondaryLabelColor];
self.enableOptions = [[NSUserDefaults standardUserDefaults] objectForKey:@"favouriteTimezone"] == nil ? NO : YES;
9 years ago
}
- (IBAction)timeFormatSelectionChanged:(id)sender
{
NSSegmentedControl *timeFormat = (NSSegmentedControl *)sender;
[[NSUserDefaults standardUserDefaults] setObject:@(timeFormat.selectedSegment) forKey:CL24hourFormatSelectedKey];
9 years ago
[Answers logCustomEventWithName:@"Time Format Selected" customAttributes:@{@"Time Format" : timeFormat.selectedSegment == 0 ? @"12 Hour Format" : @"24 Hour Format"}];
[self refreshMainTableview:YES andUpdateFloatingWindow:YES];
9 years ago
}
- (IBAction)themeChanged:(id)sender
{
NSSegmentedControl *themeSegment = (NSSegmentedControl *)sender;
//Get the current display mode
[self refreshMainTableview:NO andUpdateFloatingWindow:YES];
PanelController *panelController = [PanelController getPanelControllerInstance];
9 years ago
[panelController.backgroundView setNeedsDisplay:YES];
if (themeSegment.selectedSegment == CLBlackTheme) {
panelController.shutdownButton.image = [NSImage imageNamed:@"PowerIcon-White"];
panelController.preferencesButton.image = [NSImage imageNamed:@"Settings-White"];
}
else
{
panelController.shutdownButton.image = [NSImage imageNamed:@"PowerIcon"];
panelController.preferencesButton.image = [NSImage imageNamed:NSImageNameActionTemplate];
}
9 years ago
if (panelController.defaultPreferences.count == 0)
{
[panelController updatePanelColor];
}
[panelController updateTableContent];
[Answers logCustomEventWithName:@"Theme" customAttributes:@{@"themeSelected" : themeSegment.selectedSegment == CLBlackTheme ? @"Black" : @"White"}];
9 years ago
}
- (IBAction)displayModeChanged:(NSSegmentedControl *)modeSegment
{
ApplicationDelegate *sharedDelegate = (ApplicationDelegate*)[NSApplication sharedApplication].delegate;
if (modeSegment.selectedSegment == CLFloatingMode)
{
sharedDelegate.floatingWindow = [CLFloatingWindowController sharedFloatingWindow];
[sharedDelegate.floatingWindow showWindow:nil];
[sharedDelegate.floatingWindow updateDefaultPreferences];
[sharedDelegate.floatingWindow startWindowTimer];
[NSApp activateIgnoringOtherApps:YES];
}
else
{
sharedDelegate.floatingWindow = [CLFloatingWindowController sharedFloatingWindow];
[sharedDelegate.floatingWindow.window close];
[sharedDelegate.panelController updateDefaultPreferences];
}
8 years ago
[Answers logCustomEventWithName:@"Clocker Mode" customAttributes:@{@"displayMode" : modeSegment.selectedSegment == CLFloatingMode ? @"Floating Mode" : @"Menubar Mode"}];
}
- (IBAction)changeRelativeDayDisplay:(NSSegmentedControl *)relativeDayControl
{
NSNumber *selectedIndex = @(relativeDayControl.selectedSegment);
[Answers logCustomEventWithName:@"RelativeDate" customAttributes:@{@"dayPreference" : selectedIndex.integerValue == 0 ? @"Relative Day" : @"Actual Day"}];
9 years ago
[[NSUserDefaults standardUserDefaults] setObject:selectedIndex forKey:CLRelativeDateKey];
[self refreshMainTableview:YES andUpdateFloatingWindow:YES];
9 years ago
}
- (void)refreshMainTableview:(BOOL)panel andUpdateFloatingWindow:(BOOL)value
9 years ago
{
dispatch_async(dispatch_get_main_queue(), ^{
if (panel)
{
ApplicationDelegate *appDelegate = (ApplicationDelegate *)[NSApplication sharedApplication].delegate;
PanelController *panelController = [PanelController getPanelControllerInstance];
[panelController updateDefaultPreferences];
[panelController.futureSlider setNeedsDisplay:YES];
[panelController updateTableContent];
[appDelegate.menubarController setUpTimerForUpdatingMenubar];
}
if (value)
{
//Get the current display mode
NSNumber *displayMode = [[NSUserDefaults standardUserDefaults] objectForKey:CLShowAppInForeground];
if (displayMode.integerValue == CLFloatingMode)
{
CLFloatingWindowController *floatingWindowInstance = [CLFloatingWindowController sharedFloatingWindow];
[floatingWindowInstance updateTableContent];
[floatingWindowInstance.futureSlider setNeedsDisplay:YES];
//Only one instance where we need to update panel color and in that instance we pass panel as NO
if (!panel)
{
[floatingWindowInstance updatePanelColor];
}
}
}
9 years ago
});
}
- (IBAction)showFutureSlider:(id)sender
{
//Get the current display mode
[self refreshMainTableview:NO andUpdateFloatingWindow:YES];
}
- (IBAction)showSunriseSunset:(NSSegmentedControl *)sender {
[Answers logCustomEventWithName:@"Sunrise Sunset" customAttributes:@{@"Is It Displayed" : sender.selectedSegment == 0 ? @"YES" : @"NO"}];
}
- (IBAction)displayTimeWithSeconds:(NSSegmentedControl *)sender {
[Answers logCustomEventWithName:@"Display Time With Seconds" customAttributes:@{@"Displayed" : sender.selectedSegment == 0 ? @"YES" : @"NO"}];
}
- (IBAction)flashTheTimeSeperators:(NSSegmentedControl *)sender {
[Answers logCustomEventWithName:@"Flashing Time Seperators" customAttributes:@{@"Displayed" : sender.selectedSegment == 0 ? @"YES" : @"NO"}];
}
9 years ago
@end