-
-
Save chrisswong/7d93b372f06bd0fa1b0c to your computer and use it in GitHub Desktop.
vo test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// VoiceOverServiceManager.m | |
// testSqq | |
// | |
// Created by chris on 12/1/15. | |
// Copyright (c) 2015 Green Tomato. All rights reserved. | |
// | |
#import "VoiceOverServiceManager.h" | |
@interface VoiceOverServiceManager() | |
@property (nonatomic) NSInteger targetDistance; | |
@property (nonatomic) double halfDistance; | |
@property (nonatomic) NSInteger lastPlayedDistance; | |
@property (nonatomic) BOOL hasPlayHalfWorkout; | |
@property (nonatomic) BOOL hasPlayFullWorkout; | |
@end | |
@implementation VoiceOverServiceManager | |
- (instancetype)initWithTargetWorkOutDistance:(NSNumber *) targetWorkoutDistance | |
{ | |
self = [super init]; | |
if (self) { | |
self.targetDistance = [targetWorkoutDistance integerValue]; | |
self.halfDistance = self.targetDistance * 0.5f; | |
} | |
return self; | |
} | |
- (void) updateRunDistance:(double) runDistance { | |
if (runDistance < 1.0) { | |
return; | |
} | |
NSInteger floorRunDistance = floor(runDistance); | |
if (runDistance >= self.targetDistance && !_hasPlayFullWorkout) { | |
NSLog(@"play full work out vo"); | |
_hasPlayFullWorkout = YES; | |
_lastPlayedDistance = floorRunDistance; | |
} | |
if (runDistance >= self.halfDistance && !_hasPlayHalfWorkout ) { | |
NSLog(@"play half work out vo" ); | |
_hasPlayHalfWorkout = YES; | |
if (self.targetDistance % 2 == 0) { | |
_lastPlayedDistance = floorRunDistance; | |
} | |
} | |
if (floor(runDistance) > _lastPlayedDistance) { | |
NSLog(@"play vo with %ld",(long)floorRunDistance ); | |
_lastPlayedDistance = floorRunDistance; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment