forked from andrewwiik/Intelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNCNotificationPriorityList.xm
351 lines (310 loc) · 9.91 KB
/
NCNotificationPriorityList.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
#import <Intelix/NCNotificationPriorityList.h>
#import <Intelix/ITXNotificationsSection.h>
#import <UserNotificationsKit/NCNotificationRequest.h>
#import <Intelix/ITXHelper.h>
#import <Intelix/NCNotificationCombinedListViewController.h>
static NSMutableArray *notifSections;
NSUInteger cachedCount = 0;
@interface NCNotificationPriorityList ()
@property (nonatomic, retain) NSMutableArray *lSections;
@end
%hook NCNotificationPriorityList
%property (nonatomic, retain) NCNotificationCombinedListViewController *controller;
%property (nonatomic, retain) NSMutableArray *lSections;
%new
- (void)recomputeCount {
// HBLogInfo(@"Method #201");
NSUInteger count = 0;
NSMutableArray *sections = self.sections;
for (ITXNotificationsSection *section in sections) {
count += [section count];
}
cachedCount = count;
}
- (id)init {
// HBLogInfo(@"Method #1");
NCNotificationPriorityList *list = %orig;
if (list) {
self.sections = [NSMutableArray new];
}
return list;
}
%new
- (NSMutableArray *)sections {
// HBLogInfo(@"Method #2");
return notifSections;
NSMutableArray *sections = self.lSections;
if (!sections) {
// HBLogInfo(@"Sections was NULL");
} else {
// HBLogInfo(@"Sections was not NULL");
}
return sections;
}
%new
- (void)setSections:(NSMutableArray *)sections {
// HBLogInfo(@"Method #3");
notifSections = sections;
}
%new
- (NSUInteger)sectionCount {
// HBLogInfo(@"Method #4");
NSUInteger count = [self.sections count];
return count > 0 ? count : 1;
// return [self.sections count];
}
%new
- (NSUInteger)rowCountForSectionIndex:(NSUInteger)section {
// HBLogInfo(@"Method #5");
NSUInteger maxCount = [self.sections count];
if (section < maxCount) {
return [self.sections[section] count];
} else return 0;
}
%new
- (NSUInteger)actualCountInSection:(NSUInteger)section {
// HBLogInfo(@"Method #6");
NSUInteger maxCount = [self.sections count];
if (section < maxCount) {
return [self.sections[section] count];
} else return 0;
}
%new
- (NCNotificationRequest *)notificationRequestAtIndexPath:(NSIndexPath *)indexPath {
// HBLogInfo(@"Method #7");
NSUInteger maxCount = [self.sections count];
if ([indexPath section] < maxCount) {
return [self.sections[[indexPath section]] notificationAtIndex:[indexPath row]];
} else return nil;
}
%new
- (NSIndexPath *)indexPathForNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #8");
NSUInteger maxCount = [self.sections count];
for (NSUInteger x = 0; x < maxCount; x++) {
ITXNotificationsSection *section = self.sections[x];
NSUInteger index = [section indexOfNotification:request];
if (index != NSNotFound) {
return [NSIndexPath indexPathForRow:index inSection:x];
}
}
return nil;
}
%new
- (ITXNotificationsSection *)existingSectionForRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #9");
NSMutableArray *sections = self.sections;
for (ITXNotificationsSection *section in sections) {
if ([section.identifier isEqualToString:request.sectionIdentifier]) return section;
}
return nil;
}
%new
- (ITXNotificationsSection *)newSectionForRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #10");
ITXNotificationsSection *section = [[ITXNotificationsSection alloc] init];
section.title = request.content.header;
section.identifier = request.sectionIdentifier;
section.icon = request.content.icon;
return section;
}
- (NCNotificationRequest *)requestAtIndex:(NSUInteger)index {
// HBLogInfo(@"Method #11");
NSUInteger maxCount = [self.sections count];
if (maxCount > 0) {
NSUInteger count = 0;
for (NSUInteger x = 0; x < maxCount; x++) {
ITXNotificationsSection *section = self.sections[x];
if (index >= count && index < count + [section count]) {
return [section notificationAtIndex:index - count];
} else {
count += [section count];
}
}
}
return nil;
}
- (NSUInteger)_indexOfRequestMatchingNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #12");
NSUInteger count = [self.sections count];
for (NSUInteger x = 0; x < count; x++) {
ITXNotificationsSection *section = self.sections[x];
NSUInteger index = [section indexOfNotification:request];
if (index != NSNotFound) {
return [self countOfNotificationsInSectionsBeforeSection:x] + index;
}
}
return NSNotFound;
}
%new
- (NSUInteger)countOfNotificationsInSectionsBeforeSection:(NSUInteger)section {
// HBLogInfo(@"Method #13");
NSUInteger count = 0;
NSUInteger sectionCount = [self.sections count];
for (NSUInteger x = section - 1; x > -1; x--) {
if (x < sectionCount) {
count += [self.sections[x] count];
}
}
return count;
}
%new
- (NSIndexPath *)itx_removeNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #14");
NSUInteger maxCount = [self.sections count];
NSIndexPath *pathToReturn = nil;
ITXNotificationsSection *sectionToRemove = nil;
for (NSUInteger x = 0; x < maxCount; x++) {
ITXNotificationsSection *section = self.sections[x];
NSUInteger index = [section indexOfNotification:request];
if (index != NSNotFound) {
[section removeNotificationRequest:request];
if ([section count] < 1) {
[self.sections removeObject:section];
sectionToRemove = section;
}
pathToReturn = [NSIndexPath indexPathForRow:index inSection:x];
break;
//return [self countOfNotificationsInSectionsBeforeSection:x] + index;
}
}
if (sectionToRemove) {
[self.sections removeObject:sectionToRemove];
}
[self recomputeCount];
if (pathToReturn) return pathToReturn;
return nil;
}
%new
- (NSIndexPath *)itx_modifyNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #15");
NSUInteger maxCount = [self.sections count];
for (NSUInteger x = 0; x < maxCount; x++) {
ITXNotificationsSection *section = self.sections[x];
NSUInteger index = [section indexOfNotification:request];
if (index != NSNotFound) {
[section modifyNotificationRequest:request];
[self recomputeCount];
return [NSIndexPath indexPathForRow:index inSection:x];
//return [self countOfNotificationsInSectionsBeforeSection:x] + index;
}
}
[self recomputeCount];
return nil;
}
%new
-(NSIndexPath *)itx_insertNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #16");
ITXNotificationsSection *section = [self existingSectionForRequest:request];
if (section) {
NSUInteger index = [self.sections indexOfObject:section];
[self.sections removeObjectAtIndex:index];
[self.sections insertObject:section atIndex:0];
} else {
section = [self newSectionForRequest:request];
[self.sections insertObject:section atIndex:0];
}
[section insertNotificationRequest:request];
NSUInteger index = [section indexOfNotification:request];
// NSUInteger x = [self.sections indexOfObject:section];
NSUInteger indexS = [self.sections indexOfObject:section];
[self.sections removeObjectAtIndex:indexS];
[self.sections insertObject:section atIndex:0];
[ITXHelper setIcon:request.content.icon forIdentifier:request.sectionIdentifier];
[self recomputeCount];
return [NSIndexPath indexPathForRow:index inSection:0];
//return [self countOfNotificationsInSectionsBeforeSection:x] + index;
}
%new
- (BOOL)containsNotificationRequest:(NCNotificationRequest *)request {
// HBLogInfo(@"Method #17");
NSMutableArray *sections = self.sections;
for (ITXNotificationsSection *section in sections) {
if ([section indexOfNotification:request] != NSNotFound) {
return TRUE;
}
}
return FALSE;
}
- (NSMutableOrderedSet *)requests {
// HBLogInfo(@"Method #18");
NSMutableOrderedSet *requests = [NSMutableOrderedSet new];
NSMutableArray *sections = self.sections;
for (ITXNotificationsSection *section in sections) {
[requests addObjectsFromArray:section.notifications];
}
return requests;
}
- (NSUInteger)count {
// HBLogInfo(@"Method #19");
return cachedCount;
}
- (id)clearNonPersistentRequests {
// HBLogInfo(@"Method #20");
return %orig;
}
- (NSMutableSet *)clearRequestsPassingTest:(/*^block*/ id)arg1 {
// HBLogInfo(@"Method #21");
NSMutableSet *cleared = %orig;
//NSMutableArray *removedPaths = [NSMutableArray new];
// for (NCNotificationRequest *request in cleared) {
// NSIndexPath *path = [self itx_removeNotificationRequest:request];
// if (path) [removedPaths addObject:path];
// }
// HBLogInfo(@"Clearing Notifications Passing Test");
[self recomputeCount];
// for (NSIndexPath *path in removedPaths) {
// // HBLogInfo(@"Removed Index with Test: %@", path);
// }
// if (self.controller) {
// [self.controller.collectionView reloadData];
// }
return cleared;
}
- (NSMutableSet *)_clearRequestsWithPersistence:(NSUInteger)persistance {
// HBLogInfo(@"Method #22");
NSMutableSet *removed = [NSMutableSet new];
NSMutableArray *sections = self.sections;
for (ITXNotificationsSection *section in sections) {
NSMutableArray *notifications = [section.notifications mutableCopy];
for (NCNotificationRequest *request in notifications) {
if (request.options && request.options.lockScreenPersistence == persistance) {
[removed addObject:request];
//[section removeNotificationRequest:request];
}
}
}
// NSMutableArray *newSections = [NSMutableArray new];
// for (ITXNotificationsSection *section in sections) {
// if ([section count] > 0) {
// [newSections addObject:section];
// } else {
// }
// }
// self.sections = newSections;
// HBLogInfo(@"Clearing Notifications with Persistance");
// if (self.controller) {
// [self.controller.collectionView reloadData];
// }
[self recomputeCount];
return removed;
}
%new
- (NSString *)titleForSectionIndex:(NSUInteger)section {
// HBLogInfo(@"Method #23");
if (section < [self.sections count]) {
NSString *title = [self.sections[section] title];
NSString *identifier = [self.sections[section] identifier];
return [NSString stringWithFormat:@"%@|%@", title, identifier];
}
return @"";
}
%new
- (NSString *)identifierForSectionIndex:(NSUInteger)section {
// HBLogInfo(@"Method #24");
if (section < [self.sections count]) {
return [self.sections[section] identifier];
}
return @"";
}
%end