-
Notifications
You must be signed in to change notification settings - Fork 10
/
IBDetailViewController.m
145 lines (122 loc) · 5.21 KB
/
IBDetailViewController.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
#import "IBDetailViewController.h"
#import "IBWiFiNetwork.h"
#import "IBDictionaryViewController.h"
#import "IBShareViewController.h"
@interface IBDetailViewController ()
@property (nonatomic, strong) IBWiFiNetwork *network;
@property (nonatomic, strong) NSDateFormatter *formatter;
@end
@implementation IBDetailViewController
- (id)initWithNetwork:(IBWiFiNetwork *)network; {
UITableViewStyle style = UITableViewStylePlain;
if (@available(iOS 13, *)) {
style = UITableViewStyleInsetGrouped;
}
if (self = [super initWithStyle:style]) {
self.network = network;
self.formatter = [[NSDateFormatter alloc] init];
[self.formatter setDateFormat:@"dd MMM yyyy HH:mm"];
}
return self;
}
- (void) viewDidLoad {
[super viewDidLoad];
self.title = self.network.name;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 4;
} else if (section == 1) {
return 3;
}
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return @"Network Info";
} else if (section == 1) {
return @"Dates";
}
return @"";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.textLabel.text = @"SSID";
cell.detailTextLabel.text = self.network.name;
} else if (indexPath.row == 1) {
cell.textLabel.text = @"Password";
cell.detailTextLabel.text = self.network.password;
} else if (indexPath.row == 2) {
cell.textLabel.text = @"Encryption";
cell.detailTextLabel.text = self.network.encryption == WEP ? @"WEP" : self.network.encryption == WPA ? @"WPA/WPA2" : self.network.encryption == EAP ? @"EAP" : @"None";
} else {
cell.textLabel.text = @"Hidden";
cell.detailTextLabel.text = self.network.isHidden ? @"Yes" : @"No";
}
} else if (indexPath.section == 1) {
if (indexPath.row == 0) {
cell.textLabel.text = @"Added";
cell.detailTextLabel.text = [self.formatter stringFromDate:self.network.added];
} else if (indexPath.row == 1) {
cell.textLabel.text = @"Last Manual Join";
cell.detailTextLabel.text = [self.formatter stringFromDate:self.network.lastManualJoin];
} else if (indexPath.row == 2) {
cell.textLabel.text = @"Last Auto Join";
cell.detailTextLabel.text = [self.formatter stringFromDate:self.network.lastAutoJoin];
}
} else if (indexPath.section == 2) {
cell.textLabel.text = @"View Raw Data";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else {
cell.textLabel.text = @"Create QR Code";
cell.textLabel.textAlignment = NSTextAlignmentCenter;
if (@available(iOS 13, *)) {
cell.textLabel.textColor = [UIColor linkColor];
} else {
cell.textLabel.textColor = [UIColor blueColor];
}
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 2) {
IBDictionaryViewController *viewController = [[IBDictionaryViewController alloc] initWithDictionary:self.network.allRecords];
[self.navigationController pushViewController:viewController animated:true];
} else if (indexPath.section == 3 && self.network.encryption == EAP) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" message:@"Sharing Enterprise networks is not supported" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
} else if (indexPath.section == 3) {
IBShareViewController *viewController = [[IBShareViewController alloc] initWithNetwork:self.network];
[self.navigationController pushViewController:viewController animated:true];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 1) {
return YES;
}
return NO;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
if (action == @selector(copy:)){
[[UIPasteboard generalPasteboard] setString:self.network.password];
}
}
@end