-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsViewController.m
More file actions
executable file
·231 lines (203 loc) · 7.63 KB
/
SettingsViewController.m
File metadata and controls
executable file
·231 lines (203 loc) · 7.63 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
//
// SettingsViewController.m
// Junction
//
// Created by Bobby Ren on 3/1/13.
//
//
#import "SettingsViewController.h"
#import "AppDelegate.h"
#import "SettingsNotificationsViewController.h"
#import "SettingsEditProfileViewController.h"
#import "TutorialViewController.h"
static AppDelegate * appDelegate;
@interface SettingsViewController ()
@end
@implementation SettingsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[self.tabBarItem setImage:[UIImage imageNamed:@"tabbar-settings"]];
[self.tabBarItem setTitle:@"Settings"];
appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// make a custom header label
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
UIImage * headerbg = [UIImage imageNamed:@"header_bg"];
[self.navigationController.navigationBar setBackgroundImage:headerbg forBarMetrics:UIBarMetricsDefault];
UILabel * titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[titleView setFont:[UIFont boldSystemFontOfSize:23]];
[titleView setTextColor:[UIColor whiteColor]];
[titleView setBackgroundColor:[UIColor colorWithRed:14.0/255.0 green:158.0/255.0 blue:205.0/255.0 alpha:1]];
[titleView setTextAlignment:NSTextAlignmentCenter];
titleView.text = @"Settings";
UIFont * font = titleView.font;
CGRect frame = CGRectMake(0, 0, [self.navigationItem.title sizeWithFont:font].width, 44);
frame.origin.x = 320 - frame.size.width / 2;
[titleView setFrame:frame];
self.navigationItem.titleView = titleView;
tableView.backgroundColor = COLOR_FAINTBLUE;
[toggleVisibility setOn:appDelegate.myUserInfo.isVisible];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return 2;
if (section == 1)
return 3;
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell setBackgroundColor:[UIColor whiteColor]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
int section = [indexPath section];
int row = [indexPath row]; //[chatData count]-[indexPath row]-1;
switch (section) {
case 0:
{
cell.accessoryView = self.accessoryRightArrow;
cell.textLabel.textAlignment = NSTextAlignmentLeft;
if (row == 0) {
cell.textLabel.text = @"See help again";
}
else if (row == 1) {
cell.textLabel.text = @"Invite friends";
}
}
break;
case 1:
{
cell.accessoryView = self.accessoryRightArrow;
cell.textLabel.textAlignment = NSTextAlignmentLeft;
if (row == 0) {
cell.textLabel.text = @"Visibility";
cell.accessoryView = toggleVisibility;
}
else if (row == 1) {
cell.textLabel.text = @"Profile";
}
else if (row == 2) {
cell.textLabel.text = @"Notifications";
}
}
break;
case 2:
{
cell.accessoryView = self.accessoryRightArrow;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
if (row == 0) {
cell.textLabel.text = @"Send feedback";
}
else if (row == 1) {
cell.textLabel.text = @"Log out";
}
}
break;
default:
break;
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case 0:
{
if (indexPath.row == 0) {
NSLog(@"See help again");
TutorialViewController * controller = [[TutorialViewController alloc] init];
[controller setForceDone:YES];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentModalViewController:nav animated:YES];
}
else if (indexPath.row == 1) {
NSLog(@"Invite friends");
}
}
break;
case 1:
{
if (indexPath.row == 0) {
NSLog(@"Visibility");
}
else if (indexPath.row == 1) {
NSLog(@"Profile");
SettingsEditProfileViewController * controller = [[SettingsEditProfileViewController alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:controller];
//[self.navigationController pushViewController:controller animated:YES];
[self presentModalViewController:nav animated:YES];
}
else if (indexPath.row == 2) {
NSLog(@"Notifications");
SettingsNotificationsViewController * controller = [[SettingsNotificationsViewController alloc] init];
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:controller];
//[self.navigationController pushViewController:controller animated:YES];
[self presentModalViewController:nav animated:YES];
}
}
break;
case 2:
{
if (indexPath.row == 0) {
NSLog(@"Feedback");
[appDelegate sendFeedback:@"General comments"];
}
else if (indexPath.row == 1) {
NSLog(@"Log out");
[appDelegate logout];
}
}
break;
default:
break;
}
}
-(IBAction)didToggleVisibility:(id)sender {
NSLog(@"Toggled!");
BOOL oldIsOn = appDelegate.myUserInfo.isVisible;
appDelegate.myUserInfo.isVisible = toggleVisibility.isOn;
[toggleVisibility setEnabled:NO];
[appDelegate.myUserInfo.toPFObject saveEventually:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(@"Visibility toggle succeeded!");
[toggleVisibility setEnabled:YES];
}
else {
NSLog(@"Visibility toggle could not be saved!");
appDelegate.myUserInfo.isVisible = oldIsOn;
[toggleVisibility setOn:oldIsOn];
[toggleVisibility setEnabled:YES];
}
}];
}
-(UIImageView*)accessoryRightArrow {
UIImageView * accessoryRightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btn-field-arrow.png"]];
[accessoryRightArrow setFrame:CGRectMake(0, 0, 17, 25)];
return accessoryRightArrow;
}
@end