-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreditDebitScreen.m
158 lines (137 loc) · 5.3 KB
/
CreditDebitScreen.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
//
// CreditDebitScreen.m
// Allowance
//
// Created by Pablo Collins on 7/11/10.
//
#import "CreditDebitScreen.h"
@implementation CreditDebitScreen
@synthesize reloadableParent;
- (void)viewDidLoad {
//[self.tableView addSubview:[self applyButton]];
//[self.tableView addSubview:[self cancelButton]];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return @"Amount";
case 1:
return @"Notes";
default:
return @"";
}
}
- (UITableViewCell *)amountCell {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text = amount == nil ?
[AllowanceAppDelegate priceFromDouble:0.0] :
[AllowanceAppDelegate priceFromDouble:[amount intValue]/(double)[AllowanceAppDelegate priceDenominator]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (EditableCell *)notesCell {
if (notesCell == nil) {
notesCell = [[EditableCell alloc] initWithStyle:UITableViewCellStyleDefault placeholder:@"Notes"];
}
return notesCell;
}
- (void)applyBtnClicked:(id)sender {
Kid *kid = [AllowanceAppDelegate currentKid];
int amt = [amount intValue];
if ([type isEqualToString:@"Credit"]) {
[kid updateAccountBy:amt withNotes:[self notesCell].textLabel.text];
} else {
[kid updateAccountBy:-amt withNotes:[self notesCell].textLabel.text];
}
[self.navigationController popViewControllerAnimated:YES];
[self.reloadableParent readAndReload];
}
- (void)cancelBtnClicked:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (UIButton *)applyButton {
NSString *t = [NSString stringWithFormat:@"Apply %@",type];
CGRect frame = CGRectMake(10, 300, 300, 42);
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *whiteImage = [UIImage imageNamed:@"whiteButton.png"];
UIButton *btn = [AllowanceAppDelegate newButtonWithTitle:t
target:self
selector:@selector(applyBtnClicked:)
frame:frame
image:whiteImage
imagePressed:blueImage
darkTextColor:YES];
return btn;
}
- (UIButton *)cancelButton {
NSString *t = [NSString stringWithFormat:@"Cancel"];
CGRect frame = CGRectMake(10, 280, 300, 42);
UIImage *buttonBackground = [UIImage imageNamed:@"whiteButton.png"];
UIImage *buttonBackgroundPressed = [UIImage imageNamed:@"blueButton.png"];
UIButton *btn = [AllowanceAppDelegate newButtonWithTitle:t
target:self
selector:@selector(cancelBtnClicked:)
frame:frame
image:buttonBackground
imagePressed:buttonBackgroundPressed
darkTextColor:YES ];
return btn;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
switch ([indexPath indexAtPosition:0]) {
case 0:
cell = [self amountCell];
break;
case 1:
cell = [self notesCell];
break;
default:
break;
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath indexAtPosition:0]) {
case 1:
return 85;
default:
return 44;
}
}
- (void)pushAmountEditor {
AmountEditor *e = [[AmountEditor alloc] initWithNibName:@"AmountEditor" bundle:nil];
e.title = @"Amount";
[e setCallback:@selector(saveAmount:) withObject:self];
[self.navigationController pushViewController:e animated:YES];
}
- (void)saveAmount:(NSNumber *)n {
amount = n;
[(UITableView *)self.view reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
withRowAnimation:UITableViewRowAnimationNone];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:@selector(applyBtnClicked:)];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch ([indexPath indexAtPosition:0]) {
case 0:
[self pushAmountEditor];
break;
case 1:
break;
default:
break;
}
}
- (void)setType:(NSString *)t {
type = t;
}
@end