forked from BlakeBoxberger/DateUnderTimeX
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tweak.xm
162 lines (133 loc) · 4.5 KB
/
Tweak.xm
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#import "important.h"
#import <spawn.h>
@interface UIColor (fromHex)
+ (UIColor *)colorwithHexString:(NSString *)hexStr alpha:(CGFloat)alpha;
@end
@interface _UIStatusBarStringView : UIView
@property (copy) NSString *text;
@property NSInteger numberOfLines;
@property (copy) UIFont *font;
@property (copy) UIColor *color;
@property NSInteger textAlignment;
@end
@interface _UIStatusBarBackgroundActivityView : UIView
@property (copy) CALayer *pulseLayer;
@end
@interface _UIStatusBarTimeItem : UIView
@property (copy) _UIStatusBarStringView *shortTimeView;
@property (copy) _UIStatusBarStringView *pillTimeView;
@property (nonatomic, retain) NSTimer *nz9_seconds_timer;
@end
@implementation UIColor (fromHex)
+ (UIColor *)colorwithHexString:(NSString *)hexStr alpha:(CGFloat)alpha;
{
//-----------------------------------------
// Convert hex string to an integer
//-----------------------------------------
unsigned int hexint = 0;
// Create scanner
NSScanner *scanner = [NSScanner scannerWithString:hexStr];
// Tell scanner to skip the # character
[scanner setCharactersToBeSkipped:[NSCharacterSet
characterSetWithCharactersInString:@"#"]];
[scanner scanHexInt:&hexint];
//-----------------------------------------
// Create color object, specifying alpha
//-----------------------------------------
UIColor *color =
[UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255
green:((CGFloat) ((hexint & 0xFF00) >> 8))/255
blue:((CGFloat) (hexint & 0xFF))/255
alpha:alpha];
return color;
}
@end
int sizeOfFont = GetPrefInt(@"sizeOfFont");
int fontAlpha = GetPrefInt(@"fontAlpha");
NSString *fontColor = GetPrefString(@"fontHex");
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
%hook _UIStatusBarStringView
- (void)setText:(NSString *)text {
if(GetPrefBool(@"Enable") && [text containsString:@":"]) {
NSString *lineOne = GetPrefString(@"lineOne");
NSString *lineTwo = GetPrefString(@"lineTwo");
NSString *timeLineOne = lineOne;
NSString *timeLineTwo = lineTwo;
NSDate *now = [NSDate date];
if(!GetPrefBool(@"lineTwoStandard")){
[dateFormatter setDateFormat:lineTwo];
timeLineTwo = [dateFormatter stringFromDate:now];
timeLineTwo = [timeLineTwo substringToIndex:[timeLineTwo length]];
}
if(!GetPrefBool(@"lineOneStandard")){
[dateFormatter setDateFormat:lineOne];
timeLineOne = [dateFormatter stringFromDate:now];
timeLineOne = [timeLineOne substringToIndex:[timeLineOne length]];
}
NSString *newString;
if(GetPrefBool(@"lineOneEnable")){
newString = [NSString stringWithFormat:@"%@\n%@", timeLineOne, timeLineTwo];
}
else{
newString = [NSString stringWithFormat:@"%@\n%@", text, timeLineTwo];
}
[self setFont: [self.font fontWithSize:sizeOfFont]];
if((fontColor) && (fontAlpha) && (GetPrefBool(@"customColor"))){
[self setColor:[UIColor colorwithHexString:fontColor alpha:fontAlpha]];
}
if(GetPrefBool(@"replaceTime")){
%orig(timeLineOne);
}
else{
self.textAlignment = 1;
self.numberOfLines = 2;
%orig(newString);
}
}
else {
%orig(text);
}
}
%end
%hook _UIStatusBarTimeItem
%property (nonatomic, retain) NSTimer *nz9_seconds_timer;
- (instancetype)init {
%orig;
if(GetPrefBool(@"Enable") && GetPrefBool(@"hasSeconds")) {
self.nz9_seconds_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer *timer) {
self.shortTimeView.text = @":";
self.pillTimeView.text = @":";
[self.shortTimeView setFont: [self.shortTimeView.font fontWithSize:sizeOfFont]];
[self.pillTimeView setFont: [self.pillTimeView.font fontWithSize:sizeOfFont]];
}];
}
return self;
}
- (id)applyUpdate:(id)arg1 toDisplayItem:(id)arg2 {
id returnThis = %orig;
[self.shortTimeView setFont: [self.shortTimeView.font fontWithSize:sizeOfFont]];
[self.pillTimeView setFont: [self.pillTimeView.font fontWithSize:sizeOfFont]];
return returnThis;
}
%end
%hook _UIStatusBarBackgroundActivityView
- (void)setCenter:(CGPoint)point {
if(GetPrefBool(@"Enable") && !GetPrefBool(@"replaceTime")){
point.y = 11;
self.frame = CGRectMake(0, 0, self.frame.size.width, 31);
self.pulseLayer.frame = CGRectMake(0, 0, self.frame.size.width, 31);
%orig(point);
}
}
%end
%hook _UIStatusBarIndicatorLocationItem
- (id)applyUpdate:(id)arg1 toDisplayItem:(id)arg2 {
return nil;
}
%end
%ctor {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterNoStyle;
dateFormatter.timeStyle = NSDateFormatterMediumStyle;
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
}