-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSavedPrefs.m
135 lines (109 loc) · 3.98 KB
/
SavedPrefs.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#import "SavedPrefs.h"
@implementation SavedPrefs
@synthesize preferences;
- (instancetype) init {
self = [super init];
if (self) {
self.preferences = [[HBPreferences alloc] initWithIdentifier: @"com.thatmarcel.tweaks.lyzz.prefs.defaults"];
[preferences registerDefaults: @{
@"tweak-enabled": @true,
@"lockscreen-notification-enabled": @true,
@"lockscreen-notification-color-style": @0,
@"lockscreen-notification-view-style": @0,
@"lockscreen-notification-custom-color": @"#ffffff",
@"apple-music-enabled": @true,
@"apple-music-color-style": @0,
@"apple-music-view-style": @0,
@"apple-music-custom-color": @"#ffffff",
@"spotify-enabled": @true,
@"spotify-color-style": @0,
@"spotify-view-style": @0,
@"spotify-custom-color": @"#ffffff"
}];
}
return self;
}
- (BOOL) isEnabled {
return [preferences boolForKey:@"tweak-enabled"];
}
- (BOOL) isTypeEnabled:(LyzzType)type {
if (![self isEnabled]) {
return false;
}
NSString *key;
switch (type) {
case LockscreenNotificationType:
key = @"lockscreen-notification-enabled";
break;
case AppleMusicType:
key = @"apple-music-enabled";
break;
case SpotifyType:
key = @"spotify-enabled";
break;
default:
return false;
}
return [preferences boolForKey: key];
}
- (BOOL) isColorFlowEnabledForType:(LyzzType)type {
NSString *key;
switch (type) {
case LockscreenNotificationType:
key = @"lockscreen-notification-color-style";
break;
case AppleMusicType:
key = @"apple-music-color-style";
break;
case SpotifyType:
key = @"spotify-color-style";
break;
default:
return false;
}
return [@0 isEqual: ((NSNumber*) [preferences objectForKey: key])];
}
- (UIColor*) customColorForType:(LyzzType)type {
NSString *key;
switch (type) {
case LockscreenNotificationType:
key = @"lockscreen-notification-custom-color";
break;
case AppleMusicType:
key = @"apple-music-custom-color";
break;
case SpotifyType:
key = @"spotify-custom-color";
break;
default:
return [UIColor whiteColor];
}
unsigned int hexInt = 0;
NSScanner *scanner = [NSScanner scannerWithString: (NSString*) [preferences objectForKey: key]];
// Tell scanner to skip the # character
[scanner setCharactersToBeSkipped: [NSCharacterSet characterSetWithCharactersInString: @"#"]];
[scanner scanHexInt: &hexInt];
UIColor *color = [UIColor colorWithRed: ((CGFloat) ((hexInt & 0xFF0000) >> 16)) / 255
green: ((CGFloat) ((hexInt & 0xFF00) >> 8)) / 255
blue: ((CGFloat) (hexInt & 0xFF)) / 255
alpha: 1.0];
return color;
}
- (LyzzViewType) viewStyleForType:(LyzzType)type {
NSString *key;
switch (type) {
case LockscreenNotificationType:
key = @"lockscreen-notification-view-style";
break;
case AppleMusicType:
key = @"apple-music-view-style";
break;
case SpotifyType:
key = @"spotify-view-style";
break;
default:
return false;
}
return [(NSNumber*) [preferences objectForKey: key] unsignedIntegerValue];
}
@end