Changeset 633
- Timestamp:
- 01/11/10 19:51:34 (3 years ago)
- Location:
- apps/iphone/my.tel/trunk
- Files:
-
- 3 added
- 4 modified
-
Classes/HATypePickerController.h (added)
-
Classes/HATypePickerController.m (added)
-
Classes/KeywordEditController.h (modified) (3 diffs)
-
Classes/KeywordEditController.m (modified) (11 diffs)
-
Classes/KeywordViewController.m (modified) (5 diffs)
-
HATypePickerController.xib (added)
-
VIP.tel.xcodeproj/project.pbxproj (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/iphone/my.tel/trunk/Classes/KeywordEditController.h
r626 r633 11 11 #import "Keyword.h" 12 12 #import "HATextViewEditController.h" 13 #import "HATypePickerController.h" 13 14 14 15 enum kKKeywordEditTableViewSections { … … 31 32 @interface KeywordEditController : UITableViewController <UITableViewDelegate, 32 33 UITableViewDataSource, 33 HATextViewEditDelegate> { 34 HATextViewEditDelegate, 35 HATypePickerViewDelegate> { 34 36 35 37 NSString *keywordId; … … 41 43 UIBarButtonItem *buttonSave; 42 44 BOOL isEditing; 45 NSInteger rowBeingEdited; 43 46 } 44 47 45 + (KeywordEditController *)controllerForKeyword:(NSDictionary *)aRec ;46 - (KeywordEditController *)initWithKeyword:(NSDictionary *)aRec ;48 + (KeywordEditController *)controllerForKeyword:(NSDictionary *)aRec delegate:(id <KeywordEditDelegate>)aDelegate; 49 - (KeywordEditController *)initWithKeyword:(NSDictionary *)aRec delegate:(id <KeywordEditDelegate>)aDelegate; 47 50 - (void)didClickCancel; 48 51 - (void)didClickSave; -
apps/iphone/my.tel/trunk/Classes/KeywordEditController.m
r629 r633 20 20 #pragma mark ------ Calling methods 21 21 22 + (KeywordEditController *)controllerForKeyword:(NSDictionary *)aRec {23 KeywordEditController *keyEC = [[[KeywordEditController alloc] initWithKeyword:aRec ] autorelease];22 + (KeywordEditController *)controllerForKeyword:(NSDictionary *)aRec delegate:(id <KeywordEditDelegate>)aDelegate { 23 KeywordEditController *keyEC = [[[KeywordEditController alloc] initWithKeyword:aRec delegate:aDelegate] autorelease]; 24 24 return keyEC; 25 25 } 26 26 27 - (KeywordEditController *)initWithKeyword:(NSDictionary *)aRec {27 - (KeywordEditController *)initWithKeyword:(NSDictionary *)aRec delegate:(id <KeywordEditDelegate>)aDelegate { 28 28 if (! [super initWithStyle:UITableViewStyleGrouped]) { 29 29 return nil; 30 30 } 31 self.delegate = aDelegate; 31 32 if (!aRec) { // new 32 33 isEditing = NO; … … 43 44 self.secondaryKeywords = [self fillSecondaryKeywords:[aRec objectForKey:@"secondaryKeywords"]]; 44 45 } 46 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 47 target:self 48 action:@selector(didClickCancel)] autorelease]; 45 49 buttonSave = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(didClickSave)]; 46 50 [buttonSave retain]; … … 98 102 } else { 99 103 // this is a known keyword that may or may not have its secondaries filled in 104 // first remove the used secondaries from the list of known ones 105 NSMutableIndexSet *duplicateSecs = [NSMutableIndexSet indexSet]; 100 106 for (NSDictionary *secDict in returnedArray) { 101 // first remove the used secondaries from the list of known ones102 107 NSString *shortName = [secDict objectForKey:@"field"]; 103 [knownSecondaries removeObjectIdenticalTo:shortName]; 104 } 108 NSUInteger i, count = [knownSecondaries count]; 109 for (i = 0; i < count; i++) { 110 NSString *knownSec = [knownSecondaries objectAtIndex:i]; 111 if ([knownSec isEqualToString:shortName]) 112 [duplicateSecs addIndex:i]; 113 } 114 } 115 [knownSecondaries removeObjectsAtIndexes:duplicateSecs]; 105 116 for (NSString *unusedSec in knownSecondaries) { 106 117 // then append the culled list to the list of used secondaries … … 138 149 break; 139 150 case kKKeywordEditTableViewSectionValue: 140 returnedTitle = @"Value"; 151 if (self.keywordHasSecondaries) { 152 returnedTitle = @"Description"; 153 } else { 154 returnedTitle = @"Value"; 155 } 141 156 break; 142 157 case kKKeywordEditTableViewSectionSecondaries: … … 180 195 reuseIdentifier:ValueCellIdentifier] autorelease]; 181 196 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 182 cell.textLabel. font = [cell.textLabel.font fontWithSize:12.0f];197 cell.textLabel.minimumFontSize = 12.0f; 183 198 cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 184 cell.textLabel.adjustsFontSizeToFitWidth = NO;199 cell.textLabel.adjustsFontSizeToFitWidth = YES; 185 200 } 186 201 cell.textLabel.text = self.primaryValue; … … 217 232 218 233 if (indexPath.section == kKKeywordEditTableViewSectionType) { 219 // TODO: load an action sheet with a pickerview to choose from different primaries 234 HATypePickerController *typePickerController = [[[HATypePickerController alloc] initWithNibName:@"HATypePickerController" 235 bundle:nil] autorelease]; 236 typePickerController.delegate = self; 237 [typePickerController presentViewController]; 220 238 } else if (indexPath.section == kKKeywordEditTableViewSectionValue) { 221 239 NSString *tvEditTitle = [delegate longNameForKeyword:self.primaryType]; 240 rowBeingEdited = -1; 222 241 HATextViewEditController *teC = [HATextViewEditController controllerWithDelegate:self 223 242 title:tvEditTitle … … 229 248 teC.maxCharSize = kKValueMaxLength; 230 249 } 231 teC.returnKeyType = UIReturnKeyD one;250 teC.returnKeyType = UIReturnKeyDefault; 232 251 [self.navigationController pushViewController:teC animated:YES]; 233 252 } else if (indexPath.section == kKKeywordEditTableViewSectionSecondaries) { 234 // TODO: new view controller to manage a secondary type and value 253 NSDictionary *theSecondary = [self.secondaryKeywords objectAtIndex:indexPath.row]; 254 NSString *tvEditTitle = [delegate longNameForKeyword:[theSecondary objectForKey:@"field"]]; 255 rowBeingEdited = indexPath.row; 256 HATextViewEditController *teC = [HATextViewEditController controllerWithDelegate:self 257 title:tvEditTitle 258 prompt:nil]; 259 teC.textContent = [theSecondary objectForKey:@"value"]; 260 teC.maxCharSize = kKPrimaryValueMaxLength; 261 teC.returnKeyType = UIReturnKeyDefault; 262 [self.navigationController pushViewController:teC animated:YES]; 235 263 } 236 264 } … … 240 268 241 269 - (void)didClickCancel { 242 [self. view removeFromSuperview];270 [self.navigationController popViewControllerAnimated:YES]; 243 271 } 244 272 … … 287 315 if ([[parsedJson valueForKey:@"success"] integerValue] == 1) { 288 316 [delegate dataDidChangeInController:self]; 289 [self. view removeFromSuperview];317 [self.navigationController popViewControllerAnimated:YES]; 290 318 } else { 291 319 [JsonConnection throwJsonErrorAlert:parsedJson]; … … 297 325 298 326 - (void)didChangeContentOfTextView:(UITextView *)textView { 299 self.primaryValue = textView.text; 300 NSIndexPath *primaryValueIndexPath = [NSIndexPath indexPathForRow:0 inSection:kKKeywordEditTableViewSectionValue]; 301 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:primaryValueIndexPath] 302 withRowAnimation:UITableViewRowAnimationFade]; 327 if (rowBeingEdited == -1) { // Editing the primary value 328 self.primaryValue = textView.text; 329 NSIndexPath *primaryValueIndexPath = [NSIndexPath indexPathForRow:0 inSection:kKKeywordEditTableViewSectionValue]; 330 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:primaryValueIndexPath] 331 withRowAnimation:UITableViewRowAnimationFade]; 332 } else { 333 if ([self.secondaryKeywords count] > rowBeingEdited) { 334 NSDictionary *origSecondary = [self.secondaryKeywords objectAtIndex:rowBeingEdited]; 335 NSDictionary *newSecondary = [NSDictionary dictionaryWithObjectsAndKeys: 336 @"", @"id", 337 [origSecondary objectForKey:@"field"], @"field", 338 textView.text, @"value", 339 nil]; 340 [self.secondaryKeywords replaceObjectAtIndex:rowBeingEdited withObject:newSecondary]; 341 } 342 NSIndexPath *secKeywordIndexPath = [NSIndexPath indexPathForRow:rowBeingEdited inSection:kKKeywordEditTableViewSectionSecondaries]; 343 [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:secKeywordIndexPath] 344 withRowAnimation:UITableViewRowAnimationFade]; 345 } 303 346 } 304 347 … … 306 349 } 307 350 351 #pragma mark - 352 #pragma mark UIPickerView stuff 353 354 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { 355 return 1; 356 } 357 358 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 359 return [[delegate typesForKeyword:nil] count]; 360 } 361 362 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 363 } 364 365 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 366 NSString *shortName = [[delegate typesForKeyword:nil] objectAtIndex:row]; 367 return [delegate longNameForKeyword:shortName]; 368 } 369 370 - (void)pickerView:(UIPickerView *)pickerView willCancelWithButton:(id)sender { 371 } 372 373 - (void)pickerView:(UIPickerView *)pickerView willAcceptWithButton:(id)sender { 374 self.primaryType = [[delegate typesForKeyword:nil] objectAtIndex:[pickerView selectedRowInComponent:0]]; 375 self.primaryValue = @""; 376 self.secondaryKeywords = [self fillSecondaryKeywords:nil]; 377 [self.tableView reloadData]; 378 } 379 308 380 @end 309 381 -
apps/iphone/my.tel/trunk/Classes/KeywordViewController.m
r630 r633 124 124 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 125 125 [tableView deselectRowAtIndexPath:indexPath animated:NO]; 126 KeywordEditController *editC = [KeywordEditController controllerForKeyword:[uiArray objectAtIndex:indexPath.row]]; 126 KeywordEditController *editC = [KeywordEditController controllerForKeyword:[uiArray objectAtIndex:indexPath.row] 127 delegate:self]; 127 128 editC.delegate = self; 128 129 [self.navigationController pushViewController:editC animated:YES]; … … 179 180 constrainedToSize:constrainedSize 180 181 lineBreakMode:UILineBreakModeWordWrap].height; 182 [uiItem release]; 181 183 return rowSize; 182 184 } … … 204 206 205 207 - (NSArray *)typesForKeyword:(NSString *)shortName { 206 if (shortName == nil) return nil; 208 if (shortName == nil) { 209 // return primary keyword types 210 NSArray *primaryTypes = [keywordTypes allKeys]; 211 return primaryTypes; 212 } 207 213 NSArray *secondaryTypes = [keywordTypes objectForKey:shortName]; 208 214 return secondaryTypes; … … 212 218 213 219 - (void)addRecord { 214 KeywordEditController *editC = [KeywordEditController controllerForKeyword:nil]; 215 editC.delegate = self; 220 KeywordEditController *editC = [KeywordEditController controllerForKeyword:nil delegate:self]; 216 221 [self.navigationController pushViewController:editC animated:YES]; 217 222 } … … 257 262 // secondaryKeywords: [ {id: 15, field: "a1", value: "my street"}]} 258 263 259 //#ifdef DEBUG260 // NSLog(@"Naptr Rec in JSON: %@", [jsonItem descriptionInStringsFileFormat]);261 //#endif262 263 264 NSMutableDictionary *uiItem; 264 265 if (!jsonItem) { -
apps/iphone/my.tel/trunk/VIP.tel.xcodeproj/project.pbxproj
r628 r633 146 146 38E9DC800ED3222B000CD956 /* RecordViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 38E9DC7F0ED3222B000CD956 /* RecordViewController.m */; }; 147 147 38F0F72B0ED8AD4B00CF5196 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38F0F72A0ED8AD4B00CF5196 /* QuartzCore.framework */; }; 148 38FCE46810FB7B8000EA4525 /* HATypePickerController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 38FCE46710FB7B8000EA4525 /* HATypePickerController.xib */; }; 149 38FCE4B510FB839000EA4525 /* HATypePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 38FCE4B310FB839000EA4525 /* HATypePickerController.m */; }; 148 150 /* End PBXBuildFile section */ 149 151 … … 345 347 38E9DC7F0ED3222B000CD956 /* RecordViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecordViewController.m; sourceTree = "<group>"; }; 346 348 38F0F72A0ED8AD4B00CF5196 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 349 38FCE46710FB7B8000EA4525 /* HATypePickerController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HATypePickerController.xib; sourceTree = "<group>"; }; 350 38FCE4B210FB839000EA4525 /* HATypePickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HATypePickerController.h; sourceTree = "<group>"; }; 351 38FCE4B310FB839000EA4525 /* HATypePickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HATypePickerController.m; sourceTree = "<group>"; }; 347 352 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 348 353 /* End PBXFileReference section */ … … 616 621 380A663010877F0F00205110 /* HATextViewEditController.h */, 617 622 380A663110877F0F00205110 /* HATextViewEditController.m */, 623 38FCE4B210FB839000EA4525 /* HATypePickerController.h */, 624 38FCE4B310FB839000EA4525 /* HATypePickerController.m */, 618 625 380D47C310CD077800A35176 /* AccountEditController.h */, 619 626 380D47C410CD077800A35176 /* AccountEditController.m */, … … 686 693 380A663210877F0F00205110 /* HATextViewEditController.xib */, 687 694 380A673B108AF2AC00205110 /* HATextFieldEditController.xib */, 695 38FCE46710FB7B8000EA4525 /* HATypePickerController.xib */, 688 696 ); 689 697 name = NIBs; … … 861 869 38D9D34410CFFB9A00EC529B /* TabLoc.xib in Resources */, 862 870 385F284A10F6136A00BCBB14 /* KeywordTypesLongNames.plist in Resources */, 871 38FCE46810FB7B8000EA4525 /* HATypePickerController.xib in Resources */, 863 872 ); 864 873 runOnlyForDeploymentPostprocessing = 0; … … 921 930 380D47C210CD007900A35176 /* TextFieldCell.m in Sources */, 922 931 380D47C510CD077800A35176 /* AccountEditController.m in Sources */, 932 38FCE4B510FB839000EA4525 /* HATypePickerController.m in Sources */, 923 933 ); 924 934 runOnlyForDeploymentPostprocessing = 0;








