forked from andrewwiik/Intelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNCNotificationCombinedListViewController.xm
660 lines (597 loc) · 31.8 KB
/
NCNotificationCombinedListViewController.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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
#import <UserNotificationsKit/NCNotificationRequest.h>
#import <UIKit/UICollectionView+Private.h>
#import <Intelix/NCNotificationCombinedListViewController.h>
#import <Intelix/NCNotificationListCell.h>
#import <Intelix/NCNotificationChronologicalList.h>
#import <Intelix/ITXNCGroupFooterView.h>
#import <Intelix/ITXNCGroupBackgroundView.h>
#import <Intelix/ITXNCGroupBackgroundConfiguration.h>
#import <Intelix/NCNotificationPriorityList.h>
#import <Intelix/NCNotificationListSectionHeaderView.h>
// static BOOL isIOS11 = YES;
%hook NCNotificationCombinedListViewController
- (BOOL)_isNotificationRequestForLockScreenNotificationDestination:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #25");
BOOL orig = %orig;
return orig;
// return orig;
if (orig) {
self.showingNotificationsHistory = YES;
self.notificationPriorityList.controller = self;
//[self _revealNotificationsHistory];
}
return NO;
// return NO;
}
%new
- (id)sectionList {
// HBLogInfo(@"Method #26");
return [self notificationSectionList];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)layout referenceSizeForHeaderInSection:(NSUInteger)section {
// HBLogInfo(@"Method #27");
if (section > [self.notificationPriorityList sectionCount] - 1) return %orig;
else {
if ([collectionView numberOfItemsInSection:section] > 0) {
return CGSizeMake(collectionView.bounds.size.width, 60);
} else {
return CGSizeZero;
}
}
}
-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(NCNotificationListCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
if ([cell isKindOfClass:NSClassFromString(@"NCNotificationListCell")]) {
cell.hasFooterUnder = [self.sectionList sectionHasFooter:[self _adjustedSectionIndexForListOperation:[indexPath section]]];
cell.isLastInSection = [self collectionView:collectionView numberOfItemsInSection:[indexPath section]] - 1 == [indexPath row];
cell._isFirstInSection = [indexPath row] == 0;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
cell.hidden = !self.showingNotificationsHistory;
} else {
cell.hidden = NO;
cell.alpha= 1.0;
}
//cell.hasFooterUnder = [self.sectionList sectionIsCollapsed:[indexPath section]];
// cell.cellOver = nil;
// cell.cellUnder = nil;
}
%orig;
}
-(void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if (kind && [kind isEqualToString:[ITXNCGroupBackgroundView elementKind]]) {
ITXNCGroupBackgroundView *bgView = (ITXNCGroupBackgroundView *)view;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
bgView.hidden = !self.showingNotificationsHistory;
bgView.isTopSection = NO;
if (!self.showingNotificationsHistory) {
bgView.alpha = 0;
}
} else {
[bgView _resetRevealOverrides];
bgView.isTopSection = YES;
view.alpha= 1.0;
view.hidden = NO;
}
// if ([indexPath section] == 0) {
// [bgView _resetRevealOverrides];
// view.alpha = 1.0;
// view.hidden = NO;
// }
} else if (kind && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
NCNotificationListSectionHeaderView *headerView = (NCNotificationListSectionHeaderView *)view;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
headerView.hidden = !self.showingNotificationsHistory;
headerView.isTopSection = NO;
if (!self.showingNotificationsHistory) {
headerView.overrideAlpha = 0;
headerView.alpha = 0;
}
} else {
headerView.isTopSection = YES;
headerView.alpha = 1.0;
headerView.hidden = NO;
}
}
%orig;
}
-(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// HBLogInfo(@"Method #27");
// NSUInteger section = [indexPath section];
// if (section > [self.notificationPriorityList sectionCount] - 1) {
// if ([self.sectionList sectionIsCollapsed:[self _adjustedSectionIndexForListOperation:[indexPath section]]]) {
// if ([indexPath row] > 2) return nil;
// }
// } else {
// }
NCNotificationListCell *cell = %orig;
if ([cell isKindOfClass:NSClassFromString(@"NCNotificationListCell")]) {
cell.hasFooterUnder = [self.sectionList sectionHasFooter:[self _adjustedSectionIndexForListOperation:[indexPath section]]];
cell.isLastInSection = [self collectionView:collectionView numberOfItemsInSection:[indexPath section]] - 1 == [indexPath row];
cell._isFirstInSection = [indexPath row] == 0;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
//cell.alpha = self.showingNotificationsHistory ? 1.0 : 0.0;
cell.hidden = self.showingNotificationsHistory ? NO : YES;
} else {
cell.hidden = NO;
cell.alpha = 1.0;
// cell.alpha = 1.0;
}
//cell.hasFooterUnder = [self.sectionList sectionIsCollapsed:[indexPath section]];
// cell.cellOver = nil;
// cell.cellUnder = nil;
}
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(NCNotificationListCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
// HBLogInfo(@"Method #28");
%orig;
if ([cell isKindOfClass:NSClassFromString(@"NCNotificationListCell")]) {
cell.hasFooterUnder = [self.sectionList sectionHasFooter:[self _adjustedSectionIndexForListOperation:[indexPath section]]];
int numInSection = [self collectionView:collectionView numberOfItemsInSection:[indexPath section]];
cell.isLastInSection = numInSection - 1 == [indexPath row];
cell._isFirstInSection = [indexPath row] == 0;
//cell.hasFooterUnder = [self.sectionList sectionIsCollapsed:[indexPath section]];
// cell.cellOver = nil;
// cell.cellUnder = nil;
}
}
-(UIView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
// return %orig;
// HBLogInfo(@"Method #29");
if (kind && [kind isEqualToString:UICollectionElementKindSectionHeader]) {
if ([self.collectionView numberOfItemsInSection:[indexPath section]] > 0) {
NCNotificationListSectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"NotificationListSectionHeaderReuseIdentifier" forIndexPath:indexPath];
headerView.delegate = self;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
headerView.overrideAlpha = self.showingNotificationsHistory ? 1.0 : 0.0;
headerView.isTopSection = NO;
//if (self.showingNotificationsHistory) headerView.backgroundColor = [UIColor redColor];
//else headerView.backgroundColor = [UIColor greenColor];
if (!self.showingNotificationsHistory) headerView.alpha = 0;
headerView.hidden = !self.showingNotificationsHistory;
[headerView setTitle:[self.sectionList titleForSectionIndex:[self _adjustedSectionIndexForListOperation:[indexPath section]]] forSectionIdentifier:[self.sectionList identifierForSectionIndex:[self _adjustedSectionIndexForListOperation:[indexPath section]]]];
} else {
//headerView.backgroundColor = [UIColor blueColor];
headerView.overrideAlpha = 1.0;
headerView.alpha = 1.0;
headerView.hidden = NO;
headerView.isTopSection = YES;
[headerView setTitle:[self.notificationPriorityList titleForSectionIndex:[indexPath section]] forSectionIdentifier:[self.notificationPriorityList identifierForSectionIndex:[indexPath section]]];
// [headerView setTitle:]
}
return headerView;
}
}
if (kind && [kind isEqualToString:[ITXNCGroupBackgroundView elementKind]]) {
ITXNCGroupBackgroundView *backgroundView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"ITXNCGroupBackgroundViewReuseIdentifier" forIndexPath:indexPath];
backgroundView.isSectionBackground = YES;
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
backgroundView.isTopSection = NO;
} else {
backgroundView.isTopSection = YES;
}
// if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
// [bgView _resetRevealOverrides];
// view.alpha = 1.0;
// view.hidden = NO;
// } else {
// if (!self.showingNotificationsHistory) {
// bgView.alpha = 0;
// }
// }
return backgroundView;
}
//if (isIOS11 && [indexPath section] < 1) return %orig;
if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
if ([indexPath section] > [self.notificationPriorityList sectionCount] - 1) {
if ([self.sectionList sectionHasFooter:[self _adjustedSectionIndexForListOperation:[indexPath section]]]) {
ITXNCGroupFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"NotificationListSectionHFooterReuseIdentifier" forIndexPath:indexPath];
footerView.numberToShow = [self.sectionList actualNumberOfNotificationsInSection:[self _adjustedSectionIndexForListOperation:[indexPath section]]] - 3;
footerView.cellDelegate = self;
footerView.sectionIdentifier = [self.sectionList otherSectionIdentifierForSectionIndex:[self _adjustedSectionIndexForListOperation:[indexPath section]]];
footerView.isExpanded = [self.sectionList sectionIsExpanded:[self _adjustedSectionIndexForListOperation:[indexPath section]]];
footerView.alpha = self.showingNotificationsHistory ? 1.0 : 0.0;
footerView.userInteractionEnabled = YES;
return footerView;
}
} else {
ITXNCGroupFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"NotificationListSectionHFooterReuseIdentifier" forIndexPath:indexPath];
//footerView.numberToShow =
footerView.userInteractionEnabled = NO;
return footerView;
}
}
return nil;
// return %orig;
// return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
// HBLogInfo(@"Method #30");
if (section > [self.notificationPriorityList sectionCount] - 1) {
if ([self.sectionList sectionHasFooter:[self _adjustedSectionIndexForListOperation:section]]) {
return CGSizeMake(collectionView.frame.size.width - 8*2, 36);
}
}
return CGSizeZero;
}
- (void)viewDidLoad {
// HBLogInfo(@"Method #31");
%orig;
[[self collectionView] registerClass:[ITXNCGroupFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"NotificationListSectionHFooterReuseIdentifier"];
[[self collectionView] registerClass:[ITXNCGroupBackgroundView class] forSupplementaryViewOfKind:[ITXNCGroupBackgroundView elementKind] withReuseIdentifier:@"ITXNCGroupBackgroundViewReuseIdentifier"];
}
%new
-(void)sectionFooterView:(ITXNCGroupFooterView *)footerView didReceiveToggleExpansionActionForSectionIdentifier:(NSString *)sectionIdentifier {
// HBLogInfo(@"Method #32");
[self.sectionList toggleExpansionForSectionIdentifier:sectionIdentifier];
}
- (void)notificationSectionList:(NCNotificationChronologicalList *)sectionList didInsertNotificationRequest:(NCNotificationRequest *)request atIndexPath:(NSIndexPath *)path {
// HBLogInfo(@"Method #33");
[self _performCollectionViewOperationBlockIfNecessary:^{
[[[self collectionView] collectionViewLayout] invalidateLayout];
NSUInteger section = [path section];
//if (section > 0) {
if ([self.sectionList sectionIsCollapsed:section]) {
[[self collectionView] reloadSections:[NSIndexSet indexSetWithIndex:[self _adjustedSectionIndexForCollectionViewOperation:section]]];
} else {
NSIndexPath *newPath = [NSIndexPath indexPathForRow:[path row] inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]];
[[self collectionView] insertItemsAtIndexPaths:[NSArray arrayWithObjects:newPath,nil]];
}
if ([self.sectionList sectionIsCollapsed:section]) {
ITXNCGroupFooterView *footerView = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
if (footerView) {
footerView.numberToShow = [self.sectionList actualNumberOfNotificationsInSection:[path section]] - 3;
footerView.cellDelegate = self;
footerView.sectionIdentifier = [self.sectionList otherSectionIdentifierForSectionIndex:[path section]];
footerView.isExpanded = [self.sectionList sectionIsExpanded:[path section]];
// if (![self.sectionList sectionIsCollapsed:section]) {
// [self.collectionView.collectionViewLayout invalidateLayout];
// }
}
}
//}
}];
}
- (void)notificationSectionList:(NCNotificationChronologicalList *)sectionList didRemoveNotificationRequest:(NCNotificationRequest *)request atIndexPath:(NSIndexPath *)path {
// HBLogInfo(@"Method #34");
// HBLogInfo(@"Removed Notification: %@\n IndexPath: %@", request, path);
// NCNotificationListCell *cell = (NCNotificationListCell *)[[self collectionView] _visibleCellForIndexPath:[self _adjustedSectionIndexPathForCollectionViewOperation:path]];
// NSLog(@"NOTIFICATION REMOVAL:\n CELL: %@\nPATH: %@\n,ADJUSTED PATH: %@", cell, path, [self _adjustedSectionIndexPathForCollectionViewOperation:path]);
// if (cell) {
// NSLog(@"NOTIFICATION REMOVAL:\n CELL: %@\nPATH: %@\n,ADJUSTED PATH: %@\nCELL OVER: %@\nCELL UNDER: %@", cell, path, [self _adjustedSectionIndexPathForCollectionViewOperation:path], cell.cellOver, cell.cellUnder);
// if (cell.cellOver && [cell.cellOver respondsToSelector:@selector(itxBackgroundView)]) {
// [((id<ITXHasRoundedBackground>)cell.cellOver).itxBackgroundView setBottomRadius:0];
// [((id<ITXHasRoundedBackground>)cell.cellOver).itxBackgroundView setBottomClipPercent:0];
// NSLog(@"ITX BACKGROUND OVER: %@", ((id<ITXHasRoundedBackground>)cell.cellOver).itxBackgroundView);
// }
// if (cell.cellUnder && [cell.cellUnder respondsToSelector:@selector(itxBackgroundView)]) {
// [((id<ITXHasRoundedBackground>)cell.cellUnder).itxBackgroundView setTopRadius:0];
// [((id<ITXHasRoundedBackground>)cell.cellUnder).itxBackgroundView setTopClipPercent:0];
// NSLog(@"ITX BACKGROUND UNDER: %@", ((id<ITXHasRoundedBackground>)cell.cellUnder).itxBackgroundView);
// }
// cell.cellOver = nil;
// cell.cellUnder = nil;
// }
//5 [[[self collectionView] collectionViewLayout] invalidateLayout];
//[[[self collectionView] collectionViewLayout] invalidateLayout];
[self _performCollectionViewOperationBlockIfNecessary:^{
BOOL hadFooter = NO;
ITXNCGroupFooterView *footer = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
if (footer) {
hadFooter = !footer.isExpanded;
}
[[[self collectionView] collectionViewLayout] invalidateLayout];
//[[[self collectionView] collectionViewLayout] invalidateLayout];
NSUInteger section = [path section];
if ([self.sectionList sectionIsCollapsed:section] || (hadFooter && ![self.sectionList sectionHasFooter:section])) {
NSMutableArray *indexPaths = [NSMutableArray new];
for (int x = [path row]; x < [self.sectionList rowCountForSectionIndex:section]; x++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:x inSection:[self _adjustedSectionIndexForCollectionViewOperation:section]]];
}
if ([indexPaths count] > 0) {
// HBLogInfo(@"Reloading Items: %@", indexPaths);
// HBLogInfo(@"Nubmer of Items In Section Before Reload: %@", @([self.collectionView numberOfItemsInSection:[self _adjustedSectionIndexForCollectionViewOperation:section]]));
[[self collectionView] reloadItemsAtIndexPaths:[indexPaths copy]];
} else {
// NSLog(@"PATH TO BE RELOADED: %@", path);
// if ([self.sectionList rowCountForSectionIndex:section] >= [path row] + 1) {
// [[self collectionView] reloadItemsAtIndexPaths:@[[self _adjustedSectionIndexPathForCollectionViewOperation:path]]];
// }
}
} else {
// HBLogInfo(@"Deleting Items: %@", @[[self _adjustedSectionIndexPathForCollectionViewOperation:path]]);
//NSIndexPath *newPath = [NSIndexPath indexPathForRow:[path row] inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]];
[[self collectionView] deleteItemsAtIndexPaths:@[[self _adjustedSectionIndexPathForCollectionViewOperation:path]]];
// if ([path row] > 0) {
// [[self collectionView] reloadItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:[path row] - 1 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]],nil]];
// }
// if ([path row] + 1 < [self.sectionList rowCountForSectionIndex:section]) {
// [[self collectionView] reloadItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:[path row] + 1 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]],nil]];
// }
}
//if ([self.sectionList otherSectionIdentifierForSectionIndex:section] == request.sectionIdentifier) {
ITXNCGroupFooterView *footerView = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
if (footerView) {
footerView.numberToShow = [self.sectionList actualNumberOfNotificationsInSection:[path section]] - 3;
footerView.cellDelegate = self;
footerView.sectionIdentifier = [self.sectionList otherSectionIdentifierForSectionIndex:[path section]];
footerView.isExpanded = [self.sectionList sectionIsExpanded:[path section]];
//NCNotificationListCell *lastCell = (NCNotificationListCell *)[[self collectionView] _visibleCellForIndexPath:[NSIndexPath indexPathForRow:[self.sectionList rowCountForSectionIndex:section] - 1 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
// if (lastCell && [lastCell respondsToSelector:@selector(itxBackgroundView)]) {
// [lastCell.itxBackgroundView setTopRadius:0 bottomRadius:0 withDelay:0];
// lastCell.itxBackgroundView.topClipPercent = 0;
// lastCell.itxBackgroundView.bottomClipPercent = 0;
// }
// if ([self.sectionList actualNumberOfNotificationsInSection:section] < 4) {
// [self.collectionView.collectionViewLayout invalidateLayout];
// [self.collectionView setCollectionViewLayout:self.collectionView.collectionViewLayout];
// }
} else {
// NCNotificationListCell *lastCell = (NCNotificationListCell *)[[self collectionView] _visibleCellForIndexPath:[NSIndexPath indexPathForRow:[self.sectionList rowCountForSectionIndex:section] - 1 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
// if (lastCell && [lastCell respondsToSelector:@selector(itxBackgroundView)]) {
// [lastCell.itxBackgroundView setTopRadius:0 bottomRadius:1 withDelay:0];
// lastCell.itxBackgroundView.topClipPercent = 0;
// lastCell.itxBackgroundView.bottomClipPercent = 0;
// }
}
//}
}];
}
%new
- (void)notificationSectionList:(NCNotificationChronologicalList *)sectionList didInsertNotificationRequests:(NSArray<NCNotificationRequest *> *)requests atIndexPaths:(NSArray<NSIndexPath *> *)paths reloadIndexPaths:(NSArray<NSIndexPath *> *)reloadPaths {
// HBLogInfo(@"Method #35");
[self _performCollectionViewOperationBlockIfNecessary:^{
NSMutableArray *modifiedPaths = [NSMutableArray new];
for (NSIndexPath *path in paths) {
[modifiedPaths addObject:[self _adjustedSectionIndexPathForCollectionViewOperation:path]];
}
[[self collectionView] insertItemsAtIndexPaths:[modifiedPaths copy]];
for (NSIndexPath *path in reloadPaths) {
int numInSection = [self.sectionList rowCountForSectionIndex:[path section]];
NCNotificationListCell *cell = (NCNotificationListCell *)[[self collectionView] cellForItemAtIndexPath:[self _adjustedSectionIndexPathForCollectionViewOperation:path]];
if (cell) {
cell.hasFooterUnder = [self.sectionList sectionHasFooter:[path section]];
cell.isLastInSection = numInSection - 1 == [path row];
cell._isFirstInSection = [path row] == 0;
cell.cellOver = nil;
cell.cellUnder = nil;
}
}
if ([paths count] > 0) {
NSIndexPath *path = (NSIndexPath *)[paths objectAtIndex:0];
path = [NSIndexPath indexPathForRow:0 inSection:[path section]];
ITXNCGroupFooterView *footerView = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
if (footerView) {
footerView.numberToShow = [self.sectionList actualNumberOfNotificationsInSection:[path section]] - 3;
footerView.cellDelegate = self;
footerView.sectionIdentifier = [self.sectionList otherSectionIdentifierForSectionIndex:[path section]];
footerView.isExpanded = [self.sectionList sectionIsExpanded:[path section]];
// if (![self.sectionList sectionIsCollapsed:section]) {
// [self.collectionView.collectionViewLayout invalidateLayout];
// }
}
}
// if ([reloadPaths count] > 0) {
// NSUInteger section = [[reloadPaths objectAtIndex:0] section];
// ITXNCGroupFooterView *footer = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:section]];
// if (footer) {
// footer.isExpanded = [self.sectionList sectionIsExpanded:section];
// }
// }
//[[self collectionView] reloadItemsAtIndexPaths:[paths copy]];
}];
}
%new
- (void)notificationSectionList:(NCNotificationChronologicalList *)sectionList didRemoveNotificationRequests:(NSArray<NCNotificationRequest *> *)requests atIndexPaths:(NSArray<NSIndexPath *> *)paths reloadIndexPaths:(NSArray<NSIndexPath *> *)reloadPaths {
// HBLogInfo(@"Method #35");
[self _performCollectionViewOperationBlockIfNecessary:^{
NSMutableArray *modifiedPaths = [NSMutableArray new];
for (NSIndexPath *path in paths) {
[modifiedPaths addObject:[self _adjustedSectionIndexPathForCollectionViewOperation:path]];
}
// HBLogInfo(@"Deleting Items A: %@", modifiedPaths);
[[self collectionView] deleteItemsAtIndexPaths:[modifiedPaths copy]];
for (NSIndexPath *path in reloadPaths) {
int numInSection = [self.sectionList rowCountForSectionIndex:[path section]];
NCNotificationListCell *cell = (NCNotificationListCell *)[[self collectionView] cellForItemAtIndexPath:[self _adjustedSectionIndexPathForCollectionViewOperation:path]];
if (cell) {
cell.hasFooterUnder = [self.sectionList sectionHasFooter:[path section]];
cell.isLastInSection = numInSection - 1 == [path row];
cell._isFirstInSection = [path row] == 0;
cell.cellOver = nil;
cell.cellUnder = nil;
}
}
if ([paths count] > 0) {
NSIndexPath *path = (NSIndexPath *)[paths objectAtIndex:0];
path = [NSIndexPath indexPathForRow:0 inSection:[path section]];
ITXNCGroupFooterView *footerView = (ITXNCGroupFooterView *)[[self collectionView] _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[self _adjustedSectionIndexForCollectionViewOperation:[path section]]]];
if (footerView) {
footerView.numberToShow = [self.sectionList actualNumberOfNotificationsInSection:[path section]] - 3;
footerView.cellDelegate = self;
footerView.sectionIdentifier = [self.sectionList otherSectionIdentifierForSectionIndex:[path section]];
footerView.isExpanded = [self.sectionList sectionIsExpanded:[path section]];
// if (![self.sectionList sectionIsCollapsed:section]) {
// [self.collectionView.collectionViewLayout invalidateLayout];
// }
}
}
}];
}
- (void)_updateSectionHeadersRevealHintingForRevealPercentage:(CGFloat)percentage {
// HBLogInfo(@"Method #36");
%orig;
// NSArray<NSIndexPath *> *paths = [[self collectionView] indexPathsForVisibleSupplementaryElementsOfKind:[ITXNCGroupBackgroundView elementKind]];
// paths = [self _filteredIndexPathsForAnimationFromIndexPaths:paths];
// for (NSIndexPath *path in paths) {
// //if (!([path section] < [self.notificationPriorityList sectionCount])) {
// ITXNCGroupBackgroundView *backgroundView = (ITXNCGroupBackgroundView *)[[self collectionView] supplementaryViewForElementKind:[ITXNCGroupBackgroundView elementKind] atIndexPath:path];
// //UICollectionViewLayoutAttributes *attributes = [[self collectionView] layoutAttributesForSupplementaryElementOfKind:[ITXNCGroupBackgroundView elementKind] atIndexPath:indexPath];
// if (backgroundView) {
// UICollectionViewLayoutAttributes *attributes = [[self collectionView] layoutAttributesForSupplementaryElementOfKind:[ITXNCGroupBackgroundView elementKind] atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[path section]]];
// if (attributes) {
// [self _updateSupplementaryView:backgroundView layoutAttributes:attributes forRevealPercentage:percentage atIndexPath:path];
// }
// //[self _updateSupplementaryView:backgroundView layoutAttributes: forRevealPercentage:r15 atIndexPath:r9];
// }
// //}
// }
// NSArray<NSIndexPath *> *paths1 = [[self collectionView] indexPathsForVisibleSupplementaryElementsOfKind:@"UICollectionElementKindSectionFooter"];
// paths1 = [self _filteredIndexPathsForAnimationFromIndexPaths:paths1];
// for (NSIndexPath *path in paths1) {
// //if (!([path section] < [self.notificationPriorityList sectionCount])) {
// ITXNCGroupFooterView *footerView = (ITXNCGroupFooterView *)[[self collectionView] supplementaryViewForElementKind:@"UICollectionElementKindSectionFooter" atIndexPath:path];
// //UICollectionViewLayoutAttributes *attributes = [[self collectionView] layoutAttributesForSupplementaryElementOfKind:[ITXNCGroupBackgroundView elementKind] atIndexPath:indexPath];
// if (footerView) {
// UICollectionViewLayoutAttributes *attributes = [[self collectionView] layoutAttributesForSupplementaryElementOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[path section]]];
// if (attributes) {
// [self _updateSupplementaryView:footerView layoutAttributes:attributes forRevealPercentage:percentage atIndexPath:path];
// }
// //[self _updateSupplementaryView:backgroundView layoutAttributes: forRevealPercentage:r15 atIndexPath:r9];
// }
// //}
// }
}
- (BOOL)removeNotificationRequest:(NCNotificationRequest *)request forCoalescedNotification:(id)arg2 {
// HBLogInfo(@"Method #37");
// HBLogInfo(@"Removing Request: %@", request);
if (request && [self.notificationPriorityList containsNotificationRequest:request]) {
// HBLogInfo(@"Removing Priority Notification");
NSIndexPath *path = [self.notificationPriorityList itx_removeNotificationRequest:request];
if (path) {
[[[self collectionView] collectionViewLayout] invalidateLayout];
[self.collectionView reloadData];
[self _updatePrioritySectionLowestPosition];
[self.collectionView layoutSubviews];
return YES;
} else {
return NO;
}
}
return %orig;
}
- (BOOL)modifyNotificationRequest:(NCNotificationRequest *)request forCoalescedNotification:(id)arg2 {
// HBLogInfo(@"Method #38");
if ([self.notificationPriorityList containsNotificationRequest:request]) {
NSIndexPath *path = [self.notificationPriorityList itx_modifyNotificationRequest:request];
if (path) {
[[[self collectionView] collectionViewLayout] invalidateLayout];
[self.collectionView reloadData];
[self _updatePrioritySectionLowestPosition];
[self.collectionView layoutSubviews];
return YES;
} else {
return NO;
}
} else {
return %orig;
}
}
- (BOOL)insertNotificationRequest:(NCNotificationRequest *)request forCoalescedNotification:(id)arg2 {
//BOOL hasContent = [self hasContent];
// HBLogInfo(@"Method #39");
if ([self.notificationPriorityList containsNotificationRequestMatchingRequest:request]) {
BOOL result = [self modifyNotificationRequest:request forCoalescedNotification:arg2];
if (result) {
//if (!hasContent) {
[self notifyContentObservers];
//}
}
return result;
} else {
BOOL isForLockScreen = [self _isNotificationRequestForLockScreenNotificationDestination:request];
if (isForLockScreen) {
BOOL sectionListContainsNotification = [self.sectionList containsNotificationRequest:request];
if (sectionListContainsNotification) {
[self.sectionList removeNotificationRequest:request];
}
if ([self.notificationPriorityList count] < 1) {
[self _createRequestOperationAnimationCoordinatorForInitialContentPresentation:YES];
}
NSIndexPath *insertedPath = [self.notificationPriorityList itx_insertNotificationRequest:request];
if (insertedPath) {
BOOL isFirst = NO;
if ([insertedPath section] == 0 && [insertedPath row] == 0) {
isFirst = YES;
}
if (isFirst) {
[self _updateRaiseToListenRequest];
}
[[[self collectionView] collectionViewLayout] invalidateLayout];
[self.collectionView reloadData];
[self _updatePrioritySectionLowestPosition];
[self.collectionView layoutSubviews];
}
}
}
return %orig;
}
- (NSUInteger)_adjustedSectionIndexForListOperation:(NSUInteger)sectionIndex {
// HBLogInfo(@"Method #40");
sectionIndex -= [self.notificationPriorityList sectionCount];
return sectionIndex;
}
- (NSUInteger)_adjustedSectionIndexForCollectionViewOperation:(NSUInteger)sectionIndex {
// HBLogInfo(@"Method #41");
sectionIndex += [self.notificationPriorityList sectionCount];
return sectionIndex;
}
- (NCNotificationRequest *)notificationRequestAtIndexPath:(NSIndexPath *)indexPath {
// HBLogInfo(@"Method #42");
if ([indexPath section] < [self.notificationPriorityList sectionCount]) {
return [self.notificationPriorityList notificationRequestAtIndexPath:indexPath];
} else {
return [self.sectionList notificationRequestAtIndexPath:[self _adjustedSectionIndexPathForListOperation:indexPath]];
}
}
- (NSUInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
// HBLogInfo(@"Method #43");
NSUInteger priorityCount = [self.notificationPriorityList sectionCount];
NSUInteger historyCount = [self.sectionList sectionCount];
return priorityCount + historyCount;
}
- (NSUInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSUInteger)section {
// HBLogInfo(@"Method #44");
if (section < [self.notificationPriorityList sectionCount]) {
return [self.notificationPriorityList rowCountForSectionIndex:section];
} else {
return [self.sectionList rowCountForSectionIndex:[self _adjustedSectionIndexForListOperation:section]];
}
}
- (NSIndexPath *)indexPathForNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #45");
NSIndexPath *priorityPath = [self.notificationPriorityList indexPathForNotificationRequest:request];
if (priorityPath != nil) {
return priorityPath;
} else {
return %orig;
}
}
- (NSMutableArray<NSIndexPath *> *)_filteredIndexPathsForAnimationFromIndexPaths:(NSArray<NSIndexPath *> *)indexPaths {
// HBLogInfo(@"Method #46");
NSUInteger lastPrioritySection = [self.notificationPriorityList sectionCount] - 1;
NSMutableArray<NSIndexPath *> *newPaths = [NSMutableArray new];
for (NSIndexPath *path in indexPaths) {
if ([path section] > lastPrioritySection) {
[newPaths addObject:path];
}
}
return newPaths;
}
- (void)viewDidAppear:(BOOL)didAppear {
// HBLogInfo(@"Method #47");
%orig;
if (self.collectionView) {
[[[self collectionView] collectionViewLayout] invalidateLayout];
[self.collectionView reloadData];
[self.collectionView layoutSubviews];
}
}
- (void)_updatePrioritySectionLowestPosition {
// HBLogInfo(@"Method #48");
NSInteger priorityHighestSection = [self.notificationPriorityList sectionCount] - 1;
UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForSupplementaryElementOfKind:[ITXNCGroupBackgroundView elementKind] atIndexPath:[NSIndexPath indexPathForRow:0 inSection:priorityHighestSection]];
if (attributes) {
self.prioritySectionLowestPosition = attributes.frame.origin.y + attributes.frame.size.height;
}
}
%end