Skip to content

Commit

Permalink
Some style edits:
Browse files Browse the repository at this point in the history
- Added braces to oneliner ifs.
- Replaced weird negative if check with "== NO" instead.
- Whitespace edits.
  • Loading branch information
superjohan committed Nov 8, 2015
1 parent 9078442 commit ffd41d0
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Classes/AbstractCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ - (void)animateToPoint:(CGPoint)point withDuration:(NSTimeInterval)duration

- (void)moveCircleWithDelta:(NSTimeInterval)delta
{
if ( ! self.animating)
if (self.animating == NO)
{
return;
}

self.currentTime += delta;

Expand Down
1 change: 1 addition & 0 deletions Classes/Circle.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (id)initWithFrame:(CGRect)frame
self.savedCenter = self.center;
self.savedFrame = frame;
}

return self;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/CircloAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @implementation CircloAppDelegate

- (void)_createUserDefaults
{
if ( ! [[NSUserDefaults standardUserDefaults] boolForKey:kCircloUserDefaultsAppHasLaunchedBefore])
if ([[NSUserDefaults standardUserDefaults] boolForKey:kCircloUserDefaultsAppHasLaunchedBefore] == NO)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kCircloUserDefaultsAppHasLaunchedBefore];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kCircloUserDefaultsSoundEnabled];
Expand Down
31 changes: 29 additions & 2 deletions Classes/CircloViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,29 @@ @implementation CircloViewController
- (NSString *)_buttonTextForTag:(NSInteger)tag
{
if (tag < kMaxHoursTag)
{
return [NSString stringWithFormat:@"%ld", kMaxHoursTag - tag];
}

if (tag == kAMTag)
{
return NSLocalizedString(@"AM", nil);
}

if (tag == kPMTag)
{
return NSLocalizedString(@"PM", nil);
}

return [NSString stringWithFormat:@"%ld", tag];
}

- (void)_layoutHours:(NSInteger)hrs
{
if (self.hours == hrs)
{
return;
}

BOOL afternoon = NO;
if (hrs == 0)
Expand All @@ -65,17 +73,23 @@ - (void)_layoutHours:(NSInteger)hrs
afternoon = YES;

if (hrs > 12)
{
hrs = hrs - 12;
}
}

for (NSInteger i = 1; i < kMaxHoursTag; i++)
{
PulseCircleView *circ = (PulseCircleView *)[self.view viewWithTag:kMaxHoursTag - i];

if (i <= hrs)
{
[circ show];
}
else
{
[circ hide];
}
}

PulseCircleView *amCircle = (PulseCircleView *)[self.view viewWithTag:kAMTag];
Expand All @@ -97,7 +111,9 @@ - (void)_layoutHours:(NSInteger)hrs
- (void)_layoutMinutes:(NSInteger)mins
{
if (self.minutes == mins)
{
return;
}

NSInteger rightNumber = mins % 10;
NSInteger leftNumber = (mins - rightNumber) / 10;
Expand Down Expand Up @@ -132,9 +148,13 @@ - (void)_layoutMinutes:(NSInteger)mins
else
{
if (i <= rightNumber - 1)
{
[circ show];
}
else
{
[circ hide];
}
}
}

Expand Down Expand Up @@ -169,7 +189,9 @@ - (void)_updateClock:(NSTimer *)timer
- (void)_startTimer
{
if (self.timer)
{
return;
}

[UIApplication sharedApplication].idleTimerDisabled = YES;

Expand Down Expand Up @@ -227,13 +249,19 @@ - (void)_fadeOutStartupImage
__block UIImageView *startupImageView = nil;

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
startupImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-Portrait"]];
}
else
{
if (self.view.frame.size.height > 480.0)
{
startupImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-568h"]];
}
else
{
startupImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default"]];
}
}

startupImageView.frame = CGRectMake(0, 0, startupImageView.image.size.width, startupImageView.image.size.height);
Expand Down Expand Up @@ -303,8 +331,7 @@ - (void)viewDidLoad

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

- (void)dealloc
Expand Down
4 changes: 4 additions & 0 deletions Classes/ColorSchemeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ + (ColorScheme *)getSavedColorScheme
CircloColorSchemeType schemeType = [[NSUserDefaults standardUserDefaults] integerForKey:kCircloUserDefaultsColorScheme];

if (schemeType == CircloColorSchemeNone || schemeType >= CircloColorSchemeMax)
{
return [[self class] changeToColorScheme:CircloColorScheme1];
}
else
{
return [[ColorScheme alloc] initWithColorScheme:schemeType];
}
}

@end
8 changes: 8 additions & 0 deletions Classes/LayoutManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ + (void)createClockLayoutInView:(UIView *)view
CGFloat circleSize = 0;

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
circleSize = iPadCircleSize;
}
else
{
circleSize = iPhoneCircleSize;
}

CGFloat xPadding = (view.bounds.size.width - (5 * circleSize)) / 2.0;
CGFloat yPadding = (view.bounds.size.height - (6 * circleSize)) / 2.0;
Expand Down Expand Up @@ -98,9 +102,13 @@ + (void)createUnanimatedCircleLayoutInView:(UIView *)view
CGFloat circleSize = 0;

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
circleSize = iPadCircleSize;
}
else
{
circleSize = iPhoneCircleSize;
}

for (NSInteger i = 0; i < 10; i++)
{
Expand Down
8 changes: 8 additions & 0 deletions Classes/MenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ @implementation MenuView
- (void)_overlayButtonTouched:(id)sender
{
if ([self.delegate respondsToSelector:@selector(overlayButtonTouchedInMenuView:)])
{
[self.delegate overlayButtonTouchedInMenuView:self];
}
}

- (void)_setSoundSelection
Expand Down Expand Up @@ -59,9 +61,13 @@ - (void)_setColorScheme:(ColorScheme *)scheme
PulseCircleView *circle = (PulseCircleView *)[self viewWithTag:i];

if (i == scheme.colorSchemeType)
{
circle.selected = YES;
}
else
{
circle.selected = NO;
}
}

[self _setSoundSelection];
Expand All @@ -74,7 +80,9 @@ - (void)touchUpInCircleView:(PulseCircleView *)circleView
if (circleView.tag > 0 && circleView.tag < 6)
{
if ([self.delegate respondsToSelector:@selector(menuView:changedToColorScheme:)])
{
[self _setColorScheme:[self.delegate menuView:self changedToColorScheme:circleView.tag]];
}
}

if (circleView.tag == kSoundCircleTag)
Expand Down
18 changes: 17 additions & 1 deletion Classes/PulseCircleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ - (void)_performAnimation
- (void)_touchUpInside
{
if ([self.delegate respondsToSelector:@selector(touchUpInCircleView:)])
{
[self.delegate touchUpInCircleView:self];
}

[self startAnimation];
}
Expand Down Expand Up @@ -143,7 +145,9 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)titleText button:(BOOL)butto
[self addSubview:self.button];

if (titleText)
{
[self.button setTitle:titleText forState:UIControlStateNormal];
}
}

self.opaque = NO;
Expand All @@ -160,10 +164,14 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)titleText button:(BOOL)butto
- (void)startAnimation
{
if (self.timer || self.circleHidden)
{
return;
}

if (self.frequency < 0.001)
{
self.frequency = kDefaultFrequency;
}

[self _performAnimation];

Expand All @@ -174,7 +182,9 @@ - (void)startAnimation
- (void)stopAnimation
{
if (self.circleHidden)
{
return;
}

if (self.timer)
{
Expand All @@ -186,7 +196,9 @@ - (void)stopAnimation
- (void)hide
{
if (self.circleHidden)
{
return;
}

[self stopAnimation];
[self _performHide];
Expand All @@ -196,8 +208,10 @@ - (void)hide

- (void)show
{
if ( ! self.circleHidden)
if (self.circleHidden == NO)
{
return;
}

[self _forceCircleDisplay];
[self _performShow];
Expand All @@ -208,7 +222,9 @@ - (void)show
- (void)resetImmediately
{
if (self.circleHidden)
{
return;
}

[self stopAnimation];

Expand Down
14 changes: 11 additions & 3 deletions Classes/ReactiveCircleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ - (double)_distanceFromPoint:(CGPoint)originPoint toPoint:(CGPoint)destinationPo
double b = destinationPoint.y - originPoint.y;
double c = sqrt(pow(a, 2) + pow(b, 2));

if (c == 0)
if (c == 0)
{
return 0.00001; // this is only to prevent a division by zero
}

return c;
}
Expand All @@ -50,11 +52,13 @@ - (void)_moveCircle:(AbstractCircle *)circle inReactionToPoint:(CGPoint)point
CGPoint newPoint = CGPointMake(x, y);

if (fabs(newPoint.x - circle.center.x) < 0.000001 && fabs(newPoint.y - circle.center.y) < 0.000001)
{
return;
}

circle.center = newPoint;

if ( ! [circle isKindOfClass:[PulseCircleView class]])
if ([circle isKindOfClass:[PulseCircleView class]] == NO)
{
CGFloat sizeRatio = (distance / maxDistance) < 1 ? (distance / maxDistance) : 1;

Expand All @@ -65,12 +69,16 @@ - (void)_moveCircle:(AbstractCircle *)circle inReactionToPoint:(CGPoint)point
- (void)_returnCircleToNormal:(AbstractCircle *)circle
{
if (fabs(circle.savedCenter.x - circle.center.x) < 0.000001 && fabs(circle.savedCenter.y - circle.center.y) < 0.000001)
{
return;
}

circle.center = circle.savedCenter;

if ( ! [circle isKindOfClass:[PulseCircleView class]])
if ([circle isKindOfClass:[PulseCircleView class]] == NO)
{
circle.frame = CGRectMake(circle.savedFrame.origin.x, circle.savedFrame.origin.y, circle.savedFrame.size.width, circle.savedFrame.size.height);
}
}

- (void)_moveCirclesInReactionToPoint:(CGPoint)point
Expand Down
8 changes: 8 additions & 0 deletions Classes/SoundManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ + (void)loadSounds
+ (void)playSound:(CircloSoundType)soundType number:(NSInteger)number
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:kCircloUserDefaultsSoundEnabled])
{
[[SimpleAudioEngine sharedEngine] playEffect:[NSString stringWithFormat:@"%ld-%ld.caf", soundType, number]];
}
}

+ (void)toggleSound
Expand All @@ -81,15 +83,21 @@ + (BOOL)soundOn
+ (void)playBackgroundSound
{
if ([[self class] soundOn])
{
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"bg.m4a" loop:YES];
}
else
{
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
}
}

+ (void)updateBackgroundMusicVolumeWithHours:(NSInteger)hours minutes:(NSInteger)minutes
{
if (hours > 12)
{
hours = hours - 12;
}

double firstDecimal = (double)hours / 12.0;
double secondDecimal = (hours < 12) ? ((double)minutes / 60.0) / 10.0 : 0;
Expand Down

0 comments on commit ffd41d0

Please sign in to comment.