aboutsummaryrefslogtreecommitdiffstats
path: root/iphone/FixMyStreet/Classes/SettingsViewController.m
blob: 4be1686ba1c6ec525eb7159ff7cf93401d31813c (plain)
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
//
//  SettingsViewController.m
//  FixMyStreet
//
//  Created by Matthew on 20/10/2008.
//  Copyright 2008 UK Citizens Online Democracy. All rights reserved.
//

#import "SettingsViewController.h"
#import "FixMyStreetAppDelegate.h"
#import "EditSubjectViewController.h"

@implementation SettingsViewController

/*
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super initWithStyle:style]) {
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Edit settings";
	self.tableView.sectionHeaderHeight = 27.0;
	self.tableView.sectionFooterHeight = 0.0;
	self.tableView.scrollEnabled = NO;
	
	UIBarButtonItem* backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:nil action:nil];
	self.navigationItem.backBarButtonItem = backBarButtonItem;
	[backBarButtonItem release];
	
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
	return nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
	FixMyStreetAppDelegate* delegate = [[UIApplication sharedApplication] delegate];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

	NSString *text, *placeholder;
	UILabel *label, *current;
	if (indexPath.section == 0) {
		text = delegate.name;
		if (!nameLabel) {
			nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0,70,40)];
			nameLabel.font = [UIFont boldSystemFontOfSize:17];
			nameLabel.text = @"Name:";
			[cell.contentView addSubview:nameLabel];
		}
		label = nameLabel;
		if (!nameCurrent) {
			nameCurrent = [[UILabel alloc] initWithFrame:CGRectMake(80,0,190,40)];
			nameCurrent.font = [UIFont systemFontOfSize:17];
			[cell.contentView addSubview:nameCurrent];
		}
		current = nameCurrent;
		placeholder = @"Your name";
	} else if (indexPath.section == 1) {
		text = delegate.email;
		if (!emailLabel) {
			emailLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0,70,40)];
			emailLabel.font = [UIFont boldSystemFontOfSize:17];
			emailLabel.text = @"Email:";
			[cell.contentView addSubview:emailLabel];
		}
		label = emailLabel;
		if (!emailCurrent) {
			emailCurrent = [[UILabel alloc] initWithFrame:CGRectMake(80,0,190,40)];
			emailCurrent.font = [UIFont systemFontOfSize:17];
			[cell.contentView addSubview:emailCurrent];
		}
		current = emailCurrent;
		placeholder = @"Your email";
	} else if (indexPath.section == 2) {
		text = delegate.phone;
		if (!phoneLabel) {
			phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0,70,40)];
			phoneLabel.font = [UIFont boldSystemFontOfSize:17];
			phoneLabel.text = @"Phone:";
			[cell.contentView addSubview:phoneLabel];
		}
		label = phoneLabel;
		if (!phoneCurrent) {
			phoneCurrent = [[UILabel alloc] initWithFrame:CGRectMake(80,0,190,40)];
			phoneCurrent.font = [UIFont systemFontOfSize:17];
			[cell.contentView addSubview:phoneCurrent];
		}
		current = phoneCurrent;
		placeholder = @"Your phone (optional)";
	}

	if (text) {
		label.hidden = NO;
		cell.text = nil;
		current.text = text;
		current.hidden = NO;
		// cell.accessoryType = UITableViewCellAccessoryCheckmark;
	} else {
		label.hidden = YES;
		current.hidden = YES;
		cell.text = placeholder;
		cell.textColor = [UIColor grayColor];
		// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	}
		
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	FixMyStreetAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
	EditSubjectViewController* editSubjectViewController = [[EditSubjectViewController alloc] initWithStyle:UITableViewStyleGrouped];
	if (indexPath.section == 0) {
		[editSubjectViewController setAll:delegate.name viewTitle:@"Edit name" placeholder:@"Your name" keyboardType:UIKeyboardTypeDefault capitalisation:UITextAutocapitalizationTypeWords];
	} else if (indexPath.section == 1) {
		[editSubjectViewController setAll:delegate.email viewTitle:@"Edit email" placeholder:@"Your email" keyboardType:UIKeyboardTypeEmailAddress capitalisation:UITextAutocapitalizationTypeNone];
	} else if (indexPath.section == 2) {
		[editSubjectViewController setAll:delegate.phone viewTitle:@"Edit phone" placeholder:@"Your phone number" keyboardType:UIKeyboardTypeNumbersAndPunctuation capitalisation:UITextAutocapitalizationTypeNone];
	}	

	[self.navigationController pushViewController:editSubjectViewController animated:YES];
	[editSubjectViewController release];
}

- (void)viewWillAppear:(BOOL)animated {
	[self.tableView reloadData];
//    [super viewWillAppear:animated];
}

/*
- (void)viewDidAppear:(BOOL)animated {
	[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
}
*/
/*
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
*/

- (void)dealloc {
	[nameLabel release];
	[emailLabel release];
	[phoneLabel release];
	[nameCurrent release];
	[emailCurrent release];
	[phoneCurrent release];
    [super dealloc];
}


@end