-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimerAlarms.xm
63 lines (47 loc) · 2.29 KB
/
TimerAlarms.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
#import "TimerAlarms.h"
static NSDate *choosenTime;
%hook TimerViewController
- (void) viewDidLoad {
if (!self.navigationItem.leftBarButtonItem) {
NSLog(@"[TimerAlarms] Adding TimerAlarms add button to Timer view...");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addButtonPressed:)];
}
%orig;
}
%new - (void)addButtonPressed:(id)sender {
if ([sender isKindOfClass:[UIBarButtonItem class]]) {
NSLog(@"[TimerAlarms] Detected add button press, showing add view...");
} else {
return;
}
//Get the timePicker. Thanks to IRC user Jailpod on #theos IRC for his help
/*
TimerControlsView *timerControlsView = MSHookIvar <TimerControlsView *> (self, "_timerControlsView");
UIDatePicker *timerPicker = MSHookIvar <UIDatePicker *> (timerControlsView, "_timePicker");
*/
//The 2 above lines replaced by: (thanks DHowett)
UIDatePicker *timePicker = MSHookIvar<UIDatePicker *>(MSHookIvar<id>(self, "_timerControlsView"), "_timePicker");
//Assign the choosen time
NSTimeInterval timeInterval = timePicker.countDownDuration;
choosenTime = [[NSDate date] dateByAddingTimeInterval:timeInterval];
//v1.1: Fix for "deleting all alarms" bug (Initialize the alarm view if not initialized)
if ([(AlarmViewController *)[[self.tabBarController.viewControllers objectAtIndex:1] topViewController] numberOfItems] == 0) {
NSLog(@"[TimerAlarms] AlarmView might have not been initialized. Initializing AlarmView...");
[(AlarmViewController *)[[self.tabBarController.viewControllers objectAtIndex:1] topViewController] reloadState];
NSLog(@"[TimerAlarms] AlarmView initialized!");
}
//Show the add new alarm view of AlarmViewController
NSLog(@"[TimerAlarms] User pickicked time [%@], prompting add view...", choosenTime);
[(AlarmViewController *)[[self.tabBarController.viewControllers objectAtIndex:1] topViewController] showAddView];
}
%end
%hook EditAlarmView
- (void)layoutSubviews {
%orig();
if (choosenTime) {
// NSLog(@"[TimerAlarms] Setting addAlarm's datePicker to %@.", choosenTime);
[self.timePicker setDate:choosenTime animated:NO];
choosenTime = nil;
}
}
%end