-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.xm
More file actions
executable file
·53 lines (40 loc) · 1.67 KB
/
Tweak.xm
File metadata and controls
executable file
·53 lines (40 loc) · 1.67 KB
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
#import "UIView+Toast.m"
#import "MobileTimer/EditAlarmView.h"
@interface EditAlarmViewController : UIViewController
@end
int differenceFromTimeInterval(int secondsForAlarm) {
// Get the current time as seconds into the day
NSDate *now = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:now];
int secondsNow = ([components hour] * 3600) + ([components minute] * 60);
// Calculate difference between the alarm and time now
int difference = 0;
if (secondsNow < secondsForAlarm) {
difference = secondsForAlarm - secondsNow;
} else {
difference = (86400) - (secondsNow - secondsForAlarm);
}
return difference;
}
NSString *stringFromDifference(int difference) {
// Convert the difference to days, hours and minutes
int days = difference / 86400;
int hours = (difference % 86400) / 3600;
int minutes = ((difference % 86400) % 3600) / 60;
// Turn into string
NSString *daysString = (days > 0) ? [NSString stringWithFormat:@"%dd ", days] : @"";
NSString *hoursString = (hours > 0) ? [NSString stringWithFormat:@"%dh ", hours] : @"";
return [NSString stringWithFormat:@"%@%@%dm", daysString, hoursString, minutes];
}
%hook EditAlarmViewController
- (void)handlePickerChanged {
%orig;
EditAlarmView *editAlarmView = MSHookIvar<EditAlarmView *>(self, "_editAlarmView");
UIDatePicker *timePicker = MSHookIvar<UIDatePicker *>(editAlarmView, "_timePicker");
int pickedTime = timePicker.countDownDuration;
int difference = differenceFromTimeInterval(pickedTime);
[self.view hideToastActivity];
[self.view makeToast:stringFromDifference(difference)];
}
%end