This repository has been archived by the owner on Apr 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathABVolumeHUDVisibilityManager.m
72 lines (59 loc) · 1.89 KB
/
ABVolumeHUDVisibilityManager.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// ABVolumeHUDVisibilityManager.m
// Ultrasound
//
// Created by Ayden Panhuyzen on 8/27/18.
// Copyright © 2018 Ayden Panhuyzen. All rights reserved.
//
#import "ABVolumeHUDVisibilityManager.h"
#import "ABVolumeHUDViewSettings.h"
@implementation ABVolumeHUDVisibilityManager {
NSMutableSet <NSString *>*prolongedDisplayRequests;
NSTimer *hideTimer;
BOOL _visible;
}
- (void)showVolumeHUD {
NSLog(@"Visibility manager instructed to show volume HUD.");
[self changeVisibleTo:YES];
[self evaluateTimerStart];
}
- (void)restartIdleTimer {
if (!_visible) return;
[self showVolumeHUD];
}
- (void)hideImmediatelyIfPossible {
if (!_visible) return;
[self attemptToHide];
}
- (void)prolongDisplayForReason:(NSString *)reason {
NSLog(@"Visibility manager asked to prolong display for reason: %@", reason);
[self stopTimerIfActive];
[prolongedDisplayRequests addObject:reason];
}
- (void)releaseProlongedDisplayForReason:(NSString *)reason {
NSLog(@"Visibility manager asked to release prolonged display for reason: %@", reason);
[prolongedDisplayRequests removeObject:reason];
[self evaluateTimerStart];
}
- (void)evaluateTimerStart {
[self stopTimerIfActive];
if (prolongedDisplayRequests.count > 0) return;
hideTimer = [NSTimer scheduledTimerWithTimeInterval:[ABVolumeHUDViewSettings sharedSettings].timeout target:self selector:@selector(tick) userInfo:nil repeats:NO];
}
- (void)stopTimerIfActive {
if (hideTimer) [hideTimer invalidate];
hideTimer = nil;
}
- (void)changeVisibleTo:(BOOL)visible {
_visible = visible;
if (!self.delegate) return;
[self.delegate shouldChangeVolumeHUDVisibleTo:visible];
}
- (void)attemptToHide {
if (prolongedDisplayRequests.count > 0) return;
[self changeVisibleTo:NO];
}
- (void)tick {
[self attemptToHide];
}
@end