-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathSNPrivateViewController.m
executable file
·240 lines (211 loc) · 8.61 KB
/
SNPrivateViewController.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
#import "SNPrivateViewController.h"
#import "SNPrivatelistViewController.h"
#import "SNPrivateMessageHistoryViewController.h"
#import "SNTextTableViewCell.h"
#import <objc/runtime.h>
#import <sqlite3.h>
#import <notify.h>
#ifndef SMSNinjaDebug
#define SETTINGS @"/var/mobile/Library/SMSNinja/smsninja.plist"
#define DATABASE @"/var/mobile/Library/SMSNinja/smsninja.db"
#else
#define SETTINGS @"/Users/snakeninny/Library/Application Support/iPhone Simulator/7.0.3/Applications/0C9D35FB-B626-42B7-AAE9-45F6F537890B/Documents/var/mobile/Library/SMSNinja/smsninja.plist"
#define DATABASE @"/Users/snakeninny/Library/Application Support/iPhone Simulator/7.0.3/Applications/0C9D35FB-B626-42B7-AAE9-45F6F537890B/Documents/var/mobile/Library/SMSNinja/smsninja.db"
#endif
@implementation SNPrivateViewController
- (void)dealloc
{
[fakePasswordField release];
fakePasswordField = nil;
[purpleSwitch release];
purpleSwitch = nil;
[semicolonSwitch release];
semicolonSwitch = nil;
[revealSwitch release];
revealSwitch = nil;
[tapRecognizer release];
tapRecognizer = nil;
[super dealloc];
}
- (instancetype)init
{
if ((self = [super initWithStyle:UITableViewStyleGrouped]))
{
self.title = NSLocalizedString(@"Private Zone", @"Private Zone");
fakePasswordField = [[UITextField alloc] initWithFrame:CGRectZero];
purpleSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
semicolonSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
revealSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboardWithTap:)];
tapRecognizer.delegate = self;
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 0: return 2;
case 1: return 1;
case 2: return 3;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SNTextTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"any-cell"];
if (cell == nil) cell = [[[SNTextTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"any-cell"] autorelease];
for (UIView *subview in [cell.contentView subviews]) [subview removeFromSuperview];
cell.textLabel.text = nil;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryNone;
NSDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:SETTINGS];
switch (indexPath.section)
{
case 0:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
switch (indexPath.row)
{
case 0:
{
cell.textLabel.text = NSLocalizedString(@"Private Info", @"Private Info");
break;
}
case 1:
{
cell.textLabel.text = NSLocalizedString(@"Privatelist", @"Privatelist");
break;
}
}
break;
case 1:
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = NSLocalizedString(@"FakePW", @"FakePW");
fakePasswordField.delegate = self;
fakePasswordField.secureTextEntry = YES;
fakePasswordField.placeholder = NSLocalizedString(@"Input fake password", @"Input fake password");
fakePasswordField.text = [dictionary objectForKey:@"fakePassword"];
fakePasswordField.clearButtonMode = UITextFieldViewModeWhileEditing;
if ([cell.contentView.subviews indexOfObject:fakePasswordField] == NSNotFound) [cell.contentView addSubview:fakePasswordField];
break;
}
case 2:
switch (indexPath.row)
{
case 0:
{
cell.textLabel.text = NSLocalizedString(@"Purple Square", @"Purple Square");
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = purpleSwitch;
purpleSwitch.on = [[dictionary objectForKey:@"shouldShowPurpleSquare"] boolValue];
[purpleSwitch addTarget:self action:@selector(saveSettingsFromSource:) forControlEvents:UIControlEventValueChanged];
break;
}
case 1:
{
cell.textLabel.text = NSLocalizedString(@"Show Semicolon", @"Show Semicolon");
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = semicolonSwitch;
semicolonSwitch.on = [[dictionary objectForKey:@"shouldShowSemicolon"] boolValue];
[semicolonSwitch addTarget:self action:@selector(saveSettingsFromSource:) forControlEvents:UIControlEventValueChanged];
break;
}
case 2:
{
cell.textLabel.text = NSLocalizedString(@"Reveal Privatelist", @"Reveal Privatelist");
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryView = revealSwitch;
revealSwitch.on = [[dictionary objectForKey:@"shouldRevealPrivatelistOutsideSMSNinja"] boolValue];
[revealSwitch addTarget:self action:@selector(saveSettingsFromSource:) forControlEvents:UIControlEventValueChanged];
break;
}
}
break;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
switch (indexPath.row)
{
case 0:
{
SNPrivateMessageHistoryViewController *privateMessageHistoryViewController = [[SNPrivateMessageHistoryViewController alloc] init];
[self.navigationController pushViewController:privateMessageHistoryViewController animated:YES];
[privateMessageHistoryViewController release];
break;
}
case 1:
{
SNPrivatelistViewController *privatelistViewController = [[SNPrivatelistViewController alloc] init];
[self.navigationController pushViewController:privatelistViewController animated:YES];
[privatelistViewController release];
break;
}
}
}
}
- (void)saveSettingsFromSource:(UIControl *)control
{
NSFileManager *fileManager = [NSFileManager defaultManager];
if (control == purpleSwitch && (![fileManager fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/libstatusbar.dylib"] || ![fileManager fileExistsAtPath:@"/Library/MobileSubstrate/DynamicLibraries/libstatusbar.plist"]))
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Notice", @"Notice") message:NSLocalizedString(@"To enable this feature, you need to install libstatusbar, whose potential bugs are not in my charge.", @"To enable this feature, you need to install libstatusbar, whose potential bugs are not in my charge.") delegate:self cancelButtonTitle:NSLocalizedString(@"Never mind", @"Never mind") otherButtonTitles:NSLocalizedString(@"Go to Cydia", @"Go to Cydia") , nil];
[alertView show];
[alertView release];
purpleSwitch.on = NO;
}
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:SETTINGS];
[dictionary setObject:[NSNumber numberWithBool:purpleSwitch.on] forKey:@"shouldShowPurpleSquare"];
[dictionary setObject:[NSNumber numberWithBool:semicolonSwitch.on] forKey:@"shouldShowSemicolon"];
[dictionary setObject:[NSNumber numberWithBool:revealSwitch.on] forKey:@"shouldRevealPrivatelistOutsideSMSNinja"];
[dictionary writeToFile:SETTINGS atomically:YES];
notify_post("com.naken.smsninja.settingschanged");
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"cydia://package/libstatusbar"]];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:SETTINGS];
[dictionary setObject:textField.text ? textField.text : @"" forKey:@"fakePassword"];
[dictionary writeToFile:SETTINGS atomically:YES];
notify_post("com.naken.smsninja.settingschanged");
[textField resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addGestureRecognizer:tapRecognizer];
}
- (void)dismissKeyboardWithTap:(UITapGestureRecognizer *)tap
{
[fakePasswordField resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (gestureRecognizer == tapRecognizer && ([touch.view isKindOfClass:[UIButton class]] || [touch.view isKindOfClass:NSClassFromString(@"UITableViewCellContentView")])) return NO;
return YES;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section == 2) return NSLocalizedString(@"If \"Reveal Privatelist\" is on, you can add numbers to Privatelist inside stock MobilePhone and MobileSMS", @"If \"Reveal Privatelist\" is on, you can add numbers to Privatelist inside stock MobilePhone and MobileSMS");
return nil;
}
@end