-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into bugfix/fix-an-collection-controller-tests
* develop: iOS-69-add-timeout-validator: added timeout validator for ANTableController & ANCollectionController # Conflicts: # Example/Alister-Example.xcodeproj/project.pbxproj
- Loading branch information
Showing
7 changed files
with
750 additions
and
554 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Alister/ANActionTimeoutValidator/ANActionTimeOutValidator.h
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// ADActionTimeoutValidator.h | ||
// ANODA | ||
// | ||
// Created by ANODA on 3/18/16. | ||
// Copyright © 2016 ANODA. All rights reserved. | ||
// | ||
|
||
typedef void (^ANCodeBlock)(void); | ||
|
||
@interface ANActionTimeOutValidator : NSObject | ||
|
||
/** | ||
* custom init with delay. | ||
* | ||
* @param delay delay in seconds | ||
* | ||
* @return ADActionTimeoutValidator instance | ||
*/ | ||
- (instancetype)initWithTimeoutDelay:(CGFloat)delay; | ||
|
||
/** | ||
* check is action enabled. | ||
* | ||
* @return return bool value, that meaning is time delay expired or not. | ||
*/ | ||
|
||
- (BOOL)isActionEnabled; | ||
|
||
|
||
/** | ||
* reset current time delay | ||
*/ | ||
- (void)reset; | ||
|
||
/** | ||
* required method for user timeout validator | ||
* | ||
* @param delay delay in seconds | ||
* @param completion block that execute when action enabled | ||
* @param skipBlock block that execute when action disabled, time delay has not expired | ||
*/ | ||
- (void)handleTimeoutWithDelayInSeconds:(CGFloat)delay | ||
completion:(ANCodeBlock)completion | ||
skipBlock:(ANCodeBlock)skipBlock; | ||
|
||
@end |
81 changes: 81 additions & 0 deletions
81
Alister/ANActionTimeoutValidator/ANActionTimeOutValidator.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// ADActionTimeoutValidator.m | ||
// ANODA | ||
// | ||
// Created by ANODA on 3/18/16. | ||
// Copyright © 2016 ANODA. All rights reserved. | ||
// | ||
|
||
#import "ANActionTimeOutValidator.h" | ||
|
||
static CGFloat const kADActionTimeOutValidatorDefaultDelay = 1; | ||
|
||
@interface ANActionTimeOutValidator () | ||
|
||
@property (nonatomic, assign) CGFloat delay; | ||
@property (nonatomic, strong) NSDate *initialDate; | ||
@property (nonatomic, assign) BOOL isFirstRequest; | ||
|
||
@end | ||
|
||
@implementation ANActionTimeOutValidator | ||
|
||
- (instancetype)init | ||
{ | ||
return [self initWithTimeoutDelay:kADActionTimeOutValidatorDefaultDelay]; | ||
} | ||
|
||
- (instancetype)initWithTimeoutDelay:(CGFloat)delay | ||
{ | ||
self = [super init]; | ||
{ | ||
self.delay = delay; | ||
self.initialDate = [NSDate date]; | ||
self.isFirstRequest = YES; | ||
} | ||
return self; | ||
} | ||
|
||
- (BOOL)isActionEnabled | ||
{ | ||
NSTimeInterval timeInterval = [self.initialDate timeIntervalSinceDate:[NSDate date]]; | ||
CGFloat value = fabs(timeInterval); | ||
BOOL isEnabled = (value > self.delay); | ||
if (isEnabled) | ||
{ | ||
self.initialDate = [NSDate date]; | ||
} | ||
return isEnabled; | ||
} | ||
|
||
- (void)reset | ||
{ | ||
self.initialDate = [[NSDate alloc] initWithTimeIntervalSince1970:1000]; | ||
} | ||
|
||
- (void)handleTimeoutWithDelayInSeconds:(CGFloat)delay completion:(ANCodeBlock)completion skipBlock:(ANCodeBlock)skipBlock | ||
{ | ||
self.delay = delay; | ||
if (self.isFirstRequest) | ||
{ | ||
self.initialDate = [NSDate date]; | ||
self.isFirstRequest = NO; | ||
if (completion) | ||
{ | ||
completion(); | ||
} | ||
} | ||
else | ||
{ | ||
if ([self isActionEnabled] && completion) | ||
{ | ||
completion(); | ||
} | ||
else if (skipBlock) | ||
{ | ||
skipBlock(); | ||
} | ||
} | ||
} | ||
|
||
@end |
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
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
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
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
Oops, something went wrong.