/
Tweak.xm
507 lines (403 loc) · 15.8 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
// ChatKit imports
#import <iOS7/PrivateFrameworks/ChatKit/CKTranscriptController.h>
#import <iOS7/PrivateFrameworks/ChatKit/CKConversationList.h>
#import <iOS7/PrivateFrameworks/ChatKit/CKConversation.h>
// Messages Imports
#import "MobileSMS/CKMessagesController.h"
// UIKit imports
#import <iOS7/Frameworks/UIKit/UIGestureRecognizer.h>
#import <iOS7/Frameworks/UIKit/UIView.h>
#import <iOS7/Frameworks/UIKit/_UIBackdropView.h>
#import <iOS7/Frameworks/UIKit/_UIBackdropViewSettings.h>
// PREFERENCES
#define PrefPath [[@"~" stringByExpandingTildeInPath] stringByAppendingPathComponent:@"Library/Preferences/com.mattcmultimedia.messageswiper7.plist"]
static BOOL globalEnable = YES;
static BOOL wrapAroundEnabled = YES;
static BOOL detectCenter = NO;
static int edgePercent = 20; //%
static BOOL hiddenPreviews = NO;
static BOOL didRun = NO;
static CKMessagesController *ckMessagesController = nil;
// static UIView *backPlacard = nil;
static NSMutableArray *convos = [[[NSMutableArray alloc] init] autorelease];
static int currentConvoIndex = 0;
static BOOL leftTriggered = NO;
static BOOL rightTriggered = NO;
static UILabel *leftNameLabel;
static UILabel *rightNameLabel;
static UILabel *leftMessageLabel;
static UILabel *rightMessageLabel;
%group MessagesiOS7
/*
MS7ConvoPreview
*/
@interface MS7ConvoPreview : UIView
@property (nonatomic, retain) _UIBackdropView *fakeBar;
@end
@implementation MS7ConvoPreview
@synthesize fakeBar = _fakeBar;
- (void)baseInit {
// self.blurredPreview = [[CKBlurView alloc] initWithFrame:self.frame];
// self.blurredPreview.blurRadius = 10.0f;
// self.blurredPreview.blurCroppingRect = self.blurredPreview.frame;
[self setUserInteractionEnabled: NO];
[self setBackgroundColor: [[UIColor whiteColor] colorWithAlphaComponent:0.1]];
self.layer.cornerRadius = 8;
self.layer.masksToBounds = YES;
self.alpha = 0;
// self.fakeBar = [[UIToolbar alloc] initWithFrame:self.bounds];
self.fakeBar = [[_UIBackdropView alloc] initWithFrame:self.bounds]; // settings:[[[_UIBackdropViewSettings alloc] initWithDefaultValues] autorelease]];
self.fakeBar.autoresizingMask = self.autoresizingMask;
// [self.fakeBar applySettingsWithBuiltInAnimatieon: [_UIBackdropView defaultSettingsClass]];
// self.fakeBar.barStyle = UIBarStyleDefault;
// self.fakeBar.translucent = YES;
// [self.fakeBar setBackgroundColor: [UIColor clearColor]];
[self insertSubview:self.fakeBar atIndex:0];
// [self addSubview: self.fakeBar];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self baseInit];
}
return self;
}
@end
/*
END MS7ConvoPreview
*/
static MS7ConvoPreview *leftPreview;
static MS7ConvoPreview *rightPreview;
// There's only one CKTranscriptController instantiated.
// It controls which CkTranscriptCollectionView is shown.
// Those CKTranscriptCollectionView s have a subview of class CKTranscriptScrollView (or something like that)
%hook CKTranscriptController
%new(v@:B)
-(void)resetPreviewsAnimated:(BOOL)shouldAnimate {
// NSLog(@"RESET PREVIEWS ANIMATED: %@", shouldAnimate?@"YES":@"NO");
int height = 70+80;
if ([self _isGroupMessage]) {
height = 70+80+44;
}
if (!shouldAnimate) {
[leftPreview setCenter:CGPointMake(-60, height)];
[rightPreview setCenter:CGPointMake(self.view.superview.frame.size.width+60, height)];
leftPreview.alpha = 0.0;
rightPreview.alpha = 0.0;
} else {
// NSLog(@"159");
// animate to default positions.
[UIView animateWithDuration:0.4
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
leftPreview.center = CGPointMake(-60, leftPreview.center.y);
rightPreview.center = CGPointMake(self.view.superview.frame.size.width+60, leftPreview.center.y);
leftPreview.alpha = 0;
rightPreview.alpha = 0;
}
completion:nil];
}
}
%new(v@:@)
-(void)MS7_handlepan:(UIPanGestureRecognizer *)recognizer
{
// NSLog(@"MS7_handlepan");
if (recognizer.state == UIGestureRecognizerStateBegan) {
// reset the previews just in case they're still animating
[self.view.superview.layer removeAllAnimations];
[self resetPreviewsAnimated:NO];
if (!hiddenPreviews) {
leftPreview.alpha = 1.0;
rightPreview.alpha = 1.0;
} else {
leftPreview.alpha = 0.0;
rightPreview.alpha = 0.0;
}
// NSLog(@"BEGAN SHIT");
leftTriggered = NO;
rightTriggered = NO;
// get conversations for the previews
// swiped to left, so -1
int nextConvoIndex = 0;
nextConvoIndex = currentConvoIndex - 1;
if (currentConvoIndex == 0) {
if (wrapAroundEnabled) {
nextConvoIndex = [convos count] - 1 ;
} else {
nextConvoIndex = 0;
//maybe show bounce animation here
}
}
// NSLog(@"%i", (int)[convos count]);
// NSLog(@"%i", nextConvoIndex);
[self setLeftConversation: [convos objectAtIndex: nextConvoIndex]];
nextConvoIndex = 0;
nextConvoIndex = currentConvoIndex + 1;
if (nextConvoIndex >= [convos count]) {
if (wrapAroundEnabled) {
nextConvoIndex = 0;
} else {
nextConvoIndex = currentConvoIndex;
//maybe show bounce animation here
}
}
[self setRightConversation: [convos objectAtIndex: nextConvoIndex]];
}
// NSLog(@"213");
// now move both of the views
int translation = [recognizer translationInView:recognizer.view].x;
// NSLog(@"%i", translation);
// Move both previews
// NOTE: make sure to update preview contents when the conversation changes, not on the handle pan
int newX = (int) -60+translation;
[leftPreview setCenter:CGPointMake(MIN(60, newX), leftPreview.center.y)];
leftTriggered = leftPreview.center.x == 60;
newX = (int) self.view.superview.frame.size.width+60+translation;
[rightPreview setCenter:CGPointMake(MAX(self.view.superview.frame.size.width-60, newX), rightPreview.center.y)];
rightTriggered = rightPreview.center.x == self.view.superview.frame.size.width-60;
if (recognizer.state == UIGestureRecognizerStateEnded) {
// NSLog(@"ENDED SHIT: %@", (leftTriggered||rightTriggered)?@"YES":@"NO");
int nextConvoIndex = 0;
if (leftTriggered) {
// swiped to left, so -1
nextConvoIndex = currentConvoIndex - 1;
if (currentConvoIndex == 0) {
if (wrapAroundEnabled) {
nextConvoIndex = [convos count] - 1 ;
} else {
nextConvoIndex = 0;
//maybe show bounce animation here
}
}
}
if (rightTriggered) {
nextConvoIndex = currentConvoIndex + 1;
if (nextConvoIndex >= [convos count]) {
if (wrapAroundEnabled) {
nextConvoIndex = 0;
} else {
nextConvoIndex = currentConvoIndex;
//maybe show bounce animation here
}
}
}
// now present the user with the next conversation, possibly with a nice sliding animation?
if (leftTriggered || rightTriggered) {
[ckMessagesController showConversation:[convos objectAtIndex:nextConvoIndex] animate:YES];
}
[self resetPreviewsAnimated:YES];
}
}
%new(v@:)
- (void)initPreviews
{
leftPreview = [[MS7ConvoPreview alloc] initWithFrame:CGRectMake(0,70,120,160)];
rightPreview = [[MS7ConvoPreview alloc] initWithFrame:CGRectMake(320,70,120,160)];
// now create the labels and add them to the blurred view
leftNameLabel = [[UILabel alloc] initWithFrame: CGRectMake(10, 10, 100, 55)];
rightNameLabel = [[UILabel alloc] initWithFrame: CGRectMake(10, 10, 100, 55)];
leftMessageLabel = [[UILabel alloc] initWithFrame: CGRectMake(10,10+50+10,100,80)];
rightMessageLabel = [[UILabel alloc] initWithFrame: CGRectMake(10,10+50+10,100,80)];
[leftNameLabel setTextColor: [UIColor blackColor]];
[leftNameLabel setBackgroundColor:[UIColor clearColor]];
[rightNameLabel setTextColor: [UIColor blackColor]];
[rightNameLabel setBackgroundColor:[UIColor clearColor]];
[leftNameLabel setFont: [UIFont systemFontOfSize: 14.0f]];
[rightNameLabel setFont: [UIFont systemFontOfSize: 14.0f]];
[leftNameLabel setNumberOfLines: 4];
[rightNameLabel setNumberOfLines: 4];
[leftNameLabel setLineBreakMode: NSLineBreakByWordWrapping];
[rightNameLabel setLineBreakMode: NSLineBreakByWordWrapping];
//add message label here
[leftMessageLabel setTextColor: [UIColor blackColor]];
[leftMessageLabel setBackgroundColor: [UIColor clearColor]];
[rightMessageLabel setTextColor: [UIColor blackColor]];
[rightMessageLabel setBackgroundColor: [UIColor clearColor]];
[leftMessageLabel setFont:[UIFont systemFontOfSize: 12.0f]];
[rightMessageLabel setFont:[UIFont systemFontOfSize: 12.0f]];
[leftMessageLabel setNumberOfLines: 10];
[rightMessageLabel setNumberOfLines: 10];
[leftMessageLabel setLineBreakMode: NSLineBreakByWordWrapping];
[rightMessageLabel setLineBreakMode: NSLineBreakByWordWrapping];
[leftNameLabel setText: @"Unknown - Error"];
[rightNameLabel setText: @"Unknown - Error"];
[leftMessageLabel setText: @"Error Retrieving Message"];
[rightMessageLabel setText: @"Error Retrieving Message"];
[leftPreview addSubview: leftNameLabel];
[rightPreview addSubview: rightNameLabel];
[leftPreview addSubview: leftMessageLabel];
[rightPreview addSubview: rightMessageLabel];
}
%new(v@:@)
- (void)setLeftConversation:(CKConversation *)convo
{
// NSLog(@"left convo: %@", convo);
[leftNameLabel setText: [convo name]?:@"Unknown - Error"];
[leftMessageLabel setText: [[convo latestMessage] previewText]?:@"Error Retrieving Message"];
}
%new(v@:@)
- (void)setRightConversation:(CKConversation *)convo
{
[rightNameLabel setText: [convo name]?:@"Unknown - Error"];
[rightMessageLabel setText: [[convo latestMessage] previewText]?:@"Error Retrieving Message"];
}
//delegate methods
%new(B@:@@)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// NSLog(@"shouldReceiveTouch");
if (![self _isVisible] || !globalEnable) {
// NSLog(@"NOT ACCEPTING TOUCH");
return NO;
}
// Get the touch's location in the self.view.superview view
// if between the bounds we care about, return yes, else, no
CGPoint coord = [touch locationInView: self.view.superview];
float w = self.view.superview.frame.size.width;
float edgeSize = (edgePercent/100.0)*w;
if (detectCenter && (coord.x > edgeSize) && (coord.x < w-edgeSize)) {
// NSLog(@"ACCEPTED");
return YES;
}
if (!detectCenter && ((coord.x < edgeSize) || (coord.x > w-edgeSize))) {
// NSLog(@"ACCEPTED");
return YES;
}
// NSLog(@"NOT ACCEPTED");
return NO;
}
%new(B@:@@)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
%new(B@:@)
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
return YES;
}
- (id)initWithNavigationController:(id)arg1
{
id r = %orig;
[self initPreviews];
return r;
}
- (id)init
{
id r = %orig;
[self initPreviews];
return r;
}
- (void)viewDidAppear:(BOOL)arg1 {
%orig;
if (self.view.superview) {
if (!didRun) {
didRun = YES;
self.view.superview.userInteractionEnabled = YES;
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(MS7_handlepan:)];
panRecognizer.maximumNumberOfTouches = 1;
[panRecognizer setDelegate:self];
// [panRecognizer _setHysteresis: 50.0];
[self.view.superview addGestureRecognizer: panRecognizer];
[panRecognizer release];
// now add the previews to the self.view.superview
}
if (self) {
[self.view.superview addSubview: leftPreview];
[self.view.superview addSubview: rightPreview];
[self resetPreviewsAnimated: NO];
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
}
}
}
- (void)sendMessage:(id)arg1 {
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
currentConvoIndex = 0;
%orig;
}
%end
%hook CKMessagesController
- (void)_conversationLeft:(id)fp8 {
// left a conversation? update the list
%orig;
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
}
- (BOOL)resumeToConversation:(id)fp8 {
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
currentConvoIndex = [convos indexOfObject:fp8];
return %orig;
}
- (void)showConversation:(id)fp8 animate:(BOOL)fp12 {
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
currentConvoIndex = [convos indexOfObject:fp8];
%orig;
}
- (void)showConversation:(id)fp8 animate:(BOOL)fp12 forceToTranscript:(BOOL)fp16 {
convos = [[[%c(CKConversationList) sharedConversationList] conversations] mutableCopy];
currentConvoIndex = [convos indexOfObject:fp8];
%orig;
}
- (id)init {
id r = %orig;
ckMessagesController = r;
return r;
}
%end
%end
static void MS7UpdatePreferences() {
NSLog(@"AWW SHIT NIGGA");
NSDictionary *preferences = [[NSDictionary alloc] initWithContentsOfFile:PrefPath];
globalEnable = YES;
if (preferences) {
//if the option exists make it that, else default
if ([preferences valueForKey:@"globalEnable"] != nil) {
globalEnable = [[preferences valueForKey:@"globalEnable"] boolValue];
} else {
globalEnable = YES;
}
if ([preferences valueForKey:@"hiddenPreviews"] != nil) {
hiddenPreviews = [[preferences valueForKey:@"hiddenPreviews"] boolValue];
} else {
hiddenPreviews = NO;
}
if ([preferences valueForKey:@"wrapAroundEnabled"] != nil) {
wrapAroundEnabled = [[preferences valueForKey:@"wrapAroundEnabled"] boolValue];
} else {
wrapAroundEnabled = NO;
}
if ([preferences valueForKey:@"edgePercent"] != nil) {
edgePercent = [[preferences valueForKey:@"edgePercent"] intValue];
} else {
edgePercent = 20;
}
if ([preferences valueForKey:@"detectCenter"] != nil) {
detectCenter = [[preferences valueForKey:@"detectCenter"] boolValue];
} else {
detectCenter = NO;
}
}
[preferences release];
}
static void reloadPrefsNotification(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
MS7UpdatePreferences();
}
%ctor {
//init prefs again
MS7UpdatePreferences();
CFNotificationCenterRef reload = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(reload, NULL, &reloadPrefsNotification,
CFSTR("com.mattcmultimedia.messageswiper7/reload"), NULL, 0);
%init;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
%init(MessagesiOS7);
} else {
// %init(MessagesiOS6);
// %init(WhatsAppiOS6);
}
}