-
Notifications
You must be signed in to change notification settings - Fork 4
/
STKConstants.mm
68 lines (56 loc) · 2.42 KB
/
STKConstants.mm
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
#import "STKConstants.h"
#import "SBIconListView+ApexAdditions.h"
#import <UIKit/UIKit.h>
#import <SpringBoard/SpringBoard.h>
#import <objc/runtime.h>
#include <string>
#include <mutex>
NSString * const STKEditingEndedNotificationName = @"STKEditingEnded";
CFStringRef const STKPrefsChangedNotificationName = CFSTR("com.a3tweaks.apex2.prefschanged");
SBIconListView * STKListViewForIcon(SBIcon *icon)
{
SBIconController *controller = [objc_getClass("SBIconController") sharedInstance];
SBRootFolder *rootFolder = [controller rootFolder];
NSIndexPath *indexPath = [rootFolder indexPathForIcon:icon];
SBIconListView *listView = nil;
[controller getListView:&listView folder:NULL relativePath:NULL forIndexPath:indexPath createIfNecessary:NO];
return listView;
}
SBIconListView * STKCurrentListView(void)
{
return [[[CLASS(SBIconController) sharedInstance] _currentFolderController] currentIconListView];
}
SBIconCoordinate STKCoordinateFromDictionary(NSDictionary *dict)
{
return (SBIconCoordinate){[dict[@"row"] integerValue], [dict[@"col"] integerValue]};
}
NSDictionary * STKDictionaryFromCoordinate(SBIconCoordinate coordinate)
{
return @{@"row":[NSNumber numberWithInteger:coordinate.row], @"col":[NSNumber numberWithInteger:coordinate.col]};
}
double STKScaleNumber(double numToScale, double prevMin, double prevMax, double newMin, double newMax)
{
double oldRange = (prevMax - prevMin);
double newRange = (newMax - newMin);
return (((numToScale - prevMin) * newRange) / oldRange) + newMin;
}
NSString * NSStringFromSTKGroupSlot(STKGroupSlot slot)
{
return [NSString stringWithFormat:@"%@, index: %@", NSStringFromLayoutPosition(slot.position), @(slot.index)];
}
static std::mutex _versionMapMutex;
static NSMutableDictionary<NSString *, NSNumber *> *_versionDictionary;
BOOL STKVersionGreaterThanOrEqualTo(NSString *version) {
std::lock_guard<std::mutex> lock(_versionMapMutex);
const std::string key(version.UTF8String);
if (!_versionDictionary) {
_versionDictionary = [[NSMutableDictionary dictionaryWithSharedKeySet:[NSDictionary sharedKeySetForKeys:@[@"7.1", @"8.1", @"9.0", @"10.0"]]] retain];
}
auto value = _versionDictionary[version];
if (value) {
return value.boolValue;
}
value = @([UIDevice.currentDevice.systemVersion compare:version options:NSNumericSearch] != NSOrderedAscending);
_versionDictionary[version] = value;
return value.boolValue;
}