forked from NeoFreeBird/tweak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModernSettingsViewController.m
More file actions
2265 lines (2011 loc) · 113 KB
/
ModernSettingsViewController.m
File metadata and controls
2265 lines (2011 loc) · 113 KB
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// ModernSettingsViewController.m
// NeoFreeBird
//
// Created by BandarHelal on 25/11/2021.
//
#import "ModernSettingsViewController.h"
#import "BHTBundle/BHTBundle.h"
#import "BHDimPalette.h"
#import "Colours/Colours.h"
@class TFNTwitterAccount;
@interface GeneralSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface TwitterBlueSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface MediaDownloadsSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface ProfilesSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface TweetsSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface MessagesSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
@interface ExperimentalSettingsViewController : UIViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account;
@end
extern UIColor *BHTCurrentAccentColor(void);
typedef NS_ENUM(NSInteger, TwitterFontStyle) {
TwitterFontStyleRegular,
TwitterFontStyleSemibold,
TwitterFontStyleBold
};
static UIFont *TwitterChirpFont(TwitterFontStyle style) {
switch (style) {
case TwitterFontStyleBold:
return [UIFont fontWithName:@"ChirpUIVF_wght3200000_opsz150000" size:17] ?:
[UIFont systemFontOfSize:17 weight:UIFontWeightBold];
case TwitterFontStyleSemibold:
return [UIFont fontWithName:@"ChirpUIVF_wght2BC0000_opszE0000" size:14] ?:
[UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
case TwitterFontStyleRegular:
default:
return [UIFont fontWithName:@"ChirpUIVF_wght1900000_opszE0000" size:12] ?:
[UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
}
}
@interface ModernSettingsTableViewCell : UITableViewCell
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UIImageView *chevronImageView;
@end
@interface ModernSettingsSimpleButtonCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *chevronImageView;
@end
@interface ModernSettingsCompactButtonCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UIImageView *chevronImageView;
@end
@interface ModernSettingsToggleCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) UISwitch *toggleSwitch;
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle;
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)events;
@end
@interface ModernSettingsViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) TFNTwitterAccount *account;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *sections;
@property (nonatomic, strong) NSArray *developerCells;
@property (nonatomic, strong) NSArray *specialThanksCells;
@property (nonatomic, strong) NSArray *officialPageCells;
@end
@implementation ModernSettingsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setupViews];
[self setupConstraints];
}
return self;
}
- (void)setupViews {
self.iconImageView = [[UIImageView alloc] init];
self.iconImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.iconImageView.contentMode = UIViewContentModeScaleAspectFit;
self.iconImageView.tintColor = [UIColor secondaryLabelColor];
[self.contentView addSubview:self.iconImageView];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.titleLabel.textColor = [UIColor labelColor];
[self.contentView addSubview:self.titleLabel];
self.subtitleLabel = [[UILabel alloc] init];
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
[self updateSubtitleColor];
self.subtitleLabel.numberOfLines = 0;
[self.contentView addSubview:self.subtitleLabel];
self.chevronImageView = [[UIImageView alloc] init];
self.chevronImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.chevronImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:self.chevronImageView];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
self.selectionStyle = UITableViewCellSelectionStyleDefault;
}
- (void)setupConstraints {
[NSLayoutConstraint activateConstraints:@[
[self.iconImageView.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:20],
[self.iconImageView.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.iconImageView.widthAnchor constraintEqualToConstant:20],
[self.iconImageView.heightAnchor constraintEqualToConstant:20],
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.iconImageView.trailingAnchor constant:16],
[self.titleLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:16],
[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.chevronImageView.leadingAnchor constant:-16],
[self.subtitleLabel.leadingAnchor constraintEqualToAnchor:self.titleLabel.leadingAnchor],
[self.subtitleLabel.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:2],
[self.subtitleLabel.trailingAnchor constraintEqualToAnchor:self.titleLabel.trailingAnchor],
[self.subtitleLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-16],
[self.chevronImageView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:-20],
[self.chevronImageView.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.chevronImageView.widthAnchor constraintEqualToConstant:18],
[self.chevronImageView.heightAnchor constraintEqualToConstant:18]
]];
}
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle iconName:(NSString *)iconName {
self.titleLabel.text = title;
self.subtitleLabel.text = subtitle;
objc_setAssociatedObject(self, @selector(iconName), iconName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self updateIconColors];
}
- (void)updateIconColors {
NSString *iconName = objc_getAssociatedObject(self, @selector(iconName));
if (iconName) {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *iconColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.iconImageView.image = [UIImage tfn_vectorImageNamed:iconName fitsSize:CGSizeMake(20, 20) fillColor:iconColor];
}
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *chevronColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.chevronImageView.image = [UIImage tfn_vectorImageNamed:@"chevron_right" fitsSize:CGSizeMake(18, 18) fillColor:chevronColor];
}
- (void)updateSubtitleColor {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *subtitleColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.subtitleLabel.textColor = subtitleColor;
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
[self updateIconColors];
[self updateSubtitleColor];
if (previousTraitCollection.preferredContentSizeCategory != self.traitCollection.preferredContentSizeCategory) {
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
}
}
@end
@implementation ModernSettingsSimpleButtonCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setupViews];
[self setupConstraints];
}
return self;
}
- (void)setupViews {
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.titleLabel.textColor = [UIColor labelColor];
[self.contentView addSubview:self.titleLabel];
self.chevronImageView = [[UIImageView alloc] init];
self.chevronImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.chevronImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:self.chevronImageView];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
self.selectionStyle = UITableViewCellSelectionStyleDefault;
[self updateChevronColor];
}
- (void)setupConstraints {
[NSLayoutConstraint activateConstraints:@[
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:20],
[self.titleLabel.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.chevronImageView.leadingAnchor constant:-16],
[self.titleLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:16],
[self.titleLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-16],
[self.chevronImageView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:-20],
[self.chevronImageView.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.chevronImageView.widthAnchor constraintEqualToConstant:18],
[self.chevronImageView.heightAnchor constraintEqualToConstant:18]
]];
}
- (void)configureWithTitle:(NSString *)title {
self.titleLabel.text = title;
}
- (void)updateChevronColor {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *chevronColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.chevronImageView.image = [UIImage tfn_vectorImageNamed:@"chevron_right" fitsSize:CGSizeMake(18, 18) fillColor:chevronColor];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
[self updateChevronColor];
if (previousTraitCollection.preferredContentSizeCategory != self.traitCollection.preferredContentSizeCategory) {
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
}
}
@end
@implementation ModernSettingsCompactButtonCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setupViews];
[self setupConstraints];
}
return self;
}
- (void)setupViews {
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.titleLabel.textColor = [UIColor labelColor];
[self.contentView addSubview:self.titleLabel];
self.subtitleLabel = [[UILabel alloc] init];
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
self.subtitleLabel.textAlignment = NSTextAlignmentRight;
[self updateSubtitleColor];
[self.contentView addSubview:self.subtitleLabel];
self.chevronImageView = [[UIImageView alloc] init];
self.chevronImageView.translatesAutoresizingMaskIntoConstraints = NO;
self.chevronImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:self.chevronImageView];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
self.selectionStyle = UITableViewCellSelectionStyleDefault;
[self updateChevronColor];
}
- (void)setupConstraints {
[NSLayoutConstraint activateConstraints:@[
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:20],
[self.titleLabel.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.titleLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:16],
[self.titleLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-16],
[self.subtitleLabel.leadingAnchor constraintGreaterThanOrEqualToAnchor:self.titleLabel.trailingAnchor constant:16],
[self.subtitleLabel.trailingAnchor constraintEqualToAnchor:self.chevronImageView.leadingAnchor constant:-8],
[self.subtitleLabel.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.chevronImageView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:-20],
[self.chevronImageView.centerYAnchor constraintEqualToAnchor:self.contentView.centerYAnchor],
[self.chevronImageView.widthAnchor constraintEqualToConstant:18],
[self.chevronImageView.heightAnchor constraintEqualToConstant:18]
]];
[self.titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[self.subtitleLabel setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[self.subtitleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
}
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle {
self.titleLabel.text = title;
self.subtitleLabel.text = subtitle;
}
- (void)updateChevronColor {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *chevronColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.chevronImageView.image = [UIImage tfn_vectorImageNamed:@"chevron_right" fitsSize:CGSizeMake(18, 18) fillColor:chevronColor];
}
- (void)updateSubtitleColor {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *subtitleColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.subtitleLabel.textColor = subtitleColor;
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
self.backgroundColor = [BHDimPalette currentBackgroundColor];
[self updateChevronColor];
[self updateSubtitleColor];
if (previousTraitCollection.preferredContentSizeCategory != self.traitCollection.preferredContentSizeCategory) {
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
}
}
@end
@implementation ModernSettingsToggleCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [BHDimPalette currentBackgroundColor];
self.titleLabel = [UILabel new];
self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.titleLabel];
self.subtitleLabel = [UILabel new];
self.subtitleLabel.numberOfLines = 0;
self.subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.subtitleLabel];
self.toggleSwitch = [UISwitch new];
self.toggleSwitch.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.toggleSwitch];
[self applyTheme];
[NSLayoutConstraint activateConstraints:@[
[self.toggleSwitch.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:-20],
[self.titleLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:20],
[self.titleLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:14],
[self.titleLabel.trailingAnchor constraintEqualToAnchor:self.toggleSwitch.leadingAnchor constant:-16],
[self.toggleSwitch.centerYAnchor constraintEqualToAnchor:self.titleLabel.centerYAnchor],
[self.subtitleLabel.leadingAnchor constraintEqualToAnchor:self.titleLabel.leadingAnchor],
[self.subtitleLabel.trailingAnchor constraintEqualToAnchor:self.titleLabel.trailingAnchor],
[self.subtitleLabel.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:4],
[self.subtitleLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:-14]
]];
}
return self;
}
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle {
self.titleLabel.text = title;
self.subtitleLabel.text = subtitle;
}
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)events {
[self.toggleSwitch addTarget:target action:action forControlEvents:events];
}
- (void)applyTheme {
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
self.titleLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
self.subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id colorPalette = [[settings currentColorPalette] colorPalette];
self.titleLabel.textColor = [colorPalette performSelector:@selector(textColor)];
self.subtitleLabel.textColor = [colorPalette performSelector:@selector(tabBarItemColor)];
self.toggleSwitch.onTintColor = BHTCurrentAccentColor();
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self applyTheme];
}
@end
@implementation ModernSettingsViewController
- (void)colorPickerViewControllerDidSelectColor:(UIColorPickerViewController *)viewController {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"change_msg_background"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"background_image"];
UIColor *selectedColor = viewController.selectedColor;
if ([selectedColor respondsToSelector:@selector(hexString)]) {
[[NSUserDefaults standardUserDefaults] setObject:selectedColor.hexString forKey:@"background_color"];
} else {
// Fallback: convert to hex manually
CGFloat r, g, b, a;
[selectedColor getRed:&r green:&g blue:&b alpha:&a];
NSString *hexString = [NSString stringWithFormat:@"#%02lX%02lX%02lX",
lroundf(r * 255),
lroundf(g * 255),
lroundf(b * 255)];
[[NSUserDefaults standardUserDefaults] setObject:hexString forKey:@"background_color"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - Section Headers
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0) {
// Top subtitle header
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [BHDimPalette currentBackgroundColor];
UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
subtitleLabel.text = [[BHTBundle sharedBundle] localizedStringForKey:@"BHTWITTER_SETTINGS_DETAIL"];
subtitleLabel.numberOfLines = 0;
subtitleLabel.textAlignment = NSTextAlignmentLeft;
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
subtitleLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *subtitleColor = [colorPalette performSelector:@selector(tabBarItemColor)];
subtitleLabel.textColor = subtitleColor;
[headerView addSubview:subtitleLabel];
[NSLayoutConstraint activateConstraints:@[
[subtitleLabel.leadingAnchor constraintEqualToAnchor:headerView.leadingAnchor constant:20],
[subtitleLabel.trailingAnchor constraintEqualToAnchor:headerView.trailingAnchor constant:-20],
[subtitleLabel.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:16],
[subtitleLabel.bottomAnchor constraintEqualToAnchor:headerView.bottomAnchor constant:-16]
]];
return headerView;
}
else if (section == 1) {
// Developers section header
return [self headerViewWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"DEVELOPER_SECTION_HEADER_TITLE"]];
}
else if (section == 2) {
// Special Thanks section header
return [self headerViewWithTitle:
[[BHTBundle sharedBundle] localizedStringForKey:@"SPECIAL_THANKS_SECTION_HEADER_TITLE"]];
}
else if (section == 3) {
// Official Page section header
return [self headerViewWithTitle:
[[BHTBundle sharedBundle] localizedStringForKey:@"FOLLOW_OFFICIAL_PAGE_SECTION_HEADER_TITLE"]];
}
return nil;
}
- (UIView *)headerViewWithTitle:(NSString *)title {
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [BHDimPalette currentBackgroundColor];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
titleLabel.text = title;
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
titleLabel.font = [fontGroup performSelector:@selector(headline1BoldFont)];
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *titleColor = [colorPalette performSelector:@selector(textColor)];
titleLabel.textColor = titleColor;
[headerView addSubview:titleLabel];
[NSLayoutConstraint activateConstraints:@[
[titleLabel.leadingAnchor constraintEqualToAnchor:headerView.leadingAnchor constant:20],
[titleLabel.trailingAnchor constraintEqualToAnchor:headerView.trailingAnchor constant:-20],
[titleLabel.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:32],
[titleLabel.bottomAnchor constraintEqualToAnchor:headerView.bottomAnchor constant:-16]
]];
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0 || section == 1 || section == 2 || section == 3) {
return UITableViewAutomaticDimension;
}
return 0;
}
#pragma mark - Section Footers
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (section == 0) {
UIView *separator = [[UIView alloc] initWithFrame:CGRectZero];
separator.backgroundColor = [UIColor separatorColor];
return separator;
}
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == 0) {
return 1.0 / UIScreen.mainScreen.scale;
}
return CGFLOAT_MIN;
}
- (instancetype)initWithAccount:(TFNTwitterAccount *)account {
self = [super init];
if (self) {
_account = account;
[self setupSections];
[self setupDeveloperCells];
}
return self;
}
- (void)setupSections {
self.sections = @[
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_LAYOUT_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_LAYOUT_SUBTITLE"],
@"icon": @"settings_stroke", @"action": @"showLayoutSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_TWITTER_BLUE_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_TWITTER_BLUE_SUBTITLE"],
@"icon": @"twitter_blue", @"action": @"showTwitterBlueSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_MEDIA_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_MEDIA_SUBTITLE"],
@"icon": @"media_tab_stroke", @"action": @"showDownloadsSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_PROFILES_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_PROFILES_SUBTITLE"],
@"icon": @"account", @"action": @"showProfilesSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_TWEETS_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_TWEETS_SUBTITLE"],
@"icon": @"quill", @"action": @"showTweetsSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_MESSAGES_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_MESSAGES_SUBTITLE"],
@"icon": @"messages_stroke", @"action": @"showMessagesSettings" },
@{ @"title": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_EXPERIMENTAL_TITLE"],
@"subtitle": [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_EXPERIMENTAL_SUBTITLE"],
@"icon": @"flask", @"action": @"showExperimentalSettings" }
];
}
- (void)setupDeveloperCells {
self.developerCells = @[
@{ @"title": @"aridan", @"username": @"actuallyaridan", @"avatarURL": @"https://unavatar.io/x/actuallyaridan", @"userID": @"1351218086649720837" },
@{ @"title": @"timi2506", @"username": @"timi2506", @"avatarURL": @"https://unavatar.io/github/timi2506", @"userID": @"1671731225424195584" },
@{ @"title": @"nyathea", @"username": @"nyaathea", @"avatarURL": @"https://unavatar.io/github/nyathea", @"userID": @"1541742676009226241" }
];
self.specialThanksCells = @[
@{ @"title": @"BandarHelal", @"username": @"BandarHL", @"avatarURL": @"https://unavatar.io/x/BandarHL", @"userID": @"827842200708853762" }
];
self.officialPageCells = @[
@{ @"title": @"NeoFreeBird", @"username": @"NeoFreeBird", @"avatarURL": @"https://unavatar.io/x/NeoFreeBird", @"userID": @"1878595268255297537" }
];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupNavigationBar];
[self setupTableView];
[self setupLayout];
[self setupFooterLabel];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentSizeCategoryDidChange:) name:UIContentSizeCategoryDidChangeNotification object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)contentSizeCategoryDidChange:(NSNotification *)notification {
[self.tableView reloadData];
}
- (void)setupNavigationBar {
self.view.backgroundColor = [BHDimPalette currentBackgroundColor];
if (self.account) {
self.navigationItem.titleView = [objc_getClass("TFNTitleView") titleViewWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"BHTWITTER_SETTINGS_TITLE"] subtitle:self.account.displayUsername];
} else {
self.title = [[BHTBundle sharedBundle] localizedStringForKey:@"BHTWITTER_SETTINGS_TITLE"];
}
}
- (void)setupTableView {
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [BHDimPalette currentBackgroundColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.estimatedRowHeight = 80;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = 50;
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
[self.tableView registerClass:[ModernSettingsTableViewCell class] forCellReuseIdentifier:@"SettingsCell"];
[self.view addSubview:self.tableView];
}
- (void)setupLayout {
[NSLayoutConstraint activateConstraints:@[
[self.tableView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
[self.tableView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[self.tableView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[self.tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
]];
}
- (void)setupFooterLabel {
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)];
footerView.backgroundColor = [BHDimPalette currentBackgroundColor];
UILabel *footerLabel = [[UILabel alloc] init];
footerLabel.translatesAutoresizingMaskIntoConstraints = NO;
footerLabel.text = @"NeoFreeBird v2.0r2 (release)\nNeoFreeBird-BHTwitter v5.1 (release)";
footerLabel.numberOfLines = 0;
footerLabel.textAlignment = NSTextAlignmentLeft; // <-- Left aligned now
// Use Chirp Regular font
footerLabel.font = TwitterChirpFont(TwitterFontStyleRegular);
// Match subtitle color
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *subtitleColor = [colorPalette performSelector:@selector(tabBarItemColor)];
footerLabel.textColor = subtitleColor;
[footerView addSubview:footerLabel];
[NSLayoutConstraint activateConstraints:@[
[footerLabel.leadingAnchor constraintEqualToAnchor:footerView.leadingAnchor constant:20], // match table cell padding
[footerLabel.trailingAnchor constraintEqualToAnchor:footerView.trailingAnchor constant:-20],
[footerLabel.topAnchor constraintEqualToAnchor:footerView.topAnchor constant:8],
[footerLabel.bottomAnchor constraintEqualToAnchor:footerView.bottomAnchor constant:-8]
]];
self.tableView.tableFooterView = footerView;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return self.sections.count;
} else if (section == 1) {
return self.developerCells.count;
} else if (section == 2) {
return self.specialThanksCells.count;
} else if (section == 3) {
return self.officialPageCells.count;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
ModernSettingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SettingsCell"
forIndexPath:indexPath];
NSDictionary *sectionData = self.sections[indexPath.row];
[cell configureWithTitle:sectionData[@"title"]
subtitle:sectionData[@"subtitle"]
iconName:sectionData[@"icon"]];
return cell;
}
else if (indexPath.section == 1) {
return [self developerCellForTableView:tableView
atIndexPath:indexPath
fromArray:self.developerCells];
}
else if (indexPath.section == 2) {
return [self developerCellForTableView:tableView
atIndexPath:indexPath
fromArray:self.specialThanksCells];
}
else if (indexPath.section == 3) {
return [self developerCellForTableView:tableView
atIndexPath:indexPath
fromArray:self.officialPageCells];
}
return nil;
}
- (UITableViewCell *)developerCellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath fromArray:(NSArray *)array {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DeveloperCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DeveloperCell"];
[self setupDeveloperCell:cell];
}
NSDictionary *developer = array[indexPath.row];
[self configureDeveloperCell:cell withDeveloper:developer];
return cell;
}
#pragma mark - Developer Cell Setup
- (void)setupDeveloperCell:(UITableViewCell *)cell {
cell.textLabel.text = nil;
cell.detailTextLabel.text = nil;
cell.imageView.image = nil;
UIImageView *avatarImageView = [[UIImageView alloc] init];
avatarImageView.translatesAutoresizingMaskIntoConstraints = NO;
avatarImageView.layer.cornerRadius = 26;
avatarImageView.clipsToBounds = YES;
avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
avatarImageView.tag = 100;
[cell.contentView addSubview:avatarImageView];
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
nameLabel.tag = 101;
nameLabel.adjustsFontForContentSizeCategory = YES;
[cell.contentView addSubview:nameLabel];
UILabel *usernameLabel = [[UILabel alloc] init];
usernameLabel.translatesAutoresizingMaskIntoConstraints = NO;
usernameLabel.tag = 102;
usernameLabel.adjustsFontForContentSizeCategory = YES;
[cell.contentView addSubview:usernameLabel];
UIImageView *devChevron = [[UIImageView alloc] init];
devChevron.translatesAutoresizingMaskIntoConstraints = NO;
devChevron.tag = 103;
devChevron.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:devChevron];
[NSLayoutConstraint activateConstraints:@[
[avatarImageView.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor constant:20],
[avatarImageView.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor],
[avatarImageView.widthAnchor constraintEqualToConstant:52],
[avatarImageView.heightAnchor constraintEqualToConstant:52],
[nameLabel.leadingAnchor constraintEqualToAnchor:avatarImageView.trailingAnchor constant:12],
[nameLabel.trailingAnchor constraintEqualToAnchor:devChevron.leadingAnchor constant:-12],
[nameLabel.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor constant:16],
[usernameLabel.leadingAnchor constraintEqualToAnchor:nameLabel.leadingAnchor],
[usernameLabel.trailingAnchor constraintEqualToAnchor:devChevron.leadingAnchor constant:-12],
[usernameLabel.topAnchor constraintEqualToAnchor:nameLabel.bottomAnchor constant:2],
[usernameLabel.bottomAnchor constraintEqualToAnchor:cell.contentView.bottomAnchor constant:-16],
[devChevron.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-20],
[devChevron.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor],
[devChevron.widthAnchor constraintEqualToConstant:18],
[devChevron.heightAnchor constraintEqualToConstant:18]
]];
cell.backgroundColor = [BHDimPalette currentBackgroundColor];
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
}
- (void)configureDeveloperCell:(UITableViewCell *)cell withDeveloper:(NSDictionary *)developer {
UIImageView *avatarImageView = [cell.contentView viewWithTag:100];
UILabel *nameLabel = [cell.contentView viewWithTag:101];
UILabel *usernameLabel = [cell.contentView viewWithTag:102];
id fontGroup = [objc_getClass("TAEStandardFontGroup") sharedFontGroup];
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
id settings = [TAEColorSettingsCls sharedSettings];
id currentPalette = [settings currentColorPalette];
id colorPalette = [currentPalette colorPalette];
UIColor *textColor = [colorPalette performSelector:@selector(textColor)];
UIColor *subtitleColor = [colorPalette performSelector:@selector(tabBarItemColor)];
nameLabel.text = developer[@"title"];
nameLabel.font = [fontGroup performSelector:@selector(bodyBoldFont)];
nameLabel.textColor = textColor;
usernameLabel.text = [NSString stringWithFormat:@"@%@", developer[@"username"]];
usernameLabel.font = [fontGroup performSelector:@selector(subtext2Font)];
usernameLabel.textColor = subtitleColor;
UIImageView *devChevron = [cell.contentView viewWithTag:103];
devChevron.image = [UIImage tfn_vectorImageNamed:@"chevron_right" fitsSize:CGSizeMake(18, 18) fillColor:subtitleColor];
NSString *avatarURL = developer[@"avatarURL"];
if (avatarURL.length > 0) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:avatarURL]];
UIImage *img = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
avatarImageView.image = img ?: [UIImage systemImageNamed:@"person.circle.fill"];
});
});
} else {
avatarImageView.image = [UIImage systemImageNamed:@"person.circle.fill"];
}
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 0) {
NSDictionary *sectionData = self.sections[indexPath.row];
NSString *action = sectionData[@"action"];
if ([self respondsToSelector:NSSelectorFromString(action)]) {
[self performSelector:NSSelectorFromString(action)];
}
}
else if (indexPath.section == 1) {
NSDictionary *developer = self.developerCells[indexPath.row];
[self openTwitterProfileWithUserID:developer[@"userID"]];
}
else if (indexPath.section == 2) {
NSDictionary *developer = self.specialThanksCells[indexPath.row];
[self openTwitterProfileWithUserID:developer[@"userID"]];
}
else if (indexPath.section == 3) {
NSDictionary *developer = self.officialPageCells[indexPath.row];
[self openTwitterProfileWithUserID:developer[@"userID"]];
}
}
- (void)openTwitterProfileWithUserID:(NSString *)userID {
if (!userID.length) return;
NSString *twitterURL = [NSString stringWithFormat:@"twitter://user?id=%@", userID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:twitterURL]
options:@{}
completionHandler:nil];
}
#pragma mark - Navigation to Sub-pages
- (void)showLayoutSettings {
GeneralSettingsViewController *vc = [[GeneralSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showTwitterBlueSettings {
TwitterBlueSettingsViewController *vc = [[TwitterBlueSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showDownloadsSettings {
MediaDownloadsSettingsViewController *vc = [[MediaDownloadsSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showProfilesSettings {
ProfilesSettingsViewController *vc = [[ProfilesSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showTweetsSettings {
TweetsSettingsViewController *vc = [[TweetsSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showMessagesSettings {
MessagesSettingsViewController *vc = [[MessagesSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showExperimentalSettings {
ExperimentalSettingsViewController *vc = [[ExperimentalSettingsViewController alloc] initWithAccount:self.account];
[self.navigationController pushViewController:vc animated:YES];
}
@end
// ==============================
// TwitterBlueSettingsViewController
// ==============================
@interface TwitterBlueSettingsViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) TFNTwitterAccount *account;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray<NSDictionary *> *settings;
@end
@implementation TwitterBlueSettingsViewController
- (instancetype)initWithAccount:(TFNTwitterAccount *)account {
if ((self = [super init])) {
self.account = account;
[self buildSettingsList];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupNav];
[self setupTable];
}
- (void)setupNav {
NSString *title = [[BHTBundle sharedBundle] localizedStringForKey:@"MODERN_SETTINGS_TWITTER_BLUE_TITLE"];
if (self.account) {
self.navigationItem.titleView = [objc_getClass("TFNTitleView") titleViewWithTitle:title subtitle:self.account.displayUsername];
} else {
self.title = title;
}
}
- (void)setupTable {
self.view.backgroundColor = [BHDimPalette currentBackgroundColor];
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [BHDimPalette currentBackgroundColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 60;
[self.tableView registerClass:[ModernSettingsToggleCell class] forCellReuseIdentifier:@"ToggleCell"];
[self.tableView registerClass:[ModernSettingsSimpleButtonCell class] forCellReuseIdentifier:@"SimpleButtonCell"];
[self.view addSubview:self.tableView];
}
- (void)buildSettingsList {
self.settings = @[
@{ @"key": @"undo_tweet", @"titleKey": @"UNDO_TWEET_OPTION_TITLE", @"subtitleKey": @"UNDO_TWEET_OPTION_DETAIL_TITLE", @"default": @NO, @"type": @"toggle" },
@{ @"key": @"hide_promoted", @"titleKey": @"HIDE_ADS_OPTION_TITLE", @"subtitleKey": @"HIDE_ADS_OPTION_DETAIL_TITLE", @"default": @YES, @"type": @"toggle" },
@{ @"key": @"hide_premium_offer", @"titleKey": @"HIDE_PREMIUM_OFFER_OPTION", @"subtitleKey": @"HIDE_PREMIUM_OFFER_OPTION_DETAIL_TITLE", @"default": @YES, @"type": @"toggle" },
@{ @"titleKey": @"THEME_OPTION_TITLE", @"action": @"showThemeViewController:", @"type": @"button" },
@{ @"titleKey": @"APP_ICON_TITLE", @"action": @"showBHAppIconViewController:", @"type": @"button" },
@{ @"titleKey": @"CUSTOM_TAB_BAR_OPTION_TITLE", @"action": @"showCustomTabBarVC:", @"type": @"button" }
];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.settings.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *settingData = self.settings[indexPath.row];
NSString *type = settingData[@"type"];
if ([type isEqualToString:@"button"]) {
ModernSettingsSimpleButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleButtonCell" forIndexPath:indexPath];
NSString *title = [[BHTBundle sharedBundle] localizedStringForKey:settingData[@"titleKey"]];
[cell configureWithTitle:title];
return cell;
} else {
ModernSettingsToggleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell" forIndexPath:indexPath];
NSString *title = [[BHTBundle sharedBundle] localizedStringForKey:settingData[@"titleKey"]];
NSString *subtitleKey = settingData[@"subtitleKey"];
NSString *subtitle = (subtitleKey.length > 0) ? [[BHTBundle sharedBundle] localizedStringForKey:subtitleKey] : @"";
[cell configureWithTitle:title subtitle:subtitle];
NSString *key = settingData[@"key"];
BOOL isEnabled = [[[NSUserDefaults standardUserDefaults] objectForKey:key] ?: settingData[@"default"] boolValue];
cell.toggleSwitch.on = isEnabled;
objc_setAssociatedObject(cell.toggleSwitch, @"prefKey", key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[cell addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
return cell;
}
}