Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Properties | List of all members
Z6MenuPanoramaView Class Reference

#import <Z6MenuPanoramaView.h>

Inheritance diagram for Z6MenuPanoramaView:
Inheritance graph
[legend]
Collaboration diagram for Z6MenuPanoramaView:
Collaboration graph
[legend]

Instance Methods

(instancetype) - initWithFrame:andDelegate:
 
(void) - reload
 
(float) - heightRequirement
 
(void) - initialize [implementation]
 
(void) - appear: [implementation]
 
(void) - setCurrentDate [implementation]
 
(float) - collectionViewHeight [implementation]
 
(UIEdgeInsets) - collectionView:layout:insetForSectionAtIndex: [implementation]
 
(NSInteger) - numberOfSectionsInCollectionView: [implementation]
 
(NSInteger) - collectionView:numberOfItemsInSection: [implementation]
 
(UICollectionViewCell *) - collectionView:cellForItemAtIndexPath: [implementation]
 
(void) - collectionView:didSelectItemAtIndexPath: [implementation]
 
(void) - centerGalleryItem: [implementation]
 
(CGSize) - collectionView:layout:sizeForItemAtIndexPath: [implementation]
 
(NSMutableArray *) - redetermineMenuItems [implementation]
 
(NSArray *) - menuParameterArray: [implementation]
 
(void) - clickClearDay [implementation]
 

Properties

NSMutableArray< MenuItem * > * menuItems
 
MenuItemfocusMenuItem
 
NSDateFormatter * mDateFormatter [implementation]
 
UIButton * dateButton [implementation]
 

Detailed Description

Definition at line 14 of file Z6MenuPanoramaView.h.

Method Documentation

◆ appear:()

- (void) appear: (CGRect)  bound
implementation

Definition at line 111 of file Z6MenuPanoramaView.m.

111  :(CGRect)bound
112 {
113  NSNumber *galleryChoice = [NSNumber numberWithInt:1];
114  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
115  NSArray *tmp = [localData retrieveAllMenuItems:galleryChoice];
116  // NSLog(@"Z6MenuPanoramaView.appear: count of all menu items in d/b: %ld", (unsigned long)[tmp count]);
117  [self setMenuItems:[[NSMutableArray alloc] initWithArray:tmp]];
118  [self reload];
119 
120  CGRect collectionViewFrame = CGRectMake(10, 36, self.bounds.size.width-20, [self collectionViewHeight]);
121  [collectionView setFrame:collectionViewFrame];
122  if (0 <= selectedRow) {
123  [self centerGalleryItem:selectedRow];
124  }
125 }
NSInteger selectedRow
NSArray< MenuItem * > * retrieveAllMenuItems:(NSNumber *galleryNo)
instancetype sharedInstance()
Singleton interface to both core and remote data sources.

◆ centerGalleryItem:()

- (void) centerGalleryItem: (NSUInteger)  indexRow
implementation

Definition at line 267 of file Z6MenuPanoramaView.m.

267  :(NSUInteger)indexRow
268 {
269  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexRow inSection:0];
270  [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
271 }

◆ clickClearDay()

- (void) clickClearDay
implementation

Definition at line 371 of file Z6MenuPanoramaView.m.

372 {
373  NSLog(@"Z6MenuPanoramaView.clickClearDay");
374  self.focusMenuItem = nil;
375  selectedRow = -1;
376 
377  [menuPanoramaDelegate clickClearDay];
378  [self reload];
379 }
NSInteger selectedRow

◆ collectionView:cellForItemAtIndexPath:()

- (UICollectionViewCell *) collectionView: (UICollectionView *)  collectionView
cellForItemAtIndexPath: (NSIndexPath *)  indexPath 
implementation

Definition at line 199 of file Z6MenuPanoramaView.m.

199  :(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
200 
201  int imageHeight = 120; //
202  int selectedImageHeight = 160;
203  int outputImageHeight = 0;
204 
205  // UICollectionViewFlowLayout *viewLayout = collectionView.collectionViewLayout;
206  // UICollectionView *colView = collectionView;
207 
208 
210  if (selectedRow == indexPath.row) {
211  cell = (Y4NutritionCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:selectedCellIdentifier forIndexPath:indexPath];
212  outputImageHeight = selectedImageHeight;
213  } else {
214  cell = (Y4NutritionCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
215  outputImageHeight = imageHeight;
216  }
217  // NSLog(@"NutritionCollectController.cellForItemAtIndexPath: tag: %ld", [[cell textLabel] tag]);
218 
219  MenuItem *cellItem = [[self menuItems] objectAtIndex:indexPath.row];
220  UIImage *photoImage = [UIImage imageWithData:cellItem.photo];
221  NSString *itemName = [cellItem name];
222  if (!itemName) {
223  itemName = @"NameLess";
224  }
225 
226  CGSize photoSize = [photoImage size];
227  float resizeRatio = photoSize.height / (float)outputImageHeight;
228  UIImage *keptImage = [UIImage imageWithCGImage:[photoImage CGImage]
229  scale:photoImage.scale * resizeRatio
230  orientation:(photoImage.imageOrientation) ];
231 
232  // NSString *rkey = [Z5DataController produceRandomkey];
233  [cell.imageView setImage:keptImage];
234  [Z5DataController labelize:cell.textLabel withText:itemName];
235 
236  return cell;
237 }
NSInteger selectedRow
static NSString * cellIdentifier
Singleton interface to both core and remote data sources.
static NSString * selectedCellIdentifier
void labelize:withText:(UILabel *targLabel, [withText] NSString *txt)
UICollectionView * collectionView

◆ collectionView:didSelectItemAtIndexPath:()

- (void) collectionView: (UICollectionView *)  collectionView
didSelectItemAtIndexPath: (NSIndexPath *)  indexPath 
implementation

This is where the picture gallery is clicked. Evaluate authority is LocalData for each component, call 'ask Operator...' if insufficient. This is also the basis for turning usda json into an NSArray<NSDictionary *> *array.

Definition at line 246 of file Z6MenuPanoramaView.m.

246  :(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
247 {
248  if (selectedRow == indexPath.row) {
249  [self clickClearDay];
250  } else {
251  selectedRow = indexPath.row;
252 
253  NSLog(@"Z6MenuPanoramaView.didSelectItem: selectedRow: %ld", (long)selectedRow);
254 
255  NSUInteger tCount = [[self menuItems] count];
256  if (tCount > [indexPath row]) {
257 
258  MenuItem *selectedItem = [[self menuItems] objectAtIndex:[indexPath row]];
259  [self setFocusMenuItem:selectedItem];
260  [menuPanoramaDelegate clickedMenuItem:selectedItem atRow:selectedRow];
261  }
262  [self reload];
263  }
264  [self setNeedsDisplay];
265  [self centerGalleryItem:[indexPath row]];
266 }
NSInteger selectedRow
UICollectionView * collectionView

◆ collectionView:layout:insetForSectionAtIndex:()

- (UIEdgeInsets) collectionView: (UICollectionView *)  collectionView
layout: (UICollectionViewLayout*)  collectionViewLayout
insetForSectionAtIndex: (NSInteger)  section 
implementation

Definition at line 174 of file Z6MenuPanoramaView.m.

174  :(UICollectionView *)collectionView
175  layout:(UICollectionViewLayout*)collectionViewLayout
176  insetForSectionAtIndex:(NSInteger)section {
177 
178  // NSLog(@"Z6MenuPanoramaView.insetForSectionAtIndex: %ld", (long)section);
179 
180  UIEdgeInsets ret = UIEdgeInsetsMake(0.0, 10.0, 0.0, 10.0);
181  return ret;
182 }
UICollectionView * collectionView

◆ collectionView:layout:sizeForItemAtIndexPath:()

- (CGSize) collectionView: (UICollectionView *)  collectionView
layout: (UICollectionViewLayout *)  collectionViewLayout
sizeForItemAtIndexPath: (NSIndexPath *)  indexPath 
implementation

This is the master size of displayed menutiems.

Definition at line 275 of file Z6MenuPanoramaView.m.

275  :(UICollectionView *)collectionView
276  layout:(UICollectionViewLayout *)collectionViewLayout
277  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
278 {
279  CGSize ret;
280 
281  if (indexPath.row == selectedRow) {
282  ret = selectCellSize;
283  } else {
284  ret = defaultCellSize;
285  }
286  return ret;
287 }
NSInteger selectedRow
CGSize selectCellSize
CGSize defaultCellSize
UICollectionView * collectionView

◆ collectionView:numberOfItemsInSection:()

- (NSInteger) collectionView: (UICollectionView *)  collectionView
numberOfItemsInSection: (NSInteger)  section 
implementation

Definition at line 192 of file Z6MenuPanoramaView.m.

192  :(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
193 
194  NSInteger ret = [[self menuItems] count];
195  // NSLog(@"Z6MenuPanoramaView.numberOfItemsInSection: menuItem count: %ld", ret);
196 
197  return ret;
198 }
UICollectionView * collectionView

◆ collectionViewHeight()

- (float) collectionViewHeight
implementation

Definition at line 140 of file Z6MenuPanoramaView.m.

141 {
142  float portalHeight = selectCellSize.height
143  + [collectionView layoutMargins].top
144  + [collectionView layoutMargins].bottom
145  + [collectionView contentInset].top
146  + [collectionView contentInset].bottom + 8;
147 
148 
149  NSLog(@"Z6MenuPanoramaView.collectionViewHeight: portalHeight: %3.2f", portalHeight);
150  return portalHeight;
151 }
CGSize selectCellSize
UICollectionView * collectionView

◆ heightRequirement()

- (float) heightRequirement

Definition at line 154 of file Z6MenuPanoramaView.m.

155 {
156  // dateButton does not show up in Menu-Record
157  float dateNoticeVert = self.dateButton.bounds.size.height;
158 
159  float portalHeight = [self collectionViewHeight] + dateNoticeVert + 6;
160 
161  // portalHeight += 100.0; // this stretches gray portion (headerView.collectionView) inside brown area (headerView)
162 
163  if (selectedRow > 0) {
164  portalHeight += 16;
165  }
166 
167  // NSLog(@"MenuPanorama.heightRequirement: dateNoticeVert: %3.2f portalHeight: %3.2f",
168  // dateNoticeVert, portalHeight);
169 
170  return portalHeight;
171 }
NSInteger selectedRow

◆ initialize()

- (void) initialize
implementation

Definition at line 43 of file Z6MenuPanoramaView.m.

44 {
45  flowLayout = [[UICollectionViewFlowLayout alloc] init];
46  [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
47 
48  _mDateFormatter = [[NSDateFormatter alloc] init];
49  [_mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
50  [_mDateFormatter setTimeStyle:NSDateFormatterShortStyle];
51 
52  // start definition of collection view layout - class var, used many places
53  float defaultCellwidth = 174;
54  float defaultCellheight = 218;
55  defaultCellSize = CGSizeMake(defaultCellwidth, defaultCellheight);
56  float selectCellWidth = 256;
57  float selectCellHeight = 280;
58  selectCellSize = CGSizeMake(selectCellWidth, selectCellHeight);
59  // end, for now - start definition of collection view layout
60 
61  // float initialCollectViewHgt = selectCellHeight + 18;
62  float initialCollectViewHgt = selectCellHeight + 6;
63  CGRect collectionViewFrame = CGRectMake(10, 36, self.bounds.size.width-12, initialCollectViewHgt);
64  collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
65  [collectionView setDelegate:self];
66  [collectionView setDataSource:self];
67  // [collectionView setBackgroundColor:[UIColor lightGrayColor]];
68  [collectionView setBackgroundColor:[[Z5DataController alloc] wheatColor]];
69  [self addSubview:collectionView];
70 
71  // add a button annotated with today's date, And added it to the view
72  CGRect dateFrame = CGRectMake(60.0, 4.0, 240.0, 28.0);
73  self.dateButton = [[UIButton alloc] initWithFrame:dateFrame];
74  [self.dateButton addTarget:self action:@selector(clickClearDay) forControlEvents:UIControlEventTouchUpInside];
75  [self.dateButton setOpaque:YES];
76  [self.dateButton setBackgroundColor:[UIColor cyanColor]];
77  [self addSubview:self.dateButton];
78  // end - add a button annotated with today's date, And added it to the view
79 
80  // setup how cells are built
81  [collectionView registerClass:[Y4NutritionCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
82  [collectionView registerClass:[Y4NutritionCollectSelectViewCell class] forCellWithReuseIdentifier:selectedCellIdentifier];
83  collectionView.delegate = self;
84  // end - setup how cells are built
85 
86  // initialize class var with all menu items for (for display by the gallery?)
87  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
88  NSNumber *galleryChoice = [NSNumber numberWithInt:1];
89  NSArray *tmp = [localData retrieveAllMenuItems:galleryChoice];
90  NSLog(@"Z6MenuPanoramaView.initialize: count of all menu items in d/b: %ld", (unsigned long)[tmp count]);
91  [self setMenuItems:[[NSMutableArray alloc] initWithArray:tmp]];
92  // end - initialize class var with all menu items for (for display by the gallery?)
93 
94  if (0 < [_menuItems count]) {
95  NSUInteger selectindex;
96  if ([menuPanoramaDelegate getSelectedGalleryRow: (NSUInteger *) &selectindex]) {
97  MenuItem *selectedItem = [_menuItems objectAtIndex:selectindex];
98  [self setFocusMenuItem:selectedItem];
99  NSLog(@"Z6MenuPanoramaView.initialize: selectedRow: %ld", (long)selectedRow);
100  [self centerGalleryItem:selectedRow];
101  } else {
102  selectedRow = -1;
103  }
104  }
105 
106  [self setCurrentDate];
107 
108  [self setBackgroundColor:backgroundShade];
109 }
NSInteger selectedRow
NSArray< MenuItem * > * retrieveAllMenuItems:(NSNumber *galleryNo)
CGSize selectCellSize
instancetype sharedInstance()
UICollectionViewFlowLayout * flowLayout
float initialCollectViewHgt
id< Z6MenuPanoramaDelegate > menuPanoramaDelegate
Singleton interface to both core and remote data sources.
CGSize defaultCellSize
UICollectionView * collectionView

◆ initWithFrame:andDelegate:()

- (instancetype) initWithFrame: (CGRect)  frame
andDelegate: (id<Z6MenuPanoramaDelegate>)  delegate 

Definition at line 32 of file Z6MenuPanoramaView.m.

32  :(CGRect)frame andDelegate:(id<Z6MenuPanoramaDelegate>)dele
33 {
34  self = [super initWithFrame:frame];
35  menuPanoramaDelegate = dele;
36  backgroundShade = [UIColor colorWithRed:226.0/256 green:201.0/256 blue:114.0/256 alpha:1.0];
37  // backgroundShade = [[Z5DataController alloc] wheatColor];
38 
39  [self initialize];
40  return self;
41 }
UIColor * backgroundShade
id< Z6MenuPanoramaDelegate > menuPanoramaDelegate

◆ menuParameterArray:()

- (NSArray *) menuParameterArray: (NSString *)  jsonString
implementation

a this method provides the array when a gallery picture is selected.

Definition at line 340 of file Z6MenuPanoramaView.m.

340  : (NSString *)jsonString
341 {
342  NSLog(@"Z6MenuPanoramaView.menuParameterArray: jsonString: %@", jsonString);
343  NSData *jsonReturnData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
344  NSError *err;
345  if (jsonReturnData) {
346  NSObject *jsonSerialized = [NSJSONSerialization JSONObjectWithData:jsonReturnData options:NSJSONReadingAllowFragments error:&err];
347  if (jsonSerialized) {
348  NSString *jsonSerializedClass = NSStringFromClass([jsonSerialized class]);
349  NSLog(@"Z6MenuPanoramaView.menuParameterArray: valid data, top class: %@", jsonSerializedClass);
350  if (([jsonSerializedClass isEqualToString:@"__NSCFDictionary"])
351  || ([jsonSerializedClass isEqualToString:@"__NSSingleEntryDictionaryI"])) {
352  NSDictionary *jsonSerializedDict = (NSDictionary *)jsonSerialized;
353  NSObject *uNums = [jsonSerializedDict objectForKey:@"usdaNumbers"];
354  NSString *uNumsClass = NSStringFromClass([uNums class]);
355  NSLog(@"Z6MenuPanoramaView.menuParameterArray: uNumsClass: %@", uNumsClass);
356  NSArray *jsonSerializedArray = (NSArray *)uNums;
357  return jsonSerializedArray;
358  } else {
359  return nil;
360  }
361  } else {
362  return nil;
363  }
364  } else {
365  return nil;
366  }
367 }

◆ numberOfSectionsInCollectionView:()

- (NSInteger) numberOfSectionsInCollectionView: (UICollectionView *)  collectionView
implementation

Definition at line 186 of file Z6MenuPanoramaView.m.

186  :(UICollectionView *)collectionView {
187 
188  NSInteger ret = 1;
189 
190  return ret;
191 }
UICollectionView * collectionView

◆ redetermineMenuItems()

- (NSMutableArray *) redetermineMenuItems
implementation

this method compares the menu items in ’menuitems’, displayed on the gallery, and the menu items in the database. If a menu item is found in the database that is not in the gallery, it adds it. This will happen at the creation of new items in other screens, being added to the database, and then the gallery page showing up again.

Definition at line 297 of file Z6MenuPanoramaView.m.

298 {
299  Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
300 
301  NSNumber *galleryChoice = [NSNumber numberWithInt:1];
302  NSArray *menuItemsNow = [localData retrieveAllMenuItems:galleryChoice];
303  Boolean dbMenuItemFoundInGalllery = NO;
304  for (MenuItem *dbMenuItem in menuItemsNow) {
305  NSString *miNowRandomkey = dbMenuItem.randomkey;
306  for (MenuItem *galleryMenuItem in [self menuItems]) {
307  // NSLog(@"NutritionCollectionView.determineMenuItems: scan-in key: %@ alreadykey: %@", miNowRandomkey, galleryMenuItem.randomkey);
308 
309  if ([miNowRandomkey isEqualToString:galleryMenuItem.randomkey]) {
310  /*
311  * this block is encountered when a database menu item is found in the gallery menu items.
312  * a flag will be set indicating item is not to be added to gallery display,
313  *
314  */
315  dbMenuItemFoundInGalllery = YES;
316  break;
317  }
318  }
319  if (!dbMenuItemFoundInGalllery) {
320  /*
321  * this block is encountered when a database menu item is not found in the gallery menu items.
322  * Here it is added at the beginning of the gallery.
323  */
324  dbMenuItem.galleryPositionNo = [NSNumber numberWithLong:[localData getPrevGalleryPositionIdx]];
325  [[self menuItems] addObject:dbMenuItem];
326  }
327  }
328 
329  for (MenuItem *mi in [self menuItems]) {
330  NSLog(@"NutritionCollectionView.redetermineMenuItems: positionInGallery: %@", [mi galleryPositionNo]);
331  }
332  return [self menuItems];
333 }
NSArray< MenuItem * > * retrieveAllMenuItems:(NSNumber *galleryNo)
instancetype sharedInstance()
NSMutableArray< MenuItem * > * menuItems
Singleton interface to both core and remote data sources.

◆ reload()

- (void) reload

Definition at line 127 of file Z6MenuPanoramaView.m.

128 {
129  NSLog(@"MenuPanorama.reload: selected row: %ld", (long)selectedRow);
130  [collectionView reloadData];
131  [collectionView setNeedsDisplay];
132  [self setCurrentDate];
133 }
NSInteger selectedRow

◆ setCurrentDate()

- (void) setCurrentDate
implementation

Definition at line 135 of file Z6MenuPanoramaView.m.

136 {
137  NSString *todayDate = [_mDateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:0]];
138  [Z5DataController labelizeButton:self.dateButton withText:todayDate];
139 }
Singleton interface to both core and remote data sources.
void labelizeButton:withText:(UIButton *targButton, [withText] NSString *txt)

Property Documentation

◆ dateButton

- (UIButton*) dateButton
readwritenonatomicstrongimplementation

Definition at line 16 of file Z6MenuPanoramaView.m.

◆ focusMenuItem

- (MenuItem*) focusMenuItem
readwritenonatomicstrong

Definition at line 20 of file Z6MenuPanoramaView.h.

◆ mDateFormatter

- (NSDateFormatter*) mDateFormatter
readwritenonatomicstrongimplementation

Definition at line 15 of file Z6MenuPanoramaView.m.

◆ menuItems

- (NSMutableArray<MenuItem *>*) menuItems
readwritenonatomicstrong

Definition at line 19 of file Z6MenuPanoramaView.h.


The documentation for this class was generated from the following files: