-
Notifications
You must be signed in to change notification settings - Fork 0
/
RentIncomingDetailViewController.m
288 lines (231 loc) · 9.58 KB
/
RentIncomingDetailViewController.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*-
* Copyright 2011 os-cillation GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "RentOutgoingDetailViewController.h"
#import "Database.h"
#import "DateSelectViewController.h"
@implementation RentOutgoingDetailViewController
@synthesize scrollView, entry, descriptionTxt, type, personTxt, dateTxt;
- (IBAction)cancel {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
- (IBAction)save {
NSString *typeTxt = [type titleForSegmentAtIndex:[type selectedSegmentIndex]];
NSString *description = descriptionTxt.text;
if (entry != nil) {
[Database deleteOutgoingEntry:self.entry.entryId];
}
[Database addOutgoingEntry:typeTxt withName:description forPerson:personId withDate:date];
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
- (IBAction)showDetails {
if (personId != nil) {
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab, [personId intValue]);
personViewController.personViewDelegate = self;
personViewController.displayedPerson = person;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:personViewController];
personViewController.navigationItem.title = @"Kontaktdetails";
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelContact:)];
personViewController.navigationItem.leftBarButtonItem = cancelButton;
[self presentModalViewController:navController animated:YES];
[cancelButton release];
[personViewController release];
[navController release];
}
}
- (void)cancelContact:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)dateSelectViewControllerDidFinish:(DateSelectViewController *)controller {
date = [controller.datePicker date];
NSString *dateString = [NSString alloc];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd.MM.yyyy"];
dateString = [dateFormat stringFromDate:date];
self.dateTxt.text = dateString;
[dateFormat release];
[self dismissModalViewControllerAnimated:YES];
[self.dateTxt resignFirstResponder];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.descriptionTxt.delegate = self;
self.personTxt.delegate = self;
self.dateTxt.delegate = self;
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasHidden:)
name:UIKeyboardDidHideNotification object:nil];
if (self.entry != nil) {
if ([entry.type isEqual:@"Buch"]) {
[type setSelectedSegmentIndex:0];
}
else if ([entry.type isEqual:@"CD"]) {
[type setSelectedSegmentIndex:1];
}
else if ([entry.type isEqual:@"DVD"]) {
[type setSelectedSegmentIndex:2];
}
else if ([entry.type isEqual:@"Andere"]) {
[type setSelectedSegmentIndex:3];
}
self.descriptionTxt.text = entry.name;
self.personTxt.text = entry.person;
self.dateTxt.text = [entry getDateString];
date = entry.date;
personId = entry.person;
ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab, [entry.person intValue]);
NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *fullName;
if (firstName == nil || lastName == nil) {
if (firstName == nil) {
fullName = lastName;
}
else {
fullName = firstName;
}
}
else {
fullName = [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName];
}
self.personTxt.text = fullName;
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField == self.descriptionTxt) {
return YES;
}
if (textField == self.dateTxt) {
[textField resignFirstResponder];
DateSelectViewController *controller = [[DateSelectViewController alloc] initWithNibName:@"DateSelectViewController" bundle:nil];
controller.delegate = self;
controller.date = date;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
else if (textField == self.personTxt) {
[textField resignFirstResponder];
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
[self presentModalViewController:peoplePicker animated:YES];
[peoplePicker release];
}
return NO;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
activeField = textField;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
- (void)keyboardWasShown:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue].size;
CGRect bkgndRect = activeField.superview.frame;
bkgndRect.size.height += kbSize.height;
[activeField.superview setFrame:bkgndRect];
if (activeField.frame.origin.y > 120)
[scrollView setContentOffset:CGPointMake(0.0, activeField.frame.origin.y - 105) animated:NO];
}
// Called when the UIKeyboardDidHideNotification is sent
- (void)keyboardWasHidden:(NSNotification*)aNotification {
NSLog(@"keyboardWasHidden");
NSDictionary* info = [aNotification userInfo];
// Get the size of the keyboard.
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
// Reset the height of the scroll view to its original value
CGRect viewFrame = [scrollView frame];
viewFrame.size.height += keyboardSize.height;
scrollView.frame = viewFrame;
}
//people picker delegate protocol
// Called after the user has pressed cancel
// The delegate is responsible for dismissing the peoplePicker
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
// Called after a person has been selected by the user.
// Return YES if you want the person to be displayed.
// Return NO to do nothing (the delegate is responsible for dismissing the peoplePicker).
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectionPerson:(ABRecordRef)person {
return NO;
}
// Called after a value has been selected by the user.
// Return YES if you want default action to be performed.
// Return NO to do nothing (the delegate is responsible for dismissing the peoplePicker).
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABRecordID recordId = ABRecordGetRecordID(person);
personId = [[NSString alloc] initWithFormat:@"%i", recordId];
NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *fullName;
if (firstName == nil || lastName == nil) {
if (firstName == nil) {
fullName = lastName;
}
else {
fullName = firstName;
}
}
else {
fullName = [[NSString alloc] initWithFormat:@"%@ %@", firstName, lastName];
}
self.personTxt.text = fullName;
[self dismissModalViewControllerAnimated:YES];
[self.personTxt resignFirstResponder];
return NO;
}
// Called after a value has been selected by the user.
// Return YES if you want default action to be performed.
// Return NO to do nothing (the delegate is responsible for dismissing the peoplePicker).
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
return NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//If touch location is inside the label then...
if (CGRectContainsPoint(self.personTxt.frame, [[[event allTouches] anyObject] locationInView:self.view]))
{
//Open webpage
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.os-cillation.de"]];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue {
NSLog(@"hello");
return YES;
}
@end