-
Notifications
You must be signed in to change notification settings - Fork 380
/
SettingsViewController.m
executable file
·323 lines (271 loc) · 15.9 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
//
// 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.title = @"BHInsta";
[self.navigationController.navigationBar setPrefersLargeTitles:false];
}
return self;
}
- (UITableViewStyle)tableViewStyle {
return UITableViewStyleInsetGrouped;
}
- (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 *)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) {
PSSpecifier *feedSection = [self newSectionWithTitle:@"Feed" footer:nil];
PSSpecifier *mediaSection = [self newSectionWithTitle:@"Save media" footer:nil];
PSSpecifier *storySection = [self newSectionWithTitle:@"Story and direct" footer:nil];
PSSpecifier *securitySection = [self newSectionWithTitle:@"Security" footer:nil];
PSSpecifier *developer = [self newSectionWithTitle:@"Developer" footer:nil];
PSSpecifier *hideAds = [self newSwitchCellWithTitle:@"Hide Ads" detailTitle:@"Remove all Ads from Instagram app" key:@"hide_ads" defaultValue:true changeAction:nil];
PSSpecifier *noSuggestedPost = [self newSwitchCellWithTitle:@"No suggested post" detailTitle:@"Remove suggested posts from the feed" key:@"no_suggested_post" defaultValue:false changeAction:nil];
PSSpecifier *showLikeCount = [self newSwitchCellWithTitle:@"Show Like count" detailTitle:@"Show like count in the post" key:@"show_like_count" 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 *followConfirmation = [self newSwitchCellWithTitle:@"Confirm Follow" detailTitle:@"Show alert when you click the Follow button to confirm the Follow" key:@"follow_confirm" defaultValue:false changeAction:nil];
PSSpecifier *copyDecription = [self newSwitchCellWithTitle:@"Copy description" detailTitle:@"Copy the post description by long press" key:@"copy_description" defaultValue:true changeAction:nil];
PSSpecifier *copyBio = [self newSwitchCellWithTitle:@"Copy Profile Bio" detailTitle:@"Copy the Profile Bio by long press on Bio" key:@"copy_bio" 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 *profileSave = [self newSwitchCellWithTitle:@"Save profile image" detailTitle:@"Save profile image by long press." key:@"save_profile" defaultValue:true changeAction:nil];
PSSpecifier *keepDelMessage = [self newSwitchCellWithTitle:@"Keep deleted message" detailTitle:@"Keep deleted direct message on the chat." key:@"keep_deleted_message" defaultValue:true changeAction:nil];
PSSpecifier *hideLastSeen = [self newSwitchCellWithTitle:@"Remove last seen" detailTitle:@"Remove last seen from the chat" key:@"remove_lastseen" defaultValue:false changeAction:nil];
PSSpecifier *noScreenShotAlert = [self newSwitchCellWithTitle:@"Remove screenshot alert" detailTitle:nil key:@"remove_screenshot_alert" defaultValue:true changeAction:nil];
PSSpecifier *unlimtedReply = [self newSwitchCellWithTitle:@"Unlimited replay of once story" detailTitle:@"Unlimited replay of once story in direct chat" key:@"unlimited_replay" defaultValue:false changeAction:nil];
PSSpecifier *noStorySeenReceipt = [self newSwitchCellWithTitle:@"Disable Story Seen Receipt" detailTitle:nil key:@"no_seen_receipt" defaultValue:false changeAction:nil];
PSSpecifier *appLock = [self newSwitchCellWithTitle:@"Padlock" detailTitle:@"Lock Instagram 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,
noSuggestedPost,
showLikeCount,
likeConfirmation,
followConfirmation,
copyDecription,
copyBio,
mediaSection, // 2
downloadVid,
profileSave,
storySection, // 3
keepDelMessage,
hideLastSeen,
noScreenShotAlert,
unlimtedReply,
noStorySeenReceipt,
securitySection, // 4
appLock,
developer, // 5
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"];
}
- (void)FLEXAction:(UISwitch *)sender {
// if (sender.isOn) {
// [[objc_getClass("FLEXManager") sharedManager] showExplorer];
// } else {
// [[objc_getClass("FLEXManager") sharedManager] hideExplorer];
// }
}
@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