-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.xm
133 lines (115 loc) · 4.68 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
#define ivar(object, name) name; object_getInstanceVariable(object, "_"#name, (void**)&name);
#import <EventKit/EventKit.h>
@interface CKMessageCell : NSObject
-(void)balloonViewDidTapRemind:(id)arg1;
-(void)__performTargetAction:(SEL)arg1;
@end
%hook CKBalloonView
-(void)_showCopyCallout {
%orig;
NSMutableArray *menuItems = [NSMutableArray arrayWithArray:[[UIMenuController sharedMenuController] menuItems]];
UIMenuItem *mitem = [[UIMenuItem alloc] initWithTitle:@"Remind" action:@selector(remind:)];
[menuItems addObject:mitem];
[mitem release];
[[UIMenuController sharedMenuController] setMenuItems:menuItems];
[[UIMenuController sharedMenuController] update];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
%new
-(void)remind:(id)sender {
id ivar(self, actionDelegate);
if ([actionDelegate respondsToSelector:@selector(balloonViewDidTapRemind:)]) {
[actionDelegate balloonViewDidTapRemind:self];
}
}
%end
%hook CKMessageCell
%new
-(void)balloonViewDidTapRemind:(id)arg1 {
[self __performTargetAction:@selector(messageCellTappedRemind)];
}
%end
@interface EKReminder ()
-(void)setAction:(id)arg1;
@end
@interface CKTranscriptController : UIViewController <UIActionSheetDelegate>
-(id)recipients;
-(void)createReminderWithDurationInMinutes:(NSUInteger)minutes;
@end
%hook CKTranscriptController
%new
-(void)messageCellTappedRemind {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"1 minute", @"5 minutes", @"15 minutes", @"1 hour", nil];
[actionSheet showInView:[self view]];
[actionSheet release];
}
%new
-(void)createReminderWithDurationInMinutes:(NSUInteger)minutes {
//use originalAddress method for recipients as it falls back on rawAddress
NSArray *recipients = [[self recipients] valueForKey:@"originalAddress"];
NSString *title = [NSString stringWithFormat:@"Text %@", [[[self recipients] valueForKey:@"name"] componentsJoinedByString:@", "]];
EKEventStore *store = [[EKEventStore alloc] init];
EKReminder *reminder = [EKReminder reminderWithEventStore:store];
[reminder setTitle:title];
[reminder setCalendar:[store defaultCalendarForNewReminders]];
NSString *actionURL = [NSString stringWithFormat:@"sms:/open?addresses=%@", [recipients componentsJoinedByString:@","]];
if ([recipients count] == 1) {
actionURL = [NSString stringWithFormat:@"sms:/open?address=%@", recipients[0]];
}
[reminder setAction:[NSURL URLWithString:actionURL]];
NSDate *alarmDate = [NSDate dateWithTimeIntervalSinceNow:minutes * 60];
EKAlarm *alarm = [EKAlarm alarmWithAbsoluteDate:alarmDate];
[reminder setDueDateComponents:[[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:alarmDate]];
[reminder setAlarms:@[alarm]];
NSError *err = nil;
BOOL didSave = [store saveReminder:reminder commit:YES error:&err];
[store release];
if (didSave == NO || err != nil) {
//show error.
}
}
%new
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([actionSheet cancelButtonIndex] == buttonIndex) {
return;
}
switch (buttonIndex) {
case 0://1 min
[self createReminderWithDurationInMinutes:1];
break;
case 1://5 min
[self createReminderWithDurationInMinutes:5];
break;
case 2://15 min
[self createReminderWithDurationInMinutes:15];
break;
case 3://1 hour
[self createReminderWithDurationInMinutes:60];
break;
}
}
%end
%hook RemindersCheckboxCell
-(void)tap:(UIGestureRecognizer *)gestureRecognizer {
NSURL *ivar(self, actionURL); UIView *ivar(self, linkHighlightView);
if ([[actionURL scheme] isEqualToString:@"sms"]) {
if ([gestureRecognizer state] == 3) {//ended
[[UIApplication sharedApplication] openURL:actionURL];
}
if ([gestureRecognizer state] == 1) {//began
if (!linkHighlightView) {
UILabel *ivar(self, titleLabel);
linkHighlightView = [[%c(RemindersHighlightView) alloc] initWithFrame:[titleLabel frame]];
[linkHighlightView setOpaque:NO];
object_setInstanceVariable(self, "_linkHighlightView", linkHighlightView);
}
[self addSubview:linkHighlightView];
}
if ([gestureRecognizer state] > 2) {
[linkHighlightView removeFromSuperview];
}
} else {
%orig;
}
}
%end