9 #import <HealthKit/HealthKit.h> 262 NSMutableArray<NSString *> *
rows;
296 self.title =
@"Menu Choices";
307 [
self.view addSubview:parameterTableView];
314 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
315 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
319 -(void) viewDidAppear:(BOOL)animated
326 [parameterTableView update:nutritionComponents];
332 [menuPanoramaView appear:self.view.bounds];
333 [dateTimeView setLabelCaption:@"the menu today"];
334 [dateTimeView appear:self.view.bounds];
335 [menuApproveView appear:self.view.bounds];
336 [menuApprovalInstructions appear:self.view.bounds];
342 NSLog(
@"Y4NutritionViewController.viewDidAppear: todays count: %ld", (
unsigned long)[todays count]);
343 [parameterTableView updateMenu:todays];
350 CGRect totalFrame =
self.view.frame;
355 float verticalHeight = [parameterTableView getViewHeightReqmt];
356 float maxVertical = totalFrame.size.height - verticalPos;
357 if (verticalHeight > maxVertical) {
358 verticalHeight = maxVertical - 4.0;
361 CGRect tableViewFrame = CGRectMake(2.0, verticalPos, totalFrame.size.width - 4.0, verticalHeight);
364 [parameterTableView setFrame:tableViewFrame];
368 - (void) viewWillDisappear:(BOOL)animated
371 [[NSNotificationCenter defaultCenter] removeObserver: self];
372 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
379 Boolean ret = [HKHealthStore isHealthDataAvailable];
381 NSLog(
@"Y4NutritionViewController.initHK: HKHealthStore is available");
391 - (void)deviceOrientationDidChange:(NSNotification *)notification {
398 return self.view.bounds;
400 #pragma mark - ZOrientProtocol 405 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
408 case UIDeviceOrientationPortrait:
409 case UIDeviceOrientationFaceUp:
415 case UIDeviceOrientationLandscapeLeft:
416 case UIDeviceOrientationLandscapeRight:
431 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
434 case UIDeviceOrientationPortrait:
435 case UIDeviceOrientationFaceUp:
441 case UIDeviceOrientationLandscapeLeft:
442 case UIDeviceOrientationLandscapeRight:
516 CGSize viewSize =
self.view.frame.size;
519 [backgrdImageView setContentMode:UIViewContentModeScaleAspectFill];
520 [
self.view addSubview:backgrdImageView];
523 +
self.navigationController.navigationBar.frame.size.height;
526 CGRect totalFrame =
self.view.frame;
528 float tableWidth =
self.view.bounds.size.width;
529 CGRect headFrame = CGRectMake(4.0, 0.0, tableWidth - 12.0, 90.0);
532 NSNumber *galleryOne = [NSNumber numberWithInt:1];
534 NSInteger menuItemCount = [dataMenuItems count];
535 NSLog(
@"Y4NutritionViewController.viewDidLoad: count of all menu items in d/b: %ld", (
unsigned long)menuItemCount);
536 if (0 < menuItemCount) {
539 NSLog(
@"Y4NutritionViewController.viewDidLoad: headerVert: %3.2f", headerVert);
544 [menuPanoramaView setBackgroundColor:[UIColor cyanColor]];
551 CGRect tailFrame = CGRectMake(4.0, 0.0, tableWidth - 8.0, 46.0);
553 [menuItemControlBar showBar:YES];
564 CGRect dateTimeViewFrame = CGRectMake(0.0, 0.0, tableWidth - 8.0, dateTimeViewFrameHeight);
570 NSNumber *labelHeight = [NSNumber numberWithFloat:64.0];
571 [menuApprovalInstructions setContainedHeight:labelHeight];
577 CGRect tableViewFrame = CGRectMake(6.0, verticalPos, totalFrame.size.width - 12, 220.0);
585 initWithFrame: tableViewFrame
586 andComponents:focusUSDAparameterArray
589 [parameterTableView setViewForHead:menuPanoramaView];
590 [parameterTableView setViewForTail:menuItemControlBar];
591 [parameterTableView setViewForMenuHead:menuApproveView];
592 [parameterTableView setViewForMenuTail:menuApprovalInstructions];
593 [parameterTableView setNeedsDisplay];
595 float parameterTableHgt = [parameterTableView getViewHeightReqmt];
596 float tableVertical = parameterTableHgt;
600 tableViewFrame = CGRectMake(2.0, verticalPos, totalFrame.size.width - 4, tableVertical + 2.0);
601 [parameterTableView setFrame:tableViewFrame];
606 verticalPos += (parameterTableHgt+2);
614 CGSize viewSize =
self.view.frame.size;
617 [backgrdImageView setContentMode:UIViewContentModeScaleAspectFill];
618 [
self.view addSubview:backgrdImageView];
623 CGSize viewSize =
self.view.frame.size;
625 [backgrdImageView setImage:resizedImage];
629 CGSize viewSize =
self.view.frame.size;
631 [backgrdImageView setImage:resizedImage];
640 #pragma mark - factoring 643 float tableWidth =
self.view.bounds.size.width;
645 CGRect noChoiceLabelFrame = CGRectMake(2.0, 2.0, tableWidth-40.0, 42.0);
649 [noChoiceLabel postAttributedText:@"Empty database, refresh through messages"];
650 [noChoiceLabel setTextColor:[UIColor blackColor]];
651 [noChoiceLabel setOpaque:YES];
652 [noChoiceLabel setBackgroundColor:[UIColor greenColor]];
654 [noChoiceLabel.layer setBorderColor: [[UIColor blackColor] CGColor]];
655 [noChoiceLabel.layer setBorderWidth: 2.0];
656 noChoiceLabel.layer.cornerRadius = 8.0f;
657 noChoiceLabel.layer.masksToBounds = YES;
659 [tableNoChoice setMessageLabel:noChoiceLabel];
660 NSNumber *labelHeight = [NSNumber numberWithFloat:50.0];
661 [tableNoChoice setContainedHeight:labelHeight];
662 return tableNoChoice;
665 float tableWidth =
self.view.bounds.size.width;
667 CGRect jumpToMsgsInstructionFrame = CGRectMake(30.0, 160.0, tableWidth - 60.0, 180.0);
668 UIButton *jumpToMsgsInstruction = [[UIButton alloc] initWithFrame:jumpToMsgsInstructionFrame];
669 [jumpToMsgsInstruction setBackgroundColor:[UIColor greenColor]];
670 [jumpToMsgsInstruction setTitle:@"Scan the mail\nfor messages\nor jump to the web or drive\nor even take a snapshot" forState:UIControlStateNormal];
671 [jumpToMsgsInstruction setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
672 [jumpToMsgsInstruction addGradientFace:[UIColor blueColor]];
673 [jumpToMsgsInstruction addTarget:self action:@selector(jumpToMenuItemCreate) forControlEvents:UIControlEventTouchUpInside];
674 return jumpToMsgsInstruction;
677 - (NSArray *) fetchMenuChoicesGalleryNum:(NSNumber *)galleryNum
683 return localDataMenuItems;
691 -(NSArray *)usdaArrayFromJSON: (NSString *)jsonString
693 NSLog(
@"Y4NutritionViewController.menuParameterArray: jsonString: %@", jsonString);
694 NSData *jsonReturnData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
696 if (jsonReturnData) {
697 NSObject *jsonSerialized = [NSJSONSerialization JSONObjectWithData:jsonReturnData options:NSJSONReadingAllowFragments error:&err];
698 if (jsonSerialized) {
699 NSString *jsonSerializedClass = NSStringFromClass([jsonSerialized
class]);
700 NSLog(
@"Y4NutritionViewController.menuParameterArray: valid data, top class: %@", jsonSerializedClass);
701 if (([jsonSerializedClass isEqualToString:
@"__NSCFDictionary"])
702 || ([jsonSerializedClass isEqualToString:
@"__NSSingleEntryDictionaryI"])) {
703 NSDictionary *jsonSerializedDict = (NSDictionary *)jsonSerialized;
704 NSObject *uNums = [jsonSerializedDict objectForKey:@"usdaNumbers"];
705 NSString *uNumsClass = NSStringFromClass([uNums
class]);
706 NSLog(
@"Y4NutritionViewController.menuParameterArray: uNumsClass: %@", uNumsClass);
707 NSArray *jsonSerializedArray = (NSArray *)uNums;
708 return jsonSerializedArray;
720 #pragma mark manage screen 722 -(void) hideSelectedItemInfo:(Boolean)hideFlag
724 self.addItemOnToday.hidden = hideFlag;
740 NSString *focusUsdaNumbers = nil;
742 NSString *focusRandomkey = [galleryFocusMenuItem randomkey];
744 if (focusRandomkey) {
747 if (focusUsdaNumbers) {
750 focusUsdaNumbers =
@"";
753 NSLog(
@"Y4NutritionViewController.updateParameterList: usda: %@",
756 NSLog(
@"Y4NutritionViewController.updateParameterList: no focus item");
772 NSLog(
@"Y4NutritionViewController.focusGallery: focusMenuItem randomkey: %@", [
galleryFocusMenuItem randomkey]);
782 if ([todaysMenuItems count]) {
791 [parameterTableView update:focusUSDAparameterArray];
800 NSIndexPath *addIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
802 [parameterTableView scrollToRowAtIndexPath:addIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
810 [menuItemControlBar setHidden:NO];
811 [menuItemControlBar showBar:YES];
813 [menuItemControlBar setHidden:YES];
814 [menuItemControlBar showBar:NO];
824 CGRect totalFrame =
self.view.frame;
825 float paramLineHgt = 42.0 / totalFrame.size.height;
827 NSLog(
@"nutritionCollectionView.parameterViewHeight: nutrComp count: %ld",(
unsigned long)[
focusUSDAparameterArray count]);
829 float suggestedParamHeight = paramLineHgt * [focusUSDAparameterArray count];
831 if (0.28 < suggestedParamHeight) {
832 suggestedParamHeight = 0.28;
836 NSLog(
@"nutritionCollectionView.parameterViewHeight: OVERALL parameterViewHeight: %3.2f",
parameterViewHeight);
843 NSLog(
@"USDAparameterEntry.placeButtons: parameterViewHeight: %3.2f", [
self parameterViewHeight]);
849 [[
self navigationController] pushViewController:vc3 animated:YES];
852 #pragma mark - Z6MenuPanoramaDelegate 853 - (void) clickedMenuItem: (
MenuItem *) menuItem atRow: (NSUInteger) row
857 NSLog(
@"Y4NutritionViewController.clickedMenuItem: galleryFocusMenuItem: %@",
galleryFocusMenuItem);
864 NSLog(
@"NutritionViewController.clickedMenuItem: info: %@", info);
875 [parameterTableView update:focusUSDAparameterArray];
877 NSInteger nRowsSect0 = [parameterTableView numberOfRowsInSection:0];
878 NSIndexPath *firstIndex = [NSIndexPath indexPathForRow:0 inSection:0];
879 if (0 < nRowsSect0) {
880 [parameterTableView scrollToRowAtIndexPath:firstIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
882 NSLog(
@"NutritionViewController.clickedMenuItem: Huh?");
885 NSLog(
@"NutritionViewController.clickedMenuItem: no parameters for selected item");
893 [parameterTableView update:nil];
899 - (Boolean) getSelectedGalleryRow:(NSUInteger *)inforow
904 NSLog(
@"Y4NutritionViewController.getSelectedGalleryRow: %lu", (
unsigned long)
galleryFocusRow);
906 NSLog(
@"Y4NutritionViewController.getSelectedGalleryRow: no Selection");
910 #pragma mark - <Z5HealthConnectionProtocol> 911 - (void) healthQuantityTypeData: (HKQuantityType *)quantityType success: (Boolean) flag
913 NSLog(
@"Y4NutritionViewController.healthQuantityTypeData: ?");
917 [parameterTableView reloadData];
921 #pragma mark <U3ParameterTableDelegate> 924 - (void) updatedParameterArray:(NSArray *)menuItemArray
926 NSLog(
@"Y4NutritionViewController.updatedParameterArray, called after table-view update");
927 [focusUSDAparameterArray removeAllObjects];
928 [focusUSDAparameterArray addObjectsFromArray:menuItemArray];
933 float parameterPanelHeight = [parameterTableView getViewHeightReqmt];
935 NSLog(
@"Y4NutritionViewController.resizeParameterFrame: parameterPanelHeight: %3.2f", parameterPanelHeight);
937 CGRect totalFrame =
self.view.frame;
939 float verticalHeight = [parameterTableView getViewHeightReqmt];
940 float maxVertical = totalFrame.size.height - verticalPos;
941 if (verticalHeight > maxVertical) {
942 verticalHeight = maxVertical - 4.0;
945 CGRect tableViewFrame = CGRectMake(2.0, verticalPos, totalFrame.size.width - 4, verticalHeight);
946 [parameterTableView setFrame:tableViewFrame];
948 return parameterPanelHeight;
951 - (void) didSelectParameterRow: (NSIndexPath *)iPath
956 #pragma mark - Z6MenuItemControlbarDelegate 967 [
self.navigationController pushViewController:recipeView animated:YES];
970 NSLog(
@"CollectionView.fireRecipeCheck: nil focusMenuItem");
980 - (
void )addMenuItemOnToday:(UIButton *)sender {
982 NSLog(
@"Y4NutritionViewController.addMenuItemOnToday ==========%@===============", [
galleryFocusMenuItem name]);
988 [parameterTableView updateMenu:q];
994 NSLog(
@"Y4NutritionViewController.addMenuItemOnToday: currentParameters: %@", currentParameters);
996 if (!currentParameters) {
1002 [parameterTableView scrollForInstructionPanel];
1005 #pragma mark <U3MenuTableDelegate> 1010 NSDate *dayBegin = nil;
1019 - (void) updatedMenuItemArray:(NSArray *)menuItemArray
1021 NSLog(
@"Y4NutritionViewController.updatedMenuItemArray: ??");
1029 CGRect totalFrame =
self.view.frame;
1030 float leftMargin = 0.02*totalFrame.size.width;
1032 float controlWidth = 0.96*totalFrame.size.width;
1034 float menuItemListPanelHeight = [parameterTableView getViewHeightReqmt];
1035 CGRect menuItemParametersFrame = CGRectMake(leftMargin, topMargin + 4, controlWidth, menuItemListPanelHeight);
1036 [parameterTableView setFrame:menuItemParametersFrame];
1038 NSLog(
@"Y4NutritionViewController.resizeMenuItemFrame: height: %3.2f", menuItemParametersFrame.size.height);
1040 return menuItemListPanelHeight;
1043 - (void) didSelectMenuItemRow: (NSIndexPath *)iPath
1045 NSLog(
@"Y4NutritionViewController.didSelectMenuItemRow: NO-OP NO-OP");
1074 NSLog(
@"NutritionViewController.didTapMenuFooter");
1078 [parameterTableView setNeedsDisplay];
1082 NSLog(
@"NutritionViewController.didTapClearFooter");
1086 [parameterTableView updateMenu:todays];
1096 if (0 < [[localData todaysMenuItems] count]) {
1100 NSDate *rightNow = [NSDate dateWithTimeIntervalSinceNow:0];
1105 [
self.navigationController pushViewController:mealView animated:YES];
1108 NSLog(
@"NutritionCollectionView.didTapBravoFooter: no items in todays menu");
1113 NSLog(
@"NutritionCollectionView.didTapNetworkFooter");
1118 CGFloat yOffset = 0;
1124 [parameterTableView setContentOffset:CGPointMake(0, yOffset) animated:NO];
1127 #pragma mark button action 1130 NSLog(
@"NutritionView.clickClearDay");
1138 [parameterTableView update:nil];
1139 [parameterTableView setNeedsDisplay];
1142 float parameterTableHgt = [parameterTableView getViewHeightReqmt];
1144 CGRect totalFrame =
self.view.bounds;
1145 CGRect tableViewFrame = CGRectMake(2.0, verticalPos, totalFrame.size.width - 4, parameterTableHgt);
1146 [parameterTableView setFrame:tableViewFrame];
1153 NSLog(
@"NutritionCollectionView.clickMenuItemTodayButton");
1161 NSLog(
@"NutritionCollectionView.clickAction");
1165 [parameterTableView setInitialSectionCollapsed:YES];
1167 [
self.view setNeedsDisplay];
1187 NSString *redText =
@"red text";
1188 NSString *greenText =
@"green text";
1189 NSString *purpleBoldText =
@"purple bold text";
1191 NSString *text = [NSString stringWithFormat:@"Here are %@, %@ and %@",
1197 if ([
self.
label respondsToSelector:
@selector(setAttributedText:)]) {
1200 NSDictionary *attribs = @{
1201 NSForegroundColorAttributeName:
self.label.textColor,
1202 NSFontAttributeName:
self.label.font
1204 NSMutableAttributedString *attributedText =
1205 [[NSMutableAttributedString alloc] initWithString:text
1206 attributes:attribs];
1209 UIColor *redColor = [UIColor redColor];
1210 NSRange redTextRange = [text rangeOfString:redText];
1211 [attributedText setAttributes:@{NSForegroundColorAttributeName:redColor}
1212 range:redTextRange];
1215 UIColor *greenColor = [UIColor greenColor];
1216 NSRange greenTextRange = [text rangeOfString:greenText];
1217 [attributedText setAttributes:@{NSForegroundColorAttributeName:greenColor}
1218 range:greenTextRange];
1221 UIColor *purpleColor = [UIColor purpleColor];
1222 UIFont *boldFont = [UIFont boldSystemFontOfSize:self.label.font.pointSize];
1223 NSRange purpleBoldTextRange = [text rangeOfString:purpleBoldText];
1224 [attributedText setAttributes:@{NSForegroundColorAttributeName:purpleColor,
1225 NSFontAttributeName:boldFont}
1226 range:purpleBoldTextRange];
1228 self.label.attributedText = attributedText;
1232 self.label.text = text;
1279 [
super didReceiveMemoryWarning];
NSUInteger galleryFocusRow
NSInteger editMenuItemIndexRow
NSString * nutritionMenuPortraitBackgroundName
UIView< Z6ContainedView > * menuPanoramaView
void viewDidAppearPortrait()
void jumpToMenuItemCreate()
void extraLabelize:withText:(UILabel *targLabel, [withText] NSString *txt)
MenuItem * galleryFocusMenuItem
Z1ContainedLabel * menuApprovalInstructions
float resizeMenuItemFrame()
NSArray< MenuItem * > * retrieveAllMenuItems:(NSNumber *galleryNo)
Z6MenuItemControlbar * menuItemControlBar
U3MenuChoicesTableView * parameterTableView
void positionFramesLandscape()
void viewDidAppearLandscape()
void viewDidLoadPortrait()
U5MealPanoramaView * tableSpecial
instancetype sharedInstance()
UIView< Z6ContainedView > * menuApproveView
UIImageView * backgrdImageView
void hideSelectedItemInfo:(Boolean hideFlag)
NSArray * fetchMenuChoicesGalleryNum:(NSNumber *galleryNum)
void updateToAuthorizationOK()
void logTodaysMenu:(NSString *caption)
void didReceiveMemoryWarning()
UIImage * imageNamed:sizedToPortrait:(NSString *imageName, [sizedToPortrait] CGSize imageSize)
void clickMenuItemTodayButton()
void todaysMealRequested:(NSDate *date)
Z1ContainedLabel * produceNoChoicesLabel()
UIImage * imageNamed:sizedToLandscape:(NSString *imageName, [sizedToLandscape] CGSize imageSize)
void viewDidLoadLandscape()
NSMutableArray * focusUSDAparameterArray
UICollectionViewCell * currentlySelectedCell
NSString * nutritionMenuLandscapeBackgroundName
Singleton interface to both core and remote data sources.
float resizeParameterFrame()
NSArray * usdaArrayFromJSON:(NSString *jsonString)
float parameterViewHeight()
Z3DateTimeFocusView * dateTimeView
void positionFramesPortrait()
void didTapNetworkFooter()
UIButton * produceBigJumpButton()
CGSize overallNutritionSize
void updateParameterList()
void putMenuItemOnToday:(MenuItem *focusMenuItem)
NSIndexPath * swipedMenuIndexPath
NSMutableArray * nutritionComponents
NSMutableArray< NSString * > * rows
MenuItem * dbFocusMenuItem
NSMutableArray< MenuItem * > * todaysMenuItems
void clearTodaysMenuItems()