Created
September 26, 2016 09:06
-
-
Save Cellane/70c2afc3abf628043d67d40d4c5375c1 to your computer and use it in GitHub Desktop.
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
// | |
// ELLanguageRunner.h | |
// DiorHUB | |
// | |
// Created by Milan Vít on 26.09.16. | |
// Copyright (c) 2016 EYELEVEL. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface ELLanguageRunner : NSObject | |
- (instancetype)initWithTimeInterval:(NSTimeInterval)interval; | |
@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
// | |
// ELLanguageRunner.m | |
// DiorHUB | |
// | |
// Created by Milan Vít on 26.09.16. | |
// Copyright (c) 2016 EYELEVEL. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <libextobjc/extobjc.h> | |
#import "ELLanguageRunner.h" | |
#import "ELLanguageRealm.h" | |
#import "ELSettingRealm.h" | |
@interface ELLanguageRunner () | |
@property (assign, nonatomic) NSTimeInterval interval; | |
@end | |
@implementation ELLanguageRunner | |
#pragma mark - Init | |
- (instancetype)initWithTimeInterval:(NSTimeInterval)interval { | |
self = [super init]; | |
if (self) { | |
self.interval = interval; | |
[self cycleWithRemainingLanguageCodes:nil]; | |
} | |
return self; | |
} | |
- (void)cycleWithRemainingLanguageCodes:(NSArray<NSString *> *)languageCodes { | |
if (languageCodes && languageCodes.count == 0) { | |
// Naturally ending cycle | |
return; | |
} | |
languageCodes = languageCodes ?: [ELLanguageRealm languageCodes]; | |
[ELSettingRealm setCurrentLanguage:languageCodes.firstObject]; | |
@weakify(self); | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (self.interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
@strongify(self); | |
[self cycleWithRemainingLanguageCodes:[languageCodes subarrayWithRange:NSMakeRange(1, languageCodes.count - 1)]]; | |
}); | |
} | |
@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
// | |
// ELLanguageRunnerManager.h | |
// DiorHUB | |
// | |
// Created by Milan Vít on 26.09.16. | |
// Copyright (c) 2016 EYELEVEL. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface ELLanguageRunnerManager : NSObject | |
+ (instancetype)sharedManager; | |
- (void)runWithTimeInterval:(NSTimeInterval)interval; | |
@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
// | |
// ELLanguageRunnerManager.m | |
// DiorHUB | |
// | |
// Created by Milan Vít on 26.09.16. | |
// Copyright (c) 2016 EYELEVEL. All rights reserved. | |
// | |
#import "ELLanguageRunnerManager.h" | |
#import "ELLanguageRunner.h" | |
@interface ELLanguageRunnerManager () | |
@property (strong, nonatomic) ELLanguageRunner *runner; | |
@end | |
@implementation ELLanguageRunnerManager | |
#pragma mark - Init | |
+ (instancetype)sharedManager { | |
static ELLanguageRunnerManager *sharedManager = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedManager = [[self alloc] init]; | |
}); | |
return sharedManager; | |
} | |
#pragma mark - ELLanguageRunnerManager | |
- (void)runWithTimeInterval:(NSTimeInterval)interval { | |
self.runner = nil; | |
self.runner = [[ELLanguageRunner alloc] initWithTimeInterval:interval]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment