Today's Menu  Portugal
journal and plan nutrition
Z7MessagesPanelTableView.m
Go to the documentation of this file.
1 //
2 // Z7MessagesPanelTableView.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 6/8/17.
6 // Copyright © 2017 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
10 #import "Z5DataController.h"
11 
12 @implementation Z7MessagesPanelTableView
13 {
14  id<Z7MessagesTableDelegate> dataDelegate;
15  // EmailMessage *focusEmailMsg;
16  NSDateFormatter *mDateFormatter;
17  NSIndexPath *swipedMenuIndexPath;
18 }
19 
20 - (id) initWithFrame:(CGRect)frame
21  andComponents:(NSArray<NSDictionary *>*)components
22  inContainer:(id<Z7MessagesTableDelegate>) container
23 {
24  NSLog(@"Z7MessagesPanelTableView.init: components: %@", components);
25 
26  self = [super initWithFrame:frame];
27 
28  // [self setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
29  // self.dataSource = self;
30  self.dataSource = container;
31  [self setDelegate:self];
32 
33  dataDelegate = container;
34 
35  mDateFormatter = [[NSDateFormatter alloc] init];
36  [mDateFormatter setTimeStyle:NSDateFormatterNoStyle];
37  [mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
38 
39  [self initRemoveGesture];
40 
41  return self;
42 }
43 
44 //- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
45 //{
46 // NSArray<EmailMessage *> *eMessages = [dataDelegate retrieveEmailMessages];
47 // NSInteger nMesgs = [eMessages count];
48 // return nMesgs;
49 // return 1;
50 //}
51 //
53 //- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
54 //{
55 // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"todays-menu"];
56 // NSLog(@"MessageTableView.cellForRow: cell: %@", cell);
57 // if (cell == nil) {
58 // cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"todays-menu"];
59 //
60 // cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
61 //
62 // CGRect contentRect = [cell.contentView frame];
63 // CGRect fetchPublishButton1Frame = CGRectMake(contentRect.size.width - 86.0f, 5.0, 34.0f, contentRect.size.height - 10);
64 // UIButton *pushMe = [[UIButton alloc] initWithFrame:fetchPublishButton1Frame];
65 // [pushMe setTitle:@"GO" forState:UIControlStateApplication];
66 //
67 // [cell.contentView addSubview:pushMe];
68 // }
69 //
70 // NSArray<EmailMessage *> *eMessages = [dataDelegate retrieveEmailMessages];
71 // NSInteger nMesgs = [eMessages count];
72 //
73 // if (nMesgs > [indexPath row]) {
74 // EmailMessage *mesgForCell = [eMessages objectAtIndex:[indexPath row]];
75 // NSString *caption = [mesgForCell subject];
76 // NSDate *cellDate = [mesgForCell date];
77 // NSString *messageDate = [mDateFormatter stringFromDate:cellDate];
78 // NSLog(@"Z7MessagesTableView.cellForRow: msg date: %@", messageDate);
79 // NSString *subCaption = [NSString stringWithFormat:@"Message date: %@", messageDate];
80 //
84 //
85 // // Convert string to date object
91 //
92 // /*
93 // cell.textLabel.text = caption;
94 // cell.detailTextLabel.text = subCaption;
95 // if (mesgForCell.randomkey) {
96 // [cell setBackgroundColor:[UIColor orangeColor]];
97 // } else {
98 // [cell setBackgroundColor:[UIColor colorWithRed:0.9 green:1.0 blue:0.95 alpha:1.0]];
99 // }
100 // */
101 // [Z5DataController labelizeCell:cell withText:caption inColor:[UIColor lightGrayColor] andDetail:@"more"];
102 // }
103 //
104 // return cell;
105 //
106 //}
107 
126 {
127  NSArray<EmailMessage *> *eMessages = [dataDelegate retrieveEmailMessages];
128  NSInteger nMesgs = [eMessages count];
129 
130  float headersRequirement = [super getViewHeightReqmt];
131  // float extraMargin = 8; // oddly, give correct visual align on zod
132  float extraMargin = 0; // oddly, give correct visual align
133  float ret = headersRequirement + nMesgs * (44.0 + extraMargin);
134  NSLog(@"MessagesPanelTableView.getViewHeightReqmt: headersRequirement: %3.2f, messages: %ld", headersRequirement, (long)nMesgs);
135  NSLog(@"MessagesPanelTableView.getViewHeightReqmt: table bounds hwight: %3.2f", self.bounds.size.height);
136  return ret;
137 }
138 
140 {
141  UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeMenu:)];
142  gesture.direction = UISwipeGestureRecognizerDirectionRight;
143  [self addGestureRecognizer:gesture];
144 }
145 -(void)didSwipeMenu:(UIGestureRecognizer *)gestureRecognizer {
146 
147  if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
148  CGPoint swipeLocation = [gestureRecognizer locationInView:self];
149  swipedMenuIndexPath = [self indexPathForRowAtPoint:swipeLocation];
150  UITableViewCell* swipedCell = [self cellForRowAtIndexPath:swipedMenuIndexPath];
151  // NSLog(@"Z7MessagesPanelTableView.didSwipeMenu: cell row: %ld", (long)[swipedMenuIndexPath row]);
152  [swipedCell setBackgroundColor:[UIColor orangeColor]];
153 
154 // Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
155  NSInteger nRow = [swipedMenuIndexPath row];
156  [dataDelegate messageSwiped:nRow];
157 
158  // [self updateMenu:[localData todaysMenuItems]];
159  [self reloadData];
160  }
161 }
162 
163 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
164  // int row = (int)[indexPath row];
165 
166  /*
167  Z5EmailDataController *eMailCntrlr = [[[Z5DataController sharedInstance] remoteDataController] emailDataController];
168 
169  _focusEmailMsg = [[dataDelegate retrieveEmailMessages] objectAtIndex:[indexPath row]];
170  NSLog(@"MessagesPanelTableView.tableView:didSelectRowAtIndexPath: focusEmail: bodytext: %@ date: %@ name: %@ randomkey: %@ remoteUniqueId: %@ uid: %@", [_focusEmailMsg bodytext], [_focusEmailMsg date], [_focusEmailMsg name], [_focusEmailMsg randomkey], [_focusEmailMsg remoteUniqueIID], [_focusEmailMsg uid]);
171 
172  NSString *caption = [_focusEmailMsg name];
173 
174  NSLog(@"MessagesPanelTableView.tableView:didSelectRowAtIndexPath: row: %d caption: %@", row, caption);
175 
176  NSInteger focusEmailMsgUid = [_focusEmailMsg.uid integerValue];
177 
178  if ([_focusEmailMsg randomkey]) {
179  NSData *mphoto = [_focusEmailMsg photo];
180  UIImage *mPhotoImage = [UIImage imageWithData:_focusEmailMsg.photo];
181  [dataDelegate updateHTML:[_focusEmailMsg bodytext]];
182  } else {
183  [eMailCntrlr retrieveMessageStructure:focusEmailMsgUid fromFolder:@"INBOX"];
184  [eMailCntrlr retrieveTotalMessageHTML:focusEmailMsgUid fromFolder:@"INBOX" toDelegate:dataDelegate];
185  }
186 
187  [self showFoot:YES];
188  [self reloadData];
189  [self setNeedsDisplay];
190  [self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
191  */
192 }
193 /*
194 // Only override drawRect: if you perform custom drawing.
195 // An empty implementation adversely affects performance during animation.
196 - (void)drawRect:(CGRect)rect {
197  // Drawing code
198 }
199 */
200 
201 @end
id initWithFrame:(CGRect frame)
NSDateFormatter * mDateFormatter
NSIndexPath * swipedMenuIndexPath