-
Notifications
You must be signed in to change notification settings - Fork 0
/
KidDetail.m
212 lines (185 loc) · 6.7 KB
/
KidDetail.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
//
// KidDetail.m
// Allowance
//
// Created by Pablo Collins on 6/15/10.
//
#import "KidDetail.h"
@implementation KidDetail
@synthesize kidsTable;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = [AllowanceAppDelegate currentKid].name;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return section == 2 ? 2 : 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
switch (section) {
case 0:
return @"Touch balance to view account history";
default:
return nil;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return @"Balance";
case 1:
return @"Weekly Allowance";
case 2:
return @"Updates";
default:
return @"";
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
switch ([indexPath indexAtPosition:0]) {
case 0:
cell = [self kidBalanceCell];
break;
case 1:
cell = [self kidAllowanceCell];
break;
case 2:
switch ([indexPath indexAtPosition:1]) {
case 0:
cell = [self kidCreditCell];
break;
case 1:
cell = [self kidDebitCell];
break;
default:
break;
}
break;
case 3:
cell = [self kidDeleteCell];
break;
default:
break;
}
return cell;
}
- (Kid *)kid {
return [AllowanceAppDelegate currentKid];
}
- (UITableViewCell *)kidNameCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text = [AllowanceAppDelegate currentKid].name;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)kidAllowanceCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
double dollars = [[AllowanceAppDelegate currentKid].payAmount intValue]/(double)[AllowanceAppDelegate priceDenominator];
cell.textLabel.text = [AllowanceAppDelegate priceFromDouble:dollars];
return cell;
}
- (UITableViewCell *)kidBalanceCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [[AllowanceAppDelegate currentKid] balanceString];
return cell;
}
- (UITableViewCell *)kidCreditCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"Credit";
return cell;
}
- (UITableViewCell *)kidDebitCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = @"Debit";
return cell;
}
- (UITableViewCell *)kidDeleteCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString *t = [NSString stringWithFormat:@"Delete Account"];
[btn setTitle:t forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
CGRect frame = cell.bounds;
frame.size.width = 300; //originally 320
btn.frame = frame;
[btn addTarget:self action:@selector(deleteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btn];
return cell;
}
- (void)deleteKid {
[[ModelManager sharedInstance] delete:[AllowanceAppDelegate currentKid]];
[self.kidsTable readAndReload];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)deleteBtnClicked:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Delete" message:@"Are you sure you want to delete this account?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[self deleteKid];
}
}
- (void)readAndReload {
[self.tableView reloadData];
}
- (void)pushCreditDebitScreenWithType:(NSString *)type {
CreditDebitScreen *s = [[CreditDebitScreen alloc] initWithStyle:UITableViewStyleGrouped];
[s setType:type];
s.title = type;
s.reloadableParent = self;
[self.navigationController pushViewController:s animated:YES];
}
- (void)pushAllowanceEditor {
AmountEditor *amountEditor = [[AmountEditor alloc] initWithNibName:@"AmountEditor" bundle:nil];
amountEditor.title = @"Allowance";
Kid *kid = [AllowanceAppDelegate currentKid];
int payAmount = [kid.payAmount intValue];
[amountEditor setCallback:@selector(saveAmount:) withObject:self];
[amountEditor setAmount:payAmount];
[self.navigationController pushViewController:amountEditor animated:YES];
}
- (void)pushAccountHistory {
AccountHistory *a = [[AccountHistory alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:a animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch ([indexPath indexAtPosition:0]) {
case 0:
[self pushAccountHistory];
break;
case 1:
[self pushAllowanceEditor];
break;
case 2:
switch ([indexPath indexAtPosition:1]) {
case 0:
[self pushCreditDebitScreenWithType:@"Credit"];
break;
case 1:
[self pushCreditDebitScreenWithType:@"Debit"];
break;
default:
break;
}
default:
break;
}
}
- (void)saveAmount:(NSNumber *)amount {
Kid *kid = [AllowanceAppDelegate currentKid];
kid.payAmount = amount;
[[ModelManager sharedInstance] save];
[self readAndReload];
}
@end