62 NSMutableArray<NSString *> *
rows;
85 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
87 self = [
super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
90 self.title =
@"Messages";
91 self.tabBarItem.image = [UIImage imageNamed:@"mail19.png"];
93 rows = [[NSMutableArray alloc] init];
94 _emailMessages = [[NSMutableArray alloc] init];
96 [dspNearDateFormatter setDateStyle:NSDateFormatterMediumStyle];
97 [dspNearDateFormatter setTimeStyle:NSDateFormatterShortStyle];
100 [mDateFormatter setTimeStyle:NSDateFormatterNoStyle];
101 [mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
108 - (void)viewDidLoad {
111 [[
self view] setBackgroundColor:[UIColor colorWithHue:0.26
115 CGRect totalFrame =
self.view.frame;
117 UIImage *backgrdImage = [UIImage imageNamed:@"blueHydrangea.png"];
118 UIImageView *backgrd = [[UIImageView alloc] initWithImage:backgrdImage];
120 float topSpace = 0.0;
121 CGRect backImageFrame = CGRectMake(0.0, topSpace, totalFrame.size.width, totalFrame.size.height - topSpace);
122 [backgrd setFrame:backImageFrame];
123 [
self.view addSubview:backgrd];
127 NSInteger count = [dbEmail count];
128 NSLog(
@"Y3GmailViewController.viewDidLoad: dbEmail count: %ld", (
long)count);
130 CGRect nutritionMsgsTableFrame = CGRectMake(totalFrame.size.width * 0.54,
131 totalFrame.size.height * 0.83,
132 totalFrame.size.width * 0.42,
133 totalFrame.size.height * 0.07);
135 _nutritionMsgsTable = [[
Z7MessagesPanelTableView alloc] initWithFrame:nutritionMsgsTableFrame andComponents:nil inContainer:self];
142 [_nutritionMsgsTable setDataSource:self];
143 [_nutritionMsgsTable setDelegate:self];
145 [_nutritionMsgsTable registerClass:[
Y3GmailViewHeader class] forHeaderFooterViewReuseIdentifier:HeaderIdentifier];
153 CGRect gmailFooterFrame = CGRectMake(0.0, 0.0, totalFrame.size.width, [
gmailViewFooter heightRequirement]);
154 [gmailViewFooter setFrame:gmailFooterFrame];
155 [gmailViewFooter setBackgroundColor:[UIColor colorWithHue:0.3 saturation:1.0 brightness:1.0 alpha:1.0]];
156 [_nutritionMsgsTable setViewForTail:gmailViewFooter];
158 [_emailMessages setArray:dbEmail];
160 [
self.view addSubview:_nutritionMsgsTable];
167 - (void) addMailScanButton
169 CGRect totalFrame =
self.view.frame;
170 CGRect manualMailButtonFrame = CGRectMake(totalFrame.size.width * 0.04,
171 totalFrame.size.height * 0.83,
172 totalFrame.size.width * 0.42,
173 totalFrame.size.height * 0.07);
175 [manualMailButton setTitle:@"scan msgs" forState:UIControlStateNormal];
176 [manualMailButton addTarget:self action:@selector(execMailSession) forControlEvents:UIControlEventTouchUpInside];
177 [
self.view addSubview:manualMailButton];
179 -(void) viewDidAppear:(BOOL)animated
183 [gmailViewHeader appear:nutritionMessagesFrame];
184 [gmailViewFooter appear:nutritionMessagesFrame];
186 NSInteger nMsgs = [_emailMessages count];
187 NSInteger nRows = [_nutritionMsgsTable numberOfRowsInSection:0];
188 if ((0 < nMsgs) && (nRows > 1)){
189 CGPoint newContentOffset = CGPointMake(0, [_nutritionMsgsTable contentSize].height - _nutritionMsgsTable.bounds.size.height);
190 [_nutritionMsgsTable setContentOffset:newContentOffset animated:YES];
194 #pragma mark - Z5GoogleLoginListener 197 NSLog(
@"GmailViewController.signedIn: %@", user.
profile.
name);
200 [gmailViewFooter signedIn:user];
229 - (void) placeLogoutButton
232 UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout"
233 style:UIBarButtonItemStylePlain
235 action:@selector(logOutGoogle)];
236 self.navigationItem.rightBarButtonItem = anotherButton;
237 self.navigationItem.rightBarButtonItem.enabled = YES;
243 - (void) reframeTable
245 CGRect totalFrame =
self.view.frame;
246 float messagesTableHeight = 0.0;
247 CGRect topNaviFrame = [[[
self navigationController] navigationBar] frame];
248 float availableWindowTop = topNaviFrame.origin.y + topNaviFrame.size.height;
250 messagesTableHeight = [_nutritionMsgsTable getViewHeightReqmt];
251 float maxHgt = totalFrame.size.height * 0.84;
252 NSLog(
@"Y3GmailViewController.reframeTable: msgsTbHt: %3.2f mxHt: %3.2f", messagesTableHeight, maxHgt);
253 if (maxHgt < messagesTableHeight) {
254 messagesTableHeight = maxHgt;
257 availableWindowTop + totalFrame.size.height * 0.02,
258 totalFrame.size.width * 0.92,
259 messagesTableHeight);
260 [_nutritionMsgsTable setFrame:nutritionMessagesFrame];
262 [
self.view setNeedsDisplay];
268 #pragma mark - button action 272 - (void) execMailSession
275 [manualMailButton setBackgroundColor:[UIColor cyanColor]];
284 [
self performSelector:@selector(fetchMailAfterDelay) withObject:nil afterDelay:3.2];
287 - (void) fetchMailAfterDelay
292 NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
293 [_emailMessages setArray:[dbEmail sortedArrayUsingDescriptors:@[sortDescriptor]]];
297 -(void) fireAccountEntry
299 NSLog(
@"NutritionRoot.fireAccountEntry -- NO-OP");
308 #pragma mark - Y3GmailViewProtocol 311 NSLog(
@"Y3GmailViewController.updateUI");
312 [_nutritionMsgsTable reloadData];
314 [manualMailButton removeFromSuperview];
317 if ([[loginControl signedIn] boolValue]) {
322 - (void) updateHTML:(NSString *)body
324 NSLog(
@"GmailView.updateHTML: %@", body);
325 messageHtml = [[NSString alloc] initWithString:body];
328 [manualMailButton setHidden:NO];
329 [addItemButton setHidden:NO];
337 - (void) photoAvailable: (NSDictionary *) partDetail
339 NSString *filename = [partDetail objectForKey:@"part-filename"];
340 NSString *contentID = [partDetail objectForKey:@"part-contentID"];
342 NSLog(
@"GmailViewControl.photoAvailable: %@ content-ID: %@", filename, contentID);
344 NSString *updatePhrase;
345 NSCharacterSet *carats = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
346 NSArray<NSString *> *htmlBits = [messageHtml componentsSeparatedByCharactersInSet:carats];
347 for (NSString *bits in htmlBits) {
348 NSLog(
@" photoAvail: bit: %@", bits);
349 if (filename && [bits containsString:filename]) {
350 updatePhrase = [[NSString alloc] initWithString:bits];
351 }
else if (contentID && [bits containsString:contentID]) {
352 updatePhrase = [[NSString alloc] initWithString:bits];
356 NSString *imageHtml = [[NSString alloc] initWithFormat:@"<center><img src=\"%@\" width=\"%5.3f\"></center>", filename, 0.8 * webViewEmailWidth];
357 NSString *revisedHtml = [messageHtml stringByReplacingOccurrencesOfString:updatePhrase withString:imageHtml];
359 NSLog(
@"GmailViewControl.photoAvailable: revisedHtml: %@", revisedHtml);
366 #pragma mark - Z7MessagesTableDelegate 367 - (void) messageSwiped:(NSInteger) nRow
369 NSLog(
@"Y3GmailViewController.messageSwiped: removing message: %ld", (
long)nRow);
371 EmailMessage *eMsg = [
self.emailMessages objectAtIndex:nRow];
376 [mailUtility initializeBlockedList];
379 [
self.emailMessages removeObjectAtIndex:nRow];
384 return _emailMessages;
387 #pragma mark - UITextFieldDelegate 389 - (void)textFieldDidEndEditing:(UITextField *)textField {
390 NSLog(
@"GmailViewControl.textFieldDidEndEditing");
391 [textField resignFirstResponder];
393 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
394 [textField resignFirstResponder];
401 #pragma mark - WKUIDelegate 404 didFinishNavigation:(WKNavigation *)navigation
406 NSLog(
@"GmailViewControl.didFinishNavigation: width: %3.2f",
webView.scrollView.contentSize.width);
410 #pragma mark - GmailHeader delegate 419 #pragma mark - GmailFooter delegate 421 - (void) didTapScanServer
423 NSLog(
@"GmailViewControl.didTapScanServer");
438 [
self performSelector:@selector(reframeTable) withObject:nil afterDelay:3.0];
441 - (void) didTapAddItem
443 NSLog(
@"GmailViewControl.didTapAddItem");
447 #pragma mark - Table view data source 449 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
459 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
465 - (NSInteger) assessMessagesToDisplay
467 NSInteger ret = [_emailMessages count];
469 NSLog(
@"Y3GmailViewController.assessMessagesToDisplay: ret: %ld", (
long)ret);
472 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
474 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"todays-menu"];
477 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"todays-menu"];
479 cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
482 CGRect contentRect = [cell.contentView frame];
483 CGRect fetchPublishButton1Frame = CGRectMake(contentRect.size.width - 86.0f, 5.0, 34.0f, contentRect.size.height - 10);
484 UIButton *pushMe = [[UIButton alloc] initWithFrame:fetchPublishButton1Frame];
485 [pushMe setTitle:@"GO" forState:UIControlStateApplication];
486 [pushMe setBackgroundColor:[UIColor greenColor]];
498 NSInteger nMesgs = [_emailMessages count];
500 if (nMesgs > [indexPath row]) {
501 EmailMessage *mailMsg = [_emailMessages objectAtIndex:[indexPath row]];
502 NSString *caption = [mailMsg
subject];
503 NSString *shortCaption = [caption stringByReplacingOccurrencesOfString:@"(Nutrition Information Journal)" withString:@"<>"];
504 NSString *shortCaption2 = [shortCaption stringByReplacingOccurrencesOfString:@"(nutrition information journal)" withString:@"<>"];
506 cell.textLabel.text = shortCaption2;
507 UIColor *labelizeColor;
509 labelizeColor = [UIColor hazySkyBlueColor];
512 labelizeColor = [UIColor yellowColor];
515 NSDate *cellDate = [mailMsg
date];
516 NSString *messageDate = [mDateFormatter stringFromDate:cellDate];
529 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
534 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
536 Y3GmailViewHeader *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:HeaderIdentifier];
537 CGRect sectionHeaderViewFrame = CGRectMake(0.0, 0.0, 300.0, [
Y3GmailViewHeader heightRequirement]);
538 [sectionHeaderView setMsgHeaderDelegate:self];
539 [sectionHeaderView
appear:sectionHeaderViewFrame];
540 return sectionHeaderView;
544 #pragma mark - Table view delegate 550 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
553 NSLog(
@"%@",theHeaderView);
556 EmailMessage *focusEmailMsg = [_emailMessages objectAtIndex:[indexPath row]];
559 NSLog(
@"GmailViewController.didSelectRow: focusEmailUID: %@", messageUID);
560 NSLog(
@"GmailViewController.didSelectRow: focusEmailMsg: %@", focusEmailMsg);
564 [vc2 setFocusEmailMsg:focusEmailMsg];
567 [[
self navigationController] pushViewController:vc2 animated:YES];
571 - (void)didReceiveMemoryWarning {
572 [
super didReceiveMemoryWarning];
UIButton * manualMailButton
void addLoginListener:(id< Z5GoogleLoginListener > ear)
NSString * remoteUniqueIID
void viewDidAppear:(BOOL animated)
< Y3GmailViewProtocol, Y3GmailViewProtocol, Y3GmailFooterDelegate, Z5GoogleLoginListener, Y3GmailHeaderProtocol, Z7MessagesTableDelegate, GIDSignInUIDelegate, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, WKNavigationDelegate, WKUIDelegate > Z7MessagesPanelTableView * nutritionMsgsTable
instancetype sharedInstance()
void fetchJournalHeaders:(id< Z5GmailDataListener > listener)
Boolean deleteEmailMessageWithFileIdentification:(NSString *googlefileid)
NSDateFormatter * mDateFormatter
const NSString * HeaderIdentifier
NSDateFormatter * msgNearDateFormatter
CGRect nutritionMessagesFrame
Y3GmailViewHeader * gmailViewHeader
void labelizeCell:withText:image:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [image] NSData *cellImage, [inColor] UIColor *color, [andDetail] NSString *detailTxt)
Singleton interface to both core and remote data sources.
NSInteger assessMessagesToDisplay()
NSDateFormatter * dspNearDateFormatter
GIDGoogleUser * signedInUser
NSArray * retrieveAllEmailMessages()
M9MailServerNavigator * mailUtility
NSString * nutritionJournalDataTitleKey
Fetch all marked emails into the local database, and display a list.
NSMutableArray< NSString * > * rows
Y3GmailViewFooter * gmailViewFooter