32 - (instancetype) initWithFrame:(CGRect)frame andDelegate:(
id<Z6MenuPanoramaDelegate>)dele
34 self = [
super initWithFrame:frame];
36 backgroundShade = [UIColor colorWithRed:226.0/256 green:201.0/256 blue:114.0/256 alpha:1.0];
45 flowLayout = [[UICollectionViewFlowLayout alloc] init];
46 [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
48 _mDateFormatter = [[NSDateFormatter alloc] init];
49 [_mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
50 [_mDateFormatter setTimeStyle:NSDateFormatterShortStyle];
53 float defaultCellwidth = 174;
54 float defaultCellheight = 218;
56 float selectCellWidth = 256;
57 float selectCellHeight = 280;
64 collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:flowLayout];
65 [collectionView setDelegate:self];
66 [collectionView setDataSource:self];
69 [
self addSubview:collectionView];
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];
88 NSNumber *galleryChoice = [NSNumber numberWithInt:1];
90 NSLog(
@"Z6MenuPanoramaView.initialize: count of all menu items in d/b: %ld", (
unsigned long)[tmp count]);
91 [
self setMenuItems:[[NSMutableArray alloc] initWithArray:tmp]];
94 if (0 < [_menuItems count]) {
95 NSUInteger selectindex;
97 MenuItem *selectedItem = [_menuItems objectAtIndex:selectindex];
98 [
self setFocusMenuItem:selectedItem];
99 NSLog(
@"Z6MenuPanoramaView.initialize: selectedRow: %ld", (
long)
selectedRow);
108 [
self setBackgroundColor:backgroundShade];
111 - (void) appear:(CGRect)bound
113 NSNumber *galleryChoice = [NSNumber numberWithInt:1];
117 [
self setMenuItems:[[NSMutableArray alloc] initWithArray:tmp]];
120 CGRect collectionViewFrame = CGRectMake(10, 36,
self.bounds.size.width-20, [
self collectionViewHeight]);
121 [collectionView setFrame:collectionViewFrame];
129 NSLog(
@"MenuPanorama.reload: selected row: %ld", (
long)
selectedRow);
130 [collectionView reloadData];
131 [collectionView setNeedsDisplay];
137 NSString *todayDate = [_mDateFormatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:0]];
143 + [collectionView layoutMargins].top
144 + [collectionView layoutMargins].bottom
145 + [collectionView contentInset].top
146 + [collectionView contentInset].bottom + 8;
149 NSLog(
@"Z6MenuPanoramaView.collectionViewHeight: portalHeight: %3.2f", portalHeight);
153 #pragma mark - <Z6ContainedView> 157 float dateNoticeVert =
self.dateButton.bounds.size.height;
173 #pragma mark - <UICollectionViewDelegateFlowLayout> 175 layout:(UICollectionViewLayout*)collectionViewLayout
176 insetForSectionAtIndex:(NSInteger)section {
180 UIEdgeInsets ret = UIEdgeInsetsMake(0.0, 10.0, 0.0, 10.0);
184 #pragma mark - <UICollectionViewDataSource> 186 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
192 -(NSInteger)
collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
194 NSInteger ret = [[
self menuItems] count];
199 - (UICollectionViewCell *)
collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
201 int imageHeight = 120;
202 int selectedImageHeight = 160;
203 int outputImageHeight = 0;
212 outputImageHeight = selectedImageHeight;
215 outputImageHeight = imageHeight;
220 UIImage *photoImage = [UIImage imageWithData:cellItem.photo];
221 NSString *itemName = [cellItem
name];
223 itemName =
@"NameLess";
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) ];
233 [cell.imageView setImage:keptImage];
240 #pragma mark - <UICollectionViewDelegate> 246 - (void)
collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
253 NSLog(
@"Z6MenuPanoramaView.didSelectItem: selectedRow: %ld", (
long)
selectedRow);
255 NSUInteger tCount = [[
self menuItems] count];
256 if (tCount > [indexPath row]) {
259 [
self setFocusMenuItem:selectedItem];
260 [menuPanoramaDelegate clickedMenuItem:selectedItem atRow:selectedRow];
264 [
self setNeedsDisplay];
267 - (void) centerGalleryItem:(NSUInteger)indexRow
269 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexRow inSection:0];
270 [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
276 layout:(UICollectionViewLayout *)collectionViewLayout
277 sizeForItemAtIndexPath:(NSIndexPath *)indexPath
301 NSNumber *galleryChoice = [NSNumber numberWithInt:1];
303 Boolean dbMenuItemFoundInGalllery = NO;
304 for (
MenuItem *dbMenuItem in menuItemsNow) {
305 NSString *miNowRandomkey = dbMenuItem.randomkey;
309 if ([miNowRandomkey isEqualToString:galleryMenuItem.randomkey]) {
315 dbMenuItemFoundInGalllery = YES;
319 if (!dbMenuItemFoundInGalllery) {
330 NSLog(
@"NutritionCollectionView.redetermineMenuItems: positionInGallery: %@", [mi galleryPositionNo]);
340 -(NSArray *)menuParameterArray: (NSString *)jsonString
342 NSLog(
@"Z6MenuPanoramaView.menuParameterArray: jsonString: %@", jsonString);
343 NSData *jsonReturnData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
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;
369 #pragma mark button action 373 NSLog(
@"Z6MenuPanoramaView.clickClearDay");
374 self.focusMenuItem = nil;
377 [menuPanoramaDelegate clickClearDay];
NSArray< MenuItem * > * retrieveAllMenuItems:(NSNumber *galleryNo)
instancetype sharedInstance()
NSInteger getPrevGalleryPositionIdx()
NSDateFormatter * mDateFormatter
float initialCollectViewHgt
Singleton interface to both core and remote data sources.
void labelizeButton:withText:(UIButton *targButton, [withText] NSString *txt)
void labelize:withText:(UILabel *targLabel, [withText] NSString *txt)