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 pathABVolumeHUDVolumeModeInfo.m
68 lines (55 loc) · 2.11 KB
/
ABVolumeHUDVolumeModeInfo.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
//
// ABVolumeHUDVolumeModeInfo.m
// Ultrasound
//
// Created by Ayden Panhuyzen on 8/27/18.
// Copyright © 2018 Ayden Panhuyzen. All rights reserved.
//
#import "ABVolumeHUDVolumeModeInfo.h"
#import "ABVolumeHUDIconVolumeGlyph.h"
#import "ABVolumeHUDIconRingerGlyph.h"
#import "Headers.h"
#import "NSObject+SafeKVC.h"
@implementation ABVolumeHUDVolumeModeInfo
- (instancetype)initWithVolumeMode:(ABVolumeHUDVolumeMode)mode {
self = [super init];
if (self) _mode = mode;
return self;
}
+ (instancetype)infoForVolumeMode:(ABVolumeHUDVolumeMode)mode {
return [[self alloc] initWithVolumeMode:mode];
}
- (BOOL)allowsUserModificationForVolume:(CGFloat)volume {
return YES;
}
- (BOOL)isRingerMuted {
if ([self mediaController] && [[self mediaController] respondsToSelector:@selector(isRingerMuted)]) return [self mediaController].isRingerMuted;
if ([self ringerControl] && [[self ringerControl] respondsToSelector:@selector(isRingerMuted)]) return [self ringerControl].isRingerMuted;
return NO;
}
- (NSString *)overrideTextForVolume:(CGFloat)volume {
if (_mode == ABVolumeHUDVolumeModeRinger && [self isRingerMuted]) return @"Silent";
return nil;
}
- (CGFloat)iconVolumeForRealVolume:(CGFloat)volume {
if (_mode == ABVolumeHUDVolumeModeRinger && [self isRingerMuted]) return 0;
return volume;
}
- (BOOL)shouldDeemphasizeSliderForVolume:(CGFloat)volume {
return _mode == ABVolumeHUDVolumeModeRinger && [self isRingerMuted];
}
- (UIView<ABVolumeHUDIconGlyphProviding> *)iconGlyphProvider {
if (_mode == ABVolumeHUDVolumeModeRinger) return [[ABVolumeHUDIconRingerGlyph alloc] init];
return [[ABVolumeHUDIconVolumeGlyph alloc] init];
}
- (SBMediaController *)mediaController {
Class mediaControllerClass = NSClassFromString(@"SBMediaController");
if (!mediaControllerClass) return nil;
return [mediaControllerClass sharedInstance];
}
- (SBRingerControl *)ringerControl {
SBMainWorkspace *workspace = [NSClassFromString(@"SBMainWorkspace") sharedInstance];
if (![workspace respondsToSelector:@selector(ringerControl)]) return nil;
return [workspace ringerControl];
}
@end