-
Notifications
You must be signed in to change notification settings - Fork 73
/
SettingsViewController.m
executable file
·643 lines (579 loc) · 29.1 KB
/
SettingsViewController.m
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
//
// SettingsViewController.m
// BHTwitter
//
// Created by BandarHelal
//
#import "SettingsViewController.h"
@interface SettingsViewController ()
@property (nonatomic, assign) BOOL hasDynamicSpecifiers;
@property (nonatomic, retain) NSMutableDictionary *dynamicSpecifiers;
@end
@implementation SettingsViewController
- (instancetype)init {
self = [super init];
if (self) {
[self setupAppearance];
}
return self;
}
- (void)setupAppearance {
self.title = @"BHTikTok";
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tableViewBackgroundColor = [UIColor blackColor];
appearanceSettings.tableViewCellBackgroundColor = [UIColor colorWithRed: 25.0/255.0 green: 25.0/255.0 blue: 25.0/255.0 alpha: 1.0];
self.hb_appearanceSettings = appearanceSettings;
} else {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tableViewCellBackgroundColor = [UIColor whiteColor];
self.hb_appearanceSettings = appearanceSettings;
}
}
- (UITableViewStyle)tableViewStyle {
return UITableViewStyleInsetGrouped;
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
[self updateColorsForCurrentTraitCollection];
}
}
- (void)updateColorsForCurrentTraitCollection {
if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tableViewBackgroundColor = [UIColor blackColor];
appearanceSettings.tableViewCellBackgroundColor = [UIColor colorWithRed: 25.0/255.0 green: 25.0/255.0 blue: 25.0/255.0 alpha: 1.0];
self.hb_appearanceSettings = appearanceSettings;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
} else {
HBAppearanceSettings *appearanceSettings = [[HBAppearanceSettings alloc] init];
appearanceSettings.tableViewBackgroundColor = [UIColor systemBackgroundColor];
appearanceSettings.tableViewCellBackgroundColor = [UIColor whiteColor];
self.hb_appearanceSettings = appearanceSettings;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
}
- (PSSpecifier *)newSectionWithTitle:(NSString *)header footer:(NSString *)footer {
PSSpecifier *section = [PSSpecifier preferenceSpecifierNamed:header target:self set:nil get:nil detail:nil cell:PSGroupCell edit:nil];
if (footer != nil) {
[section setProperty:footer forKey:@"footerText"];
}
return section;
}
- (PSSpecifier *)newLinkListCellWithTitle:(NSString *)titleText key:(NSString *)keyText defaultValue:(NSNumber *)defValue dynamicRule:(NSString *)rule validTitles:(NSMutableArray <NSString *> *)validTitles validValues:(NSMutableArray<NSMutableDictionary *> *)validValues {
PSSpecifier *linkListCell = [PSSpecifier preferenceSpecifierNamed:titleText target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:PSListItemsController.class cell:PSLinkListCell edit:nil];
[linkListCell setProperty:keyText forKey:@"key"];
[linkListCell setProperty:defValue forKey:@"default"];
[linkListCell setValues:validValues titles:validTitles];
if (rule != nil) {
[linkListCell setProperty:rule forKey:@"dynamicRule"];
}
return linkListCell;
}
- (PSSpecifier *)newEditTextCellWithLabel:(NSString *)labeltext placeholder:(NSString *)placeholder keyboardType:(NSString *)keyboardType dynamicRule:(NSString *)rule key:(NSString *)keyText {
PSSpecifier *editTextCell = [PSSpecifier preferenceSpecifierNamed:labeltext target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:nil cell:PSEditTextCell edit:nil];
[editTextCell setProperty:keyText forKey:@"key"];
[editTextCell setProperty:keyText forKey:@"id"];
[editTextCell setProperty:labeltext forKey:@"label"];
[editTextCell setProperty:placeholder forKey:@"placeholder"];
[editTextCell setProperty:keyboardType forKey:@"keyboardType"];
[editTextCell setProperty:NSBundle.mainBundle.bundleIdentifier forKey:@"defaults"];
if (rule != nil) {
[editTextCell setProperty:rule forKey:@"dynamicRule"];
}
return editTextCell;
}
- (PSSpecifier *)newSwitchCellWithTitle:(NSString *)titleText detailTitle:(NSString *)detailText key:(NSString *)keyText defaultValue:(BOOL)defValue changeAction:(SEL)changeAction {
PSSpecifier *switchCell = [PSSpecifier preferenceSpecifierNamed:titleText target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:nil cell:PSSwitchCell edit:nil];
[switchCell setProperty:keyText forKey:@"key"];
[switchCell setProperty:keyText forKey:@"id"];
[switchCell setProperty:@YES forKey:@"big"];
[switchCell setProperty:BHSwitchTableCell.class forKey:@"cellClass"];
[switchCell setProperty:NSBundle.mainBundle.bundleIdentifier forKey:@"defaults"];
[switchCell setProperty:@(defValue) forKey:@"default"];
[switchCell setProperty:NSStringFromSelector(changeAction) forKey:@"switchAction"];
if (detailText != nil) {
[switchCell setProperty:detailText forKey:@"subtitle"];
}
return switchCell;
}
- (PSSpecifier *)newButtonCellWithTitle:(NSString *)titleText detailTitle:(NSString *)detailText dynamicRule:(NSString *)rule action:(SEL)action {
PSSpecifier *buttonCell = [PSSpecifier preferenceSpecifierNamed:titleText target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:nil cell:PSButtonCell edit:nil];
[buttonCell setButtonAction:action];
[buttonCell setProperty:@YES forKey:@"big"];
[buttonCell setProperty:BHButtonTableViewCell.class forKey:@"cellClass"];
if (detailText != nil ){
[buttonCell setProperty:detailText forKey:@"subtitle"];
}
if (rule != nil) {
[buttonCell setProperty:@44 forKey:@"height"];
[buttonCell setProperty:rule forKey:@"dynamicRule"];
}
return buttonCell;
}
- (PSSpecifier *)newHBLinkCellWithTitle:(NSString *)titleText detailTitle:(NSString *)detailText url:(NSString *)url {
PSSpecifier *HBLinkCell = [PSSpecifier preferenceSpecifierNamed:titleText target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:nil cell:PSButtonCell edit:nil];
[HBLinkCell setButtonAction:@selector(hb_openURL:)];
[HBLinkCell setProperty:HBLinkTableCell.class forKey:@"cellClass"];
[HBLinkCell setProperty:url forKey:@"url"];
if (detailText != nil) {
[HBLinkCell setProperty:detailText forKey:@"subtitle"];
}
return HBLinkCell;
}
- (PSSpecifier *)newHBTwitterCellWithTitle:(NSString *)titleText twitterUsername:(NSString *)user customAvatarURL:(NSString *)avatarURL {
PSSpecifier *TwitterCell = [PSSpecifier preferenceSpecifierNamed:titleText target:self set:@selector(setPreferenceValue:specifier:) get:@selector(readPreferenceValue:) detail:nil cell:1 edit:nil];
[TwitterCell setButtonAction:@selector(hb_openURL:)];
[TwitterCell setProperty:HBTwitterCell.class forKey:@"cellClass"];
[TwitterCell setProperty:user forKey:@"user"];
[TwitterCell setProperty:@YES forKey:@"big"];
[TwitterCell setProperty:@56 forKey:@"height"];
[TwitterCell setProperty:avatarURL forKey:@"iconURL"];
return TwitterCell;
}
- (NSArray *)specifiers {
if (!_specifiers) {
NSArray *regionTitles = @[@"Saudi Arabia 🇸🇦", @"Taiwan 🇹🇼", @"Hong Kong 🇭🇰", @"Macao 🇲🇴", @"Japan 🇯🇵", @"South Korea 🇰🇷", @"United Kingdom 🇬🇧", @"United States 🇺🇸", @"Australia 🇦🇺", @"Canada 🇨🇦", @"Argentina 🇦🇷", @"Philippines 🇵🇭", @"Laos 🇱🇦", @"Malaysia 🇲🇾", @"Thailand 🇹🇭", @"Singapore 🇸🇬", @"Indonesia 🇮🇩", @"Vietnam 🇻🇳", @"Anguilla 🇦🇮", @"Panama 🇵🇦", @"Germany 🇩🇪", @"Russia 🇷🇺", @"France 🇫🇷", @"Finland 🇫🇮", @"Italy 🇮🇹", @"Pakistan 🇵🇰", @"Denmark 🇩🇰", @"Norway 🇳🇴", @"Sudan 🇸🇩", @"Romania 🇷🇴", @"United Arab Emirates 🇦🇪", @"Egypt 🇪🇬", @"Lebanon 🇱🇧", @"Mexico 🇲🇽", @"Brazil 🇧🇷", @"Turkey 🇹🇷", @"Kuwait 🇰🇼", @"Algeria 🇩🇿"];
NSArray *regionCodes = @[
@{
@"area": @"Saudi Arabia 🇸🇦",
@"code": @"SA",
@"mcc": @"420",
@"mnc": @"01"
},
@{
@"area": @"Taiwan 🇹🇼",
@"code": @"TW",
@"mcc": @"466",
@"mnc": @"01"
},
@{
@"area": @"Hong Kong 🇭🇰",
@"code": @"HK",
@"mcc": @"454",
@"mnc": @"00"
},
@{
@"area": @"Macao 🇲🇴",
@"code": @"MO",
@"mcc": @"455",
@"mnc": @"00"
},
@{
@"area": @"Japan 🇯🇵",
@"code": @"JP",
@"mcc": @"440",
@"mnc": @"00"
},
@{
@"area": @"South Korea 🇰🇷",
@"code": @"KR",
@"mcc": @"450",
@"mnc": @"05"
},
@{
@"area": @"United Kingdom 🇬🇧",
@"code": @"GB",
@"mcc": @"234",
@"mnc": @"30"
},
@{
@"area": @"United States 🇺🇸",
@"code": @"US",
@"mcc": @"310",
@"mnc": @"00"
},
@{
@"area": @"Australia 🇦🇺",
@"code": @"AU",
@"mcc": @"505",
@"mnc": @"02"
},
@{
@"area": @"Canada 🇨🇦",
@"code": @"CA",
@"mcc": @"302",
@"mnc": @"720"
},
@{
@"area": @"Argentina 🇦🇷",
@"code": @"AR",
@"mcc": @"722",
@"mnc": @"07"
},
@{
@"area": @"Philippines 🇵🇭",
@"code": @"PH",
@"mcc": @"515",
@"mnc": @"02"
},
@{
@"area": @"Laos 🇱🇦",
@"code": @"LA",
@"mcc": @"457",
@"mnc": @"01"
},
@{
@"area": @"Malaysia 🇲🇾",
@"code": @"MY",
@"mcc": @"502",
@"mnc": @"13"
},
@{
@"area": @"Thailand 🇹🇭",
@"code": @"TH",
@"mcc": @"520",
@"mnc": @"18"
},
@{
@"area": @"Singapore 🇸🇬",
@"code": @"SG",
@"mcc": @"525",
@"mnc": @"01"
},
@{
@"area": @"Indonesia 🇮🇩",
@"code": @"ID",
@"mcc": @"510",
@"mnc": @"01"
},
@{
@"area": @"Vietnam 🇻🇳",
@"code": @"VN",
@"mcc": @"452",
@"mnc": @"01"
},
@{
@"area": @"Anguilla 🇦🇮",
@"code": @"AI",
@"mcc": @"365",
@"mnc": @"840"
},
@{
@"area": @"Panama 🇵🇦",
@"code": @"PA",
@"mcc": @"714",
@"mnc": @"04"
},
@{
@"area": @"Germany 🇩🇪",
@"code": @"DE",
@"mcc": @"262",
@"mnc": @"01"
},
@{
@"area": @"Russia 🇷🇺",
@"code": @"RU",
@"mcc": @"250",
@"mnc": @"01"
},
@{
@"area": @"France 🇫🇷",
@"code": @"FR",
@"mcc": @"208",
@"mnc": @"10"
},
@{
@"area": @"Finland 🇫🇮",
@"code": @"FI",
@"mcc": @"244",
@"mnc": @"91"
},
@{
@"area": @"Italy 🇮🇹",
@"code": @"IT",
@"mcc": @"222",
@"mnc": @"10"
},
@{
@"area": @"Pakistan 🇵🇰",
@"code": @"PK",
@"mcc": @"410",
@"mnc": @"01"
},
@{
@"area": @"Denmark 🇩🇰",
@"code": @"DK",
@"mcc": @"238",
@"mnc": @"01"
},
@{
@"area": @"Norway 🇳🇴",
@"code": @"NO",
@"mcc": @"242",
@"mnc": @"01"
},
@{
@"area": @"Sudan 🇸🇩",
@"code": @"SD",
@"mcc": @"634",
@"mnc": @"01"
},
@{
@"area": @"Romania 🇷🇴",
@"code": @"RO",
@"mcc": @"226",
@"mnc": @"01"
},
@{
@"area": @"United Arab Emirates 🇦🇪",
@"code": @"AE",
@"mcc": @"424",
@"mnc": @"02"
},
@{
@"area": @"Egypt 🇪🇬",
@"code": @"EG",
@"mcc": @"602",
@"mnc": @"01"
},
@{
@"area": @"Lebanon 🇱🇧",
@"code": @"LB",
@"mcc": @"415",
@"mnc": @"01"
},
@{
@"area": @"Mexico 🇲🇽",
@"code": @"MX",
@"mcc": @"334",
@"mnc": @"030"
},
@{
@"area": @"Brazil 🇧🇷",
@"code": @"BR",
@"mcc": @"724",
@"mnc": @"06"
},
@{
@"area": @"Turkey 🇹🇷",
@"code": @"TR",
@"mcc": @"286",
@"mnc": @"01"
},
@{
@"area": @"Kuwait 🇰🇼",
@"code": @"KW",
@"mcc": @"419",
@"mnc": @"02"
},
@{
@"area": @"Algeria 🇩🇿",
@"code": @"DZ",
@"mcc": @"603",
@"mnc": @"01"
}
];
PSSpecifier *feedSection = [self newSectionWithTitle:@"Feed" footer:nil];
PSSpecifier *profileSection = [self newSectionWithTitle:@"Profile" footer:nil];
PSSpecifier *countrySection = [self newSectionWithTitle:@"Country" footer:nil];
PSSpecifier *confirmationSection = [self newSectionWithTitle:@"Confirmation" footer:nil];
PSSpecifier *fakeSection = [self newSectionWithTitle:@"Fake" footer:@"if you want the default value leave it blank."];
PSSpecifier *securitySection = [self newSectionWithTitle:@"Security" footer:nil];
PSSpecifier *developer = [self newSectionWithTitle:@"Developer" footer:nil];
PSSpecifier *hideAds = [self newSwitchCellWithTitle:@"No Ads" detailTitle:@"Remove all Ads from TikTok app" key:@"hide_ads" defaultValue:true changeAction:nil];
PSSpecifier *downloadVid = [self newSwitchCellWithTitle:@"Download Videos" detailTitle:@"Download Videos by log press in any video you want." key:@"dw_videos" defaultValue:true changeAction:nil];
PSSpecifier *downloadMis = [self newSwitchCellWithTitle:@"Download Musics" detailTitle:@"Download Musics by log press in any video you want." key:@"dw_musics" defaultValue:true changeAction:nil];
PSSpecifier *hideElementButton = [self newSwitchCellWithTitle:@"Show/Hide UI button" detailTitle:@"A button on the main page to remove UI elements" key:@"remove_elements_button" defaultValue:true changeAction:nil];
PSSpecifier *copyVideoDecription = [self newSwitchCellWithTitle:@"Copy video decription" detailTitle:@"Show new option in long press to copy the video decription" key:@"copy_decription" defaultValue:true changeAction:nil];
PSSpecifier *copyVideoLink = [self newSwitchCellWithTitle:@"Copy video link" detailTitle:@"Show new option in long press to copy the video link" key:@"copy_video_link" defaultValue:true changeAction:nil];
PSSpecifier *copyMusicLink = [self newSwitchCellWithTitle:@"Copy Music link" detailTitle:@"Show new option in long press to copy the music link" key:@"copy_music_link" defaultValue:true changeAction:nil];
PSSpecifier *autoPlay = [self newSwitchCellWithTitle:@"Auto Play Next Video" detailTitle:@"Play next video automatcilly when the post is finished" key:@"auto_play" defaultValue:false changeAction:nil];
PSSpecifier *progressBar = [self newSwitchCellWithTitle:@"Show progress bar" detailTitle:nil key:@"show_porgress_bar" defaultValue:true changeAction:nil];
PSSpecifier *likeConfirmation = [self newSwitchCellWithTitle:@"Confirm like" detailTitle:@"Show alert when you click the like button to confirm the like" key:@"like_confirm" defaultValue:false changeAction:nil];
PSSpecifier *likeCommentConfirmation = [self newSwitchCellWithTitle:@"Confirm comment like" detailTitle:@"Show alert when you click the like button in comment to confirm the like" key:@"like_comment_confirm" defaultValue:false changeAction:nil];
PSSpecifier *dislikeCommentConfirmation = [self newSwitchCellWithTitle:@"Confirm comment dislike" detailTitle:@"Show alert when you click the dislike button in comment to confirm the like" key:@"dislike_comment_confirm" defaultValue:false changeAction:nil];
PSSpecifier *followConfirmation = [self newSwitchCellWithTitle:@"Confirm follow" detailTitle:@"Show alert when you click the follow button to confirm the like" key:@"follow_confirm" defaultValue:false changeAction:nil];
PSSpecifier *profileSave = [self newSwitchCellWithTitle:@"Save profile image" detailTitle:@"Save profile image by long press." key:@"save_profile" defaultValue:true changeAction:nil];
PSSpecifier *profileCopy = [self newSwitchCellWithTitle:@"Copy profile information" detailTitle:@"Copy profile information by long press." key:@"copy_profile_information" defaultValue:true changeAction:nil];
PSSpecifier *extendedBio = [self newSwitchCellWithTitle:@"Extend bio" detailTitle:@"Extend the bio letters by 222 characters" key:@"extended_bio" defaultValue:true changeAction:nil];
PSSpecifier *extendedComment = [self newSwitchCellWithTitle:@"Extend comment" detailTitle:@"Extend the comment letters by 240 characters" key:@"extended_comment" defaultValue:true changeAction:nil];
PSSpecifier *alwaysOpenSafari = [self newSwitchCellWithTitle:@"Always open in Safari" detailTitle:@"Force twitter to open URLs in Safari or your default browser." key:@"openInBrowser" defaultValue:false changeAction:nil];
PSSpecifier *regionSwitch = [self newSwitchCellWithTitle:@"Enable changing region" detailTitle:nil key:@"en_region" defaultValue:false changeAction:nil];
PSSpecifier *regions = [self newLinkListCellWithTitle:@"Regions" key:@"region" defaultValue:@0 dynamicRule:@"en_region, ==, 0" validTitles:regionTitles validValues:regionCodes];
PSSpecifier *fakeVerified = [self newSwitchCellWithTitle:@"Fake verify blue mark" detailTitle:nil key:@"fake_verify" defaultValue:false changeAction:nil];
PSSpecifier *fakeChangesEnabled = [self newSwitchCellWithTitle:@"Enable fake options" detailTitle:nil key:@"en_fake" defaultValue:false changeAction:nil];
PSSpecifier *followerCount = [self newEditTextCellWithLabel:@"Follower count" placeholder:nil keyboardType:@"decimalPad" dynamicRule:@"en_fake, ==, 0" key:@"follower_count"];
PSSpecifier *followingCount = [self newEditTextCellWithLabel:@"Following count" placeholder:nil keyboardType:@"decimalPad" dynamicRule:@"en_fake, ==, 0" key:@"following_count"];
PSSpecifier *appLock = [self newSwitchCellWithTitle:@"Padlock" detailTitle:@"Lock TikTok with passcode" key:@"padlock" defaultValue:false changeAction:nil];
// dvelopers section
PSSpecifier *bandarHL = [self newHBTwitterCellWithTitle:@"BandarHelal" twitterUsername:@"BandarHL" customAvatarURL:@"https://unavatar.io/twitter/BandarHL"];
PSSpecifier *tipJar = [self newHBLinkCellWithTitle:@"Tip Jar" detailTitle:@"Donate Via Paypal" url:@"https://www.paypal.me/BandarHL"];
_specifiers = [NSMutableArray arrayWithArray:@[
feedSection, // 1
hideAds,
downloadVid,
downloadMis,
hideElementButton,
copyVideoDecription,
copyVideoLink,
copyMusicLink,
autoPlay,
progressBar,
profileSection, // 2
profileSave,
profileCopy,
extendedBio,
extendedComment,
confirmationSection, // 3
likeConfirmation,
likeCommentConfirmation,
dislikeCommentConfirmation,
followConfirmation,
countrySection, // 4
regionSwitch,
regions,
fakeSection, // 5
fakeVerified,
fakeChangesEnabled,
followerCount,
followingCount,
securitySection, // 6
alwaysOpenSafari,
appLock,
developer, // 7
bandarHL,
tipJar,
]];
[self collectDynamicSpecifiersFromArray:_specifiers];
}
return _specifiers;
}
- (void)reloadSpecifiers {
[super reloadSpecifiers];
[self collectDynamicSpecifiersFromArray:self.specifiers];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.hasDynamicSpecifiers) {
PSSpecifier *dynamicSpecifier = [self specifierAtIndexPath:indexPath];
BOOL __block shouldHide = false;
[self.dynamicSpecifiers enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
NSMutableArray *specifiers = obj;
if ([specifiers containsObject:dynamicSpecifier]) {
shouldHide = [self shouldHideSpecifier:dynamicSpecifier];
UITableViewCell *specifierCell = [dynamicSpecifier propertyForKey:PSTableCellKey];
specifierCell.clipsToBounds = shouldHide;
}
}];
if (shouldHide) {
return 0;
}
}
return UITableViewAutomaticDimension;
}
- (void)collectDynamicSpecifiersFromArray:(NSArray *)array {
if (!self.dynamicSpecifiers) {
self.dynamicSpecifiers = [NSMutableDictionary new];
} else {
[self.dynamicSpecifiers removeAllObjects];
}
for (PSSpecifier *specifier in array) {
NSString *dynamicSpecifierRule = [specifier propertyForKey:@"dynamicRule"];
if (dynamicSpecifierRule.length > 0) {
NSArray *ruleComponents = [dynamicSpecifierRule componentsSeparatedByString:@", "];
if (ruleComponents.count == 3) {
NSString *opposingSpecifierID = [ruleComponents objectAtIndex:0];
if ([self.dynamicSpecifiers objectForKey:opposingSpecifierID]) {
NSMutableArray *specifiers = [[self.dynamicSpecifiers objectForKey:opposingSpecifierID] mutableCopy];
[specifiers addObject:specifier];
[self.dynamicSpecifiers removeObjectForKey:opposingSpecifierID];
[self.dynamicSpecifiers setObject:specifiers forKey:opposingSpecifierID];
} else {
[self.dynamicSpecifiers setObject:[NSMutableArray arrayWithArray:@[specifier]] forKey:opposingSpecifierID];
}
} else {
[NSException raise:NSInternalInconsistencyException format:@"dynamicRule key requires three components (Specifier ID, Comparator, Value To Compare To). You have %ld of 3 (%@) for specifier '%@'.", ruleComponents.count, dynamicSpecifierRule, [specifier propertyForKey:PSTitleKey]];
}
}
}
self.hasDynamicSpecifiers = (self.dynamicSpecifiers.count > 0);
}
- (DynamicSpecifierOperatorType)operatorTypeForString:(NSString *)string {
NSDictionary *operatorValues = @{ @"==" : @(EqualToOperatorType), @"!=" : @(NotEqualToOperatorType), @">" : @(GreaterThanOperatorType), @"<" : @(LessThanOperatorType) };
return [operatorValues[string] intValue];
}
- (BOOL)shouldHideSpecifier:(PSSpecifier *)specifier {
if (specifier) {
NSString *dynamicSpecifierRule = [specifier propertyForKey:@"dynamicRule"];
NSArray *ruleComponents = [dynamicSpecifierRule componentsSeparatedByString:@", "];
PSSpecifier *opposingSpecifier = [self specifierForID:[ruleComponents objectAtIndex:0]];
id opposingValue = [self readPreferenceValue:opposingSpecifier];
id requiredValue = [ruleComponents objectAtIndex:2];
if ([opposingValue isKindOfClass:NSNumber.class]) {
DynamicSpecifierOperatorType operatorType = [self operatorTypeForString:[ruleComponents objectAtIndex:1]];
switch (operatorType) {
case EqualToOperatorType:
return ([opposingValue intValue] == [requiredValue intValue]);
break;
case NotEqualToOperatorType:
return ([opposingValue intValue] != [requiredValue intValue]);
break;
case GreaterThanOperatorType:
return ([opposingValue intValue] > [requiredValue intValue]);
break;
case LessThanOperatorType:
return ([opposingValue intValue] < [requiredValue intValue]);
break;
}
}
if ([opposingValue isKindOfClass:NSString.class]) {
return [opposingValue isEqualToString:requiredValue];
}
if ([opposingValue isKindOfClass:NSArray.class]) {
return [opposingValue containsObject:requiredValue];
}
}
return NO;
}
- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier {
NSUserDefaults *Prefs = [NSUserDefaults standardUserDefaults];
[Prefs setValue:value forKey:[specifier identifier]];
if (self.hasDynamicSpecifiers) {
NSString *specifierID = [specifier propertyForKey:PSIDKey];
PSSpecifier *dynamicSpecifier = [self.dynamicSpecifiers objectForKey:specifierID];
if (dynamicSpecifier) {
[self.table beginUpdates];
[self.table endUpdates];
}
}
}
- (id)readPreferenceValue:(PSSpecifier *)specifier {
NSUserDefaults *Prefs = [NSUserDefaults standardUserDefaults];
return [Prefs valueForKey:[specifier identifier]]?:[specifier properties][@"default"];
}
@end
@implementation BHButtonTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier specifier:specifier];
if (self) {
NSString *subTitle = [specifier.properties[@"subtitle"] copy];
BOOL isBig = specifier.properties[@"big"] ? ((NSNumber *)specifier.properties[@"big"]).boolValue : NO;
self.detailTextLabel.text = subTitle;
self.detailTextLabel.numberOfLines = isBig ? 0 : 1;
self.detailTextLabel.textColor = [UIColor secondaryLabelColor];
}
return self;
}
@end
@implementation BHSwitchTableCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
if ((self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier specifier:specifier])) {
NSString *subTitle = [specifier.properties[@"subtitle"] copy];
BOOL isBig = specifier.properties[@"big"] ? ((NSNumber *)specifier.properties[@"big"]).boolValue : NO;
self.detailTextLabel.text = subTitle;
self.detailTextLabel.numberOfLines = isBig ? 0 : 1;
self.detailTextLabel.textColor = [UIColor secondaryLabelColor];
if (specifier.properties[@"switchAction"]) {
UISwitch *targetSwitch = ((UISwitch *)[self control]);
NSString *strAction = [specifier.properties[@"switchAction"] copy];
[targetSwitch addTarget:[self cellTarget] action:NSSelectorFromString(strAction) forControlEvents:UIControlEventValueChanged];
}
}
return self;
}
@end