Today's Menu  Portugal
journal and plan nutrition
U7UsdaParamEntryViewController.m
Go to the documentation of this file.
1 //
2 // U7UsdaParamEntryViewController.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 8/9/16.
6 // Copyright © 2016 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 #import <UIKit/UIKit.h>
9 #import <HealthKit/HealthKit.h>
10 #import <QuartzCore/QuartzCore.h>
11 
13 #import "Z6ParamEditTotalView.h"
14 #import "Z6ParamValueEditView.h"
15 //#import "Y3GradientButton.h"
16 #import "Z5DataController.h"
17 #import "U3ParameterTableView.h"
18 #import "Z5TextField.h"
19 #import "Z5Colors.h"
20 #import "Z6MenuItemFocusView.h"
21 
23 
24 @property (strong, nonatomic) MenuItem *focusMenuItem;
25 
26 @end
27 
28 @implementation U7UsdaParamEntryViewController
29 {
30  CGRect parameterViewFrame;
32  NSIndexPath *swipedIndexPath;
35 
36  NSNumber *topOfPage;
37  NSNumber *featuresWidth;
38  NSNumber *sideMarginWidth;
39 }
40 
41 // NSMutableDictionary *newComponentSpecDict;
42 
44 NSInteger focusGallery;
45 // NSInteger pickedNutritionParameter;
46 // Boolean editParameterSelected;
47 
48 NSDictionary *usdaNumbersJsonInitial;
49 NSMutableDictionary *usdaNumbersJsonUpdated;
50 
51 
52 
53 - (id) initWithMenuItem:(MenuItem *)menuItem
54 {
55  self = [super init];
56  self.focusMenuItem = menuItem;
57  focusGallery = [self.focusMenuItem.galleryNumber integerValue];
58  self.title = @"Update Menu Item";
59  NSString *theNumbers = self.focusMenuItem.usdaNumbers;
60  NSLog(@"USDAparameterEntry.initWithItem: USDA #: %@", theNumbers);
61 
62  if (theNumbers) {
63  NSError *jsonError;
64  NSData *objectData = [theNumbers dataUsingEncoding:NSUTF8StringEncoding];
65  usdaNumbersJsonInitial = [NSJSONSerialization JSONObjectWithData:objectData
66  options:NSJSONReadingMutableContainers
67  error:&jsonError];
68  if (jsonError) {
69  NSLog(@"USDAparameterEntry.initWithItem: ERR: %@", jsonError);
70  } else {
71  NSLog(@"USDAparameterEntry.initWithItem: json: %@", usdaNumbersJsonInitial);
72  _nutritionComponents = [usdaNumbersJsonInitial mutableArrayValueForKey:@"usdaNumbers"];
73  }
74  }
75  if (!_nutritionComponents) {
76  _nutritionComponents = [[NSMutableArray alloc] init];
77  }
78 
79  [[[Z5DataController sharedInstance] localDataController] establishNutritionParameters];
80  return self;
81 }
82 
93 - (void)viewDidLoad {
94  [super viewDidLoad];
95  // Do any additional setup after loading the view.
96  [self.view setBackgroundColor:[UIColor colorWithHue:0.17 saturation:0.5 brightness:0.7 alpha:1.0]];
97 
98  // topOfPage, imageHeight, featuresWidth,
99  // and sideMarginWidth are class vars
100  CGRect totalFrame = self.view.frame;
101  CGRect topNavigationFrame = [[[self navigationController] navigationBar] frame];
102  // CGSize buttonSize = CGSizeMake(totalFrame.size.width * 0.42, 40.0);
103 
104  float topOfPageFloat = topNavigationFrame.origin.y + topNavigationFrame.size.height;
105  topOfPage = [[NSNumber alloc] initWithFloat:topOfPageFloat];
106  float featuresWidthFloat = totalFrame.size.width * 0.84;
107  featuresWidth = [[NSNumber alloc] initWithFloat:featuresWidthFloat];
108  float sideMarginWidthFloat = totalFrame.size.width * 0.08;
109  sideMarginWidth = [[NSNumber alloc] initWithFloat:sideMarginWidthFloat];
110 
111  // get and scale image for background
112  UIImage *backgrdImage = [UIImage imageNamed:@"red_barn_field.png"];
113  CGSize photoSize = [backgrdImage size];
114  float resizeRatio = photoSize.height / totalFrame.size.height;
115  UIImage *resizedImage = [UIImage imageWithCGImage:[backgrdImage CGImage]
116  scale:backgrdImage.scale * resizeRatio
117  orientation:(backgrdImage.imageOrientation) ];
118  UIImageView *backgrd = [[UIImageView alloc] initWithImage:resizedImage];
119  [self.view addSubview:backgrd];
120  // end - get and scale image for background
121 
122  // create section 0 header and footer views
123  menuItemView = [[Z6MenuItemFocusView alloc] initWithMenuItem:_focusMenuItem andDelegate: self];
124  editTotalView = [[Z6ParamEditTotalView alloc] initWithDelegate: self];
125  // end - create section 0 header and footer views
126 
127  parameterViewFrame = CGRectMake(sideMarginWidthFloat,
128  topOfPageFloat + 6,
130  [self parameterViewHeight]);
131  parameterTableView = [[U3ParameterTableView alloc] initWithFrame:parameterViewFrame
132  andComponents:_nutritionComponents
133  inContainer:self];
134  UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
135  gesture.direction = UISwipeGestureRecognizerDirectionRight;
136  [parameterTableView addGestureRecognizer:gesture];
137 
138  [parameterTableView setViewForHead:menuItemView];
139  [parameterTableView setViewForTail:editTotalView];
140 
141  [self.view addSubview:parameterTableView];
142 
143  UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"HealthKit"
144  style:UIBarButtonItemStylePlain
145  target:self
146  action:@selector(checkWithHealthKit)];
147  self.navigationItem.rightBarButtonItem = anotherButton;
148  self.navigationItem.rightBarButtonItem.enabled = YES;
149 }
150 - (void) viewDidAppear:(BOOL)animated
151 {
152  [super viewDidAppear:animated];
153 
155 
156  // animate section 0 header and footer views
157  [menuItemView appear:parameterTableView.bounds];
158  [editTotalView appear:self.view.bounds];
159  // end - animate section 0 header and footer views
160 }
161 - (void) viewWillAppear:(BOOL)animated
162 {
163  // capture parameters to json string
164  NSLog(@"USDAparameterEntry.viewWillAppear: usdaNumbers: %@", [self.focusMenuItem usdaNumbers]);
165 
166  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
167  NSError *error;
168  NSData *data = [[self.focusMenuItem usdaNumbers] dataUsingEncoding:NSUTF8StringEncoding];
169  if (data) {
170  NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data
171  options:kNilOptions
172  error:&error];
173  if (error) {
174  NSLog(@"USDAparameterEntry.viewWillAppear: error: %@", error);
175  } else {
176  NSLog(@"USDAparameterEntry.viewWillAppear: jsonResponse: %@", jsonResponse);
177  NSArray<NSDictionary *> *parameters = [jsonResponse mutableArrayValueForKey:@"usdaNumbers"];
178  NSArray<NSDictionary *> *parametersWithAuth = [localData annotateAuthority:parameters];
179  [parameterTableView update:parametersWithAuth];
180  [parameterTableView reloadData];
181  }
182  }
183  [editTotalView appear:parameterViewFrame];
184 }
185 - (void) viewWillDisappear:(BOOL)animated
186 {
187  NSLog(@"USDAparameterEntry.viewWillDisappear: usdaNumbers: %@", [self.focusMenuItem usdaNumbers]);
188  NSLog(@"USDAparameterEntry.viewWillDisappear: nutritionComponents: %@", _nutritionComponents);
189 
191 }
192 
194 {
195  // capture parameters to json string
196 // An object that may be converted to JSON must have the following properties:
197 // The top level object is an NSArray or NSDictionary.
198 // All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
199 // All dictionary keys are instances of NSString.
200 // Numbers are not NaN or infinity.
201 
202 
203  NSString *jsonReturn = @"{ \"usdaNumbers\" : [";
204  for (NSDictionary *nutritCompo in _nutritionComponents) {
205  NSString *nuroidAddition = [[NSString alloc] initWithFormat:@" { \"%@\" : \"%@\" , \"%@\" : \"%@\" } , ", [Z5LocalDataController componentNameKey], [nutritCompo objectForKey:[Z5LocalDataController componentNameKey]], [Z5LocalDataController componentValueKey], [nutritCompo objectForKey:[Z5LocalDataController componentValueKey]]];
206  jsonReturn = [jsonReturn stringByAppendingString:nuroidAddition];
207  }
208  jsonReturn = [jsonReturn stringByAppendingString:@"] }"];
209  NSLog(@"USDAparameterEntry.viewWillDisappear: jsonReturn: %@", jsonReturn);
210 
211  NSData *jsonReturnData = [jsonReturn dataUsingEncoding:NSUTF8StringEncoding];
212  NSError *err;
213  NSObject *jsonSerialized = [NSJSONSerialization JSONObjectWithData:jsonReturnData options:NSJSONReadingAllowFragments error:&err];
214  if (jsonSerialized) {
215  NSString *jsonSerializedClass = NSStringFromClass([jsonSerialized class]);
216  NSLog(@"USDAparameterEntry.viewWillDisappear: valid data, top class: %@", jsonSerializedClass);
217  if (([jsonSerializedClass isEqualToString:@"__NSCFDictionary"])
218  || ([jsonSerializedClass isEqualToString:@"__NSSingleEntryDictionaryI"])){
219  NSDictionary *jsonSerializedDict = (NSDictionary *)jsonSerialized;
220  NSObject *uNums = [jsonSerializedDict objectForKey:@"usdaNumbers"];
221  NSString *uNumsClass = NSStringFromClass([uNums class]);
222  NSLog(@"USDAparameterEntry.viewWillDisappear: uNumsClass: %@", uNumsClass);
223  // NSArray *jsonSerializedArray = (NSArray *)uNums;
224 
225  if ([NSJSONSerialization isValidJSONObject:jsonSerialized]) {
226  NSLog(@"USDAparameterEntry.viewWillDissappear: json is valid");
227  }
228  NSString *jsonString = [[NSString alloc] initWithData:jsonReturnData encoding:NSUTF8StringEncoding];
229 
230  NSLog(@"USDAparameterEntry.viewWillDissappear: ---> jsonString: %@", jsonString);
231  NSLog(@"USDAparameterEntry.viewWillDissappear: jsonSerializedDict: %@", [jsonSerializedDict descriptionWithLocale:nil]);
232 
233  [self.focusMenuItem setUsdaNumbers:jsonString];
234  } else if ([jsonSerializedClass isEqualToString:@"__NSSingleEntryDictionaryI"]) {
235  NSDictionary *jsonSerializedDict = (NSDictionary *)jsonSerialized;
236  NSObject *uNums = [jsonSerializedDict objectForKey:@"usdaNumbers"];
237  NSString *uNumsClass = NSStringFromClass([uNums class]);
238  NSLog(@"USDAparameterEntry.viewWillDisappear: single-entry dictionary: uNumsClass: %@", uNumsClass);
239  } else {
240  NSLog(@"USDAparameterEntry.viewWillDissappear: jsonSerializedClass: %@", jsonSerializedClass);
241  }
242  } else {
243  NSLog(@"USDAparameterEntry.viewWillDisappear: invalid data");
244  }
245  // store json string in data-base menu-item.usda-numbers
246  [[[Z5DataController sharedInstance] localDataController] saveContext];
247 
248 }
249 
251 {
252  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
253  NSSet *forAuthorizationCheck = [self produceSetWith: _nutritionComponents];
254  [localData getAddedAuthorizationToShare:forAuthorizationCheck forDelegate:self];
255 }
256 -(NSSet *) produceSetWith:(NSArray *)nutrComp
257 {
258  NSMutableSet *ret = [[NSMutableSet alloc] init];
259  for (NSDictionary *entry in nutrComp) {
260  NSLog(@"USDAparameterEntry.produceSetWith: entry: %@", entry);
261  NSString *caption = [entry objectForKey:[Z5LocalDataController componentNameKey]];
262  HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:[@"HKQuantityTypeIdentifierDietary" stringByAppendingString:caption]];
263  [ret addObject:rowQuantityType];
264  }
265  return ret;
266 }
267 
268 - (void) placeButtons
269 {
270  CGRect totalFrame = self.view.frame;
271  CGRect topNavigationFrame = [[[self navigationController] navigationBar] frame];
272  float topOfPageFloat = topNavigationFrame.origin.y + topNavigationFrame.size.height;
273  topOfPage = [[NSNumber alloc] initWithFloat:topOfPageFloat];
274  float featuresWidthFloat = totalFrame.size.width * 0.84;
275  featuresWidth = [[NSNumber alloc] initWithFloat:featuresWidthFloat];
276  float sideMarginWidthFloat = totalFrame.size.width * 0.08;
277  sideMarginWidth = [[NSNumber alloc] initWithFloat:sideMarginWidthFloat];
278 
279 // float newParameterPickerHeight = totalFrame.size.height * 0.20 ;
280 // float topOfPageF = [topOfPage floatValue];
281 //
282 // float parameterViewHeight = [self parameterViewHeight];
283 }
284 - (float) viewWidth
285 {
286  return self.view.frame.size.width;
287 }
292 {
293  return [menuItemView heightRequirement]
294  + [_nutritionComponents count] * 42
295  + [editTotalView heightRequirement]
296  + 12.0;
297 }
299 {
300  float parameterFramePerCentHeightMax = 0.26;
301  CGRect totalFrame = self.view.frame;
302  float paramLineHgtPerCent = 46.0 / totalFrame.size.height;
303 
304  // NSLog(@"USDAparameterEntry.parameterViewHeight: nutrComp count: %ld",(long) [nutritionComponents count]);
305 
306  float suggestedParamHeightPerCent = paramLineHgtPerCent * [_nutritionComponents count];
307  if (parameterFramePerCentHeightMax < suggestedParamHeightPerCent) {
308  suggestedParamHeightPerCent = parameterFramePerCentHeightMax;
309  }
310  float parameterViewHeight = totalFrame.size.height * suggestedParamHeightPerCent;
311  return parameterViewHeight;
312 }
313 -(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {
314 
315  if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
316  CGPoint swipeLocation = [gestureRecognizer locationInView:parameterTableView];
317  swipedIndexPath = [parameterTableView indexPathForRowAtPoint:swipeLocation];
318  UITableViewCell* swipedCell = [parameterTableView cellForRowAtIndexPath:swipedIndexPath];
319  NSLog(@"USDAparameterEntry.didSwipe: cell: %@", [swipedCell description]);
320  [swipedCell setBackgroundColor:[UIColor orangeColor]];
321 
322  [editTotalView showRemoveOption:YES];
323  [parameterTableView scrollForControlPanel];
324  }
325 }
326 
327 #pragma mark - Z5HealthConnectionProtocol
328 - (void) healthQuantityTypeData: (HKQuantityType *)quantityType success: (Boolean) flag
329 {
330  NSLog(@"USDAparameterEntry.healthQuantityTypeData");
331 }
333 {
334  NSLog(@"USDAparameterEntry.updateToAuthorizationOK");
335  [parameterTableView update:_nutritionComponents];
336  NSLog(@"USDAparameterEntry.healthQuantityTypeData: nutritionComponents: %@", _nutritionComponents);
337  [parameterTableView reloadData];
338 }
339 
340 #pragma mark - Z6ContainingView`
341 
342 - (CGRect) screenBound
343 {
344  return parameterViewFrame;
345 }
346 
347 #pragma mark - U3ParameterTableDelegate
348 - (void) didSelectParameterRow: (NSIndexPath *)iPath
349 {
350  editParameterIndexRow = [iPath row];
351 
352  [editTotalView configureToState:PICK_QUANTITY];
353  [self resizeParameterFrame];
354 }
356 {
357  return [self manageParameterViewFrame];
358 }
359 - (void) updatedParameterArray:(NSArray *)parameterArray;
360 {
361  [_nutritionComponents removeAllObjects];
362  [_nutritionComponents addObjectsFromArray:parameterArray];
363 
364  // [parameterTableView update:nutritionComponents];
365  // NSLog(@"USDAparameterView.updatedParameterArray: nutritionComponents: %@", nutritionComponents);
366 
368 }
369 
371 {
372  float parameterPanelHgt = [self parameterViewHeight] - 6;
373  if (parameterPanelHgt < 0) parameterPanelHgt = 0;
374  CGRect totalFrame = self.view.frame;
375  float parameterPanelHgtLimit = totalFrame.size.height - topOfPage.floatValue - 8;
376  if (parameterPanelHgt > parameterPanelHgtLimit) {
377  NSLog(@"USDAparamEntryController.manageParameterViewFrame: limit vertical from %3.2f to %3.2f", parameterPanelHgt, parameterPanelHgtLimit);
378  parameterPanelHgt = parameterPanelHgtLimit;
379  }
380  parameterViewFrame = CGRectMake([sideMarginWidth floatValue],
381  [topOfPage floatValue]
382  + 6,
383  [featuresWidth floatValue], parameterPanelHgt);
384  [parameterTableView setFrame:parameterViewFrame];
385  [parameterTableView reloadData];
386  if ([parameterTableView parameterCount] > 0) {
387  NSIndexPath *addIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
388  [parameterTableView scrollToRowAtIndexPath:addIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
389  }
390  NSLog(@"USDAparameterView.manageParameterViewFrame: %3.2f/%3.2f %3.2f/%3.2f", parameterViewFrame.origin.x, parameterViewFrame.origin.y, parameterViewFrame.size.width, parameterViewFrame.size.height);
391 
392  return parameterPanelHgt;
393 }
394 // - (void) didSelectGalleryMenuItem:(MenuItem *) menuItem
395 // {
396 // NSLog(@"USDAparameterView.didSelectGalleryMenuItem)");
397 // }
398 
399 #pragma mark - Z6ParamEditTotalDelegate
400 - (void) configureToState:(TotalEditStateEnum) state
401 {
402  // TODO: do
403 }
405 {
406  [parameterTableView scrollForControlPanel];
407 }
409 {
410  NSLog(@"USDAparameterEntry: clickRemoveButton");
411  [editTotalView showRemoveOption:NO];
412 
413  NSLog(@"USDAparameterEntry.clickRemoveButton: remove %@", swipedIndexPath);
414  NSInteger tRow = [swipedIndexPath row];
415  [_nutritionComponents removeObjectAtIndex:tRow];
416  [parameterTableView update:_nutritionComponents];
417  [self placeButtons];
418 
419  // put revised data in local data
421 }
422 
423 - (void) addParameter: (NSDictionary *)newComponentSpecDict
424 {
425  NSString *specDictName = [newComponentSpecDict objectForKey:[Z5LocalDataController componentNameKey]];
426  if (0 <= [parameterTableView isListedAlready:specDictName]) {
427  NSLog(@"USDAparameterView.addParameter: RESTART HERE: %@ already listed", specDictName);
428  [parameterTableView updateParameter:newComponentSpecDict];
429  } else {
430  [parameterTableView addParameter:newComponentSpecDict];
431  }
432 
433  // put revised data in local data
435 }
436 
438 {
439  [self.view setNeedsDisplay];
440 }
441 - (NSDictionary *) selectedParameterList;
442 {
443  NSDictionary *selectParameters;
444  if ((0 < [_nutritionComponents count]) && (0 <= editParameterIndexRow)) {
445  if ([_nutritionComponents count] > editParameterIndexRow) {
446  selectParameters = [_nutritionComponents objectAtIndex:editParameterIndexRow];
447  } else {
448  NSLog(@"USDAparameterEntry.selectedParameterList: editParameterIndexRow: %ld nutritionComponents count: %lu", (long)editParameterIndexRow, (unsigned long)[_nutritionComponents count] );
449  }
450  } else {
451  selectParameters = [[NSDictionary alloc] init];
452  }
453  return selectParameters;
454 }
455 
457  // <*code*>
458  NSLog(@"USDAParameterEntryViewController.getTotalEditState: returns INITIAL_STATE");
459  return INITIAL_STATE;
460 }
462 {
463  // [parameterTableView reloadData];
464  // [self.view setNeedsDisplay];
465  [parameterTableView setViewForTail:editTotalView];
467 }
468 
469 #pragma mark - Z6MenuItemControlbarDelegate
470 
472 {
473  // TODO: do
474 }
475 - (void) addMenuItemOnToday:(UIButton *)sender
476 {
477  // TODO: do
478 }
479 
480 #pragma mark - Z6ParamValueEditDelegate
481 
482 #pragma mark - UIPickerViewDataSource
483 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
484 {
485  assert (nil);
486  return 0;
487 }
488 - (NSInteger)pickerView:(UIPickerView *)pickerView
489 numberOfRowsInComponent:(NSInteger)component
490 {
491  assert(nil);
492  return 0;
493 }
494 #pragma mark -
495 
496 #pragma mark (removed UITextFieldDelegate)
497 //- (void)textFieldDidEndEditing:(UITextField *)textField
498 //{
499 // [self.focusMenuItem setName:[textField text]];
500 // // also at this point change to attributed
501 // UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:22];
502 // NSDictionary *attribs = @{
503 // NSForegroundColorAttributeName: [UIColor blackColor],
504 // NSFontAttributeName: herefont
505 // };
506 // NSMutableAttributedString *attributedText =
507 // [[NSMutableAttributedString alloc] initWithString:[textField text]
508 // attributes:attribs];
509 // // [menuItemNameTextField setAttributedText:attributedText];
510 //
511 // }
512 //- (BOOL)textFieldShouldReturn:(UITextField *)textField {
513 // [textField resignFirstResponder];
514 // return NO;
515 //}
516 
517 
518 #pragma mark - (removed U7ParamEditControlDelegate)
519 
520 //- (void) clickPlusButton
521 //{
522 // NSLog(@"USDAparameterEntry: clickPlusButton");
523 //
524 // [editTotalView showAddSelectionButton:NO];
525 // [self showPickerView];
526 // [self placeButtons];
527 // [editTotalView showEditButton:YES];
528 //}
529 //- (void) clickEditButton
530 //{
531 // NSLog(@"USDAparameterEntry: clickEditButton");
532 // if ( !editParameterSelected ) {
533 // editParameterSelected = YES;
534 // [newParameterPickerView reloadAllComponents];
535 // // i must set pickQuantityType and picQuantityUnit here
536 // [self establishPick:newParameterIndex];
537 //
538 // [self setupDimensionWheel];
539 // return;
540 // }
541 //
542 // NSDictionary *editSource = [nutritionComponents objectAtIndex:editParameterIndexRow];
543 // [self showPickerView];
544 // [self placeButtons];
545 //
546 // NSString *caption = [editSource objectForKey:[Z5LocalDataController componentNameKey]];
547 // HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:[@"HKQuantityTypeIdentifierDietary"
548 //stringByAppendingString:caption]];
549 //
550 // HKQuantity *componentQuanValue = [editSource objectForKey:[Z5LocalDataController componentValueKey]];
551 // NSString *valueCaption = [componentQuanValue description];
552 // NSArray<NSString *> *pieces = [valueCaption componentsSeparatedByString:@" "];
553 // HKUnit *hkUnit = nil;
554 // float quantityScalar = [pieces[0] floatValue];
555 // if ([@"mcg" isEqualToString:pieces[1]]) {
556 // HKMetricPrefix microPrefix = HKMetricPrefixMicro;
557 // hkUnit = [HKUnit gramUnitWithMetricPrefix:microPrefix];
558 // } else if ([@"mg" isEqualToString:pieces[1]]) {
559 // HKMetricPrefix milliPrefix = HKMetricPrefixMilli;
560 // hkUnit = [HKUnit gramUnitWithMetricPrefix:milliPrefix];
561 // }
562 // HKQuantity *hkQuantity = [HKQuantity quantityWithUnit:hkUnit doubleValue:quantityScalar];
563 //
564 // // [self setPickerType:rowQuantityType andQuantity:hkQuantity];
565 // int intScalar = (int)quantityScalar;
566 // [self setPickerType:rowQuantityType scalar:intScalar andUnit:pieces[1]];
567 //
568 // [editTotalView showEditButton:NO];
569 //}
570 
571 //- (void)configureToState:(TotalEditStateEnum)state {
572 // <#code#>
573 //}
574 
576 // * add to USDA dictionary at this point
577 // */
578 //- (void) clickAcceptButton
579 //{
580 //
581 // // amount
582 // NSInteger hundreds = [newParameterPickerView selectedRowInComponent:1];
583 // NSInteger tens = [newParameterPickerView selectedRowInComponent:2];
584 // NSInteger ones = [newParameterPickerView selectedRowInComponent:3];
585 // double inputValue = 100*hundreds + 10*tens + ones;
586 // double nutritionAmount = inputValue; // = pickerValue;
587 // // END -- amount
588 //
589 // // units
590 // NSUInteger unitIndex = [newParameterPickerView selectedRowInComponent:4];
591 // // NSString *units = [pickerWheel4Titles objectAtIndex:unitIndex];
592 // HKUnit *massUnit = [HKUnit unitFromString:@"g"];
593 // HKUnit *energyUnit = [HKUnit unitFromString:@"cal"];
594 // HKMetricPrefix metricPrefix;
595 // HKQuantity *acceptQuantity;
596 // if ([pickQuantityType isCompatibleWithUnit:massUnit]) {
597 // metricPrefix = massUnitsMetricPrefixArray[unitIndex];
598 // HKUnit *prefixGramUnit = [HKUnit gramUnitWithMetricPrefix:metricPrefix];
599 // acceptQuantity = [HKQuantity quantityWithUnit:prefixGramUnit doubleValue:nutritionAmount];
600 // } else if ([pickQuantityType isCompatibleWithUnit:energyUnit]) {
601 // switch(unitIndex) {
602 // case 0:
603 // acceptQuantity = [HKQuantity quantityWithUnit:[HKUnit calorieUnit] doubleValue:nutritionAmount];
604 // break;
605 // case 1:
606 // acceptQuantity = [HKQuantity quantityWithUnit:[HKUnit calorieUnit] doubleValue:nutritionAmount];
607 // break;
608 // }
609 // }
610 // // END -- units
611 //
612 // NSLog(@"USDAparameterEntry.clickAcceptButton: quantity: %@", acceptQuantity);
613 //
614 // [newComponentSpecDict setObject:acceptQuantity forKey:[Z5LocalDataController componentValueKey]];
615 //
616 // // https://developer.apple.com/library/ios/documentation/HealthKit/Reference/HealthKit_Constants/index.html#//apple_ref/doc/constant_group/Nutrition_Identifiers
617 // // HKQuantityType *acceptedQuantityType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDietarySodium];
618 // // [acceptedQuantityType.canonicalUnit]
619 //
620 // NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
621 // HKQuantitySample *acceptedSample = [HKQuantitySample quantitySampleWithType:pickQuantityType
622 //quantity:acceptQuantity
623 //startDate:now
624 //endDate:now];
625 // [newComponentSpecDict setObject:acceptedSample forKey:[Z5LocalDataController componentSampleKey]];
626 // [parameterTableView addParameter:newComponentSpecDict];
627 //
628 // Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
629 // NSNumber *typeAuthorization = [localData checkTypeAuthorization:pickQuantityType];
630 // [newComponentSpecDict setObject:typeAuthorization forKey:[Z5LocalDataController componentAuthorityKey]];
631 //
632 // [self removeSamplePickerView];
633 //}
638 //- (void) clickCancelButton
639 //{
640 // [self removeSamplePickerView];
641 // [editTotalView showEditButton:NO];
642 //}
643 //- (void) removeSamplePickerView
644 //{
645 // NSLog(@"USDAparameterEntry.removeSamplePickerView");
646 // [newParameterPicker setHidden:YES];
647 //
648 // [editTotalView showReadyToConfirm];
649 // [self placeButtons];
650 // // [parameterPlusButton setFrame:newParameterPlusFrame];
651 //}
652 - (UIView *) createParameterValueEntryViewWithFrame: (CGRect) frame caption: (NSString *) nutrCaption
653 {
654  CGRect parameterNameRect = CGRectMake(0, 0, 90, 38);
655  CGRect parameterValueRect = CGRectMake(90, 0, 70, 38);
656  UIView* ret = [[UIView alloc] initWithFrame:frame];
657  [ret setBackgroundColor:[UIColor blueColor]];
658 
659  UILabel *parameterType = [[UILabel alloc] initWithFrame:parameterNameRect];
660  [parameterType setBackgroundColor:[UIColor grayColor]];
661  [parameterType setText:nutrCaption];
662  [ret addSubview:parameterType];
663 
664  UITextField *parameterValue = [[UITextField alloc] initWithFrame:parameterValueRect];
665  [parameterValue setBackgroundColor:[UIColor lightGrayColor]];
666  [ret addSubview:parameterValue];
667 
668  return ret;
669 }
670 
671 - (NSString *) stringForPickerRow99: (NSInteger) row
672 {
673  NSString *ret;
674  if ((row >= 0) && (row < [[[[Z5DataController sharedInstance] localDataController] availableNutritionParamArray] count])) {
675 
676  // get nutrition component code
677  NSString *rowQuantityTypeClue = [[[[Z5DataController sharedInstance] localDataController] availableNutritionParamArray] objectAtIndex:row];
678 
679  // convert to QuantityType
680  HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:rowQuantityTypeClue];
681 
682  // convert back to a string
683  NSString *rowQuanTypeString = [rowQuantityType description];
684  // NSLog(@"USDAparameterEntry.stringForPickerRow: rowQuantityType: %@", rowQuanTypeString);
685 
686  // pick out last portion of nutrition component code
687  NSString *protoCaption = [rowQuanTypeString substringFromIndex:31]; // length 'HKQuantityTypeIdentifierDietary' = 31
688  ret = protoCaption;
689  } else {
690  ret = @"-?-";
691  }
692 
693  return ret;
694 }
695 
696 #pragma mark - remainder
698  [super didReceiveMemoryWarning];
699  // Dispose of any resources that can be recreated.
700 }
701 
702 
703  #pragma mark - storyboard Navigation
704 
705  // In a storyboard-based application, you will often want to do a little preparation before navigation
706  // - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
707  // Get the new view controller using [segue destinationViewController].
708  // Pass the selected object to the new view controller.
709 
710 @end
void clickRemoveButton()
NSInteger focusGallery
void getAddedAuthorizationToShare:forDelegate:(NSSet *writeNutrTypes, [forDelegate] id< Z5HealthConnectionProtocol > requestFrom)
void viewDidLoad()
void updateToAuthorizationOK()
float resizeParameterFrame()
void captureNutritionComponents()
void didReceiveMemoryWarning()
void scrollForControlPanel()
NSSet * produceSetWith:(NSArray *nutrComp)
MenuItem * menuItem
void placeButtons()
instancetype sharedInstance()
void needsRedisplay()
U3ParameterTableView * parameterTableView
CGRect screenBound()
NSNumber * sideMarginWidth
TotalEditStateEnum
NSDictionary * selectedParameterList()
float parameterViewHeight()
MenuItem * focusMenuItem
Z6ParamEditTotalView * editTotalView
TotalEditStateEnum getTotalEditState()
NSNumber * featuresWidth
float featuresWidthFloat
float parameterViewHeight2()
void fireRecipeCheck()
Singleton interface to both core and remote data sources.
NSIndexPath * swipedIndexPath
void showUpdatedHeaderFooter()
Z6MenuItemFocusView * menuItemView
float manageParameterViewFrame()
NSMutableDictionary * usdaNumbersJsonUpdated
NSInteger editParameterIndexRow
NSMutableArray * annotateAuthority:(NSArray *componentArray)
void checkWithHealthKit()
float sideMarginWidthFloat
NSDictionary * usdaNumbersJsonInitial
NSNumber * topOfPage
float viewWidth()