Today's Menu  Portugal
journal and plan nutrition
V7GoogDriveViewController.m
Go to the documentation of this file.
1 //
2 // V7GoogDriveViewController.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 4/16/18.
6 // Copyright © 2018 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
10 #import "V7GoogDriveTableView.h"
11 #import "Z5DataController.h"
12 #import "Z1ContainedLabel.h"
16 
17 @interface V7GoogDriveViewController ()
18 
19 @end
20 
60 @implementation V7GoogDriveViewController
61 {
62  V7GoogDriveControlbarView *controlBar;
65 
66 // V7GoogDriveAPIController *driveAPIcontroller;
67  NSMutableArray *focusFoodDriveArray;
68  NSString *foodName;
69 
73 }
74 
75 - (void)viewDidLoad {
76  [super viewDidLoad];
77  // Do any additional setup after loading the view.
78  self.title = @"Google Drive";
79 
80  [[self view] setBackgroundColor:[UIColor colorWithHue:0.32
81  saturation:0.8
82  brightness:0.5
83  alpha:1.0]];
84  UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Create item"
85  style:UIBarButtonItemStylePlain
86  target:self
87  action:@selector(createFoodItem)];
88  self.navigationItem.rightBarButtonItem = anotherButton;
89  self.navigationItem.rightBarButtonItem.enabled = YES;
90 
91  // This array manages all the drive-menu-itmes shown.
92  focusFoodDriveArray = [[NSMutableArray alloc] init];
93 
94  [self placeUIComponents];
95 
96  Z5GoogleLoginController *loginControl = [[[Z5DataController sharedInstance] remoteDataController] loginController];
97 
98  driveControl = [[[Z5DataController sharedInstance] remoteDataController] driveController];
99  // driveAPIcontroller = [[V7GoogDriveAPIController alloc] initWithDelegate:self];
100  if ([[loginControl signedIn] boolValue]) {
101  [self viewDidLoadLoggedIn:[loginControl signedInUser]];
102 
103  [driveControl listRootFor:self];
104  /*
105  -(void) listRootFor:(id<V7GoogDriveAPIProtocol>rqstor
106  {
107  GTLRServiceTicket *rootListTicket = [self listRoot];
108 
109  NSDictionary<NSString *,id> *extraTicketProps = [rootListTicket ticketProperties];
110  NSString *rootFetchKey = [extraTicketProps objectForKey:@"query-stage"];
111  NSLog(@"V7GoogleDriveViewController.viewDidLoad: rootFetechKey: %@", rootFetchKey);
112  }
113  */
114 // self.service = [driveControl service];
115 
116 // GTLRServiceTicket *rootListTicket = [self listRoot];
117 //
118 // NSDictionary<NSString *,id> *extraTicketProps = [rootListTicket ticketProperties];
119 // NSString *rootFetchKey = [extraTicketProps objectForKey:@"query-stage"];
120 // NSLog(@"V7GoogleDriveViewController.viewDidLoad: rootFetechKey: %@", rootFetchKey);
121 
122  } else {
123  [self viewDidLoadAnonymous];
124  }
125 }
126 -(void)viewWillAppear:(BOOL)animated
127 {
128  CGRect totalFrame = self.view.frame;
129  float tableWidth = totalFrame.size.width - 8;
130  CGRect tableBound = CGRectMake(0.0, 0.0, tableWidth, 70.0);
131 
132  CGRect focusFoodBaseLabelFrame = CGRectMake(4.0, 0.0, tableWidth - 8.0, 36);
133  UILabel *focusFoodBaseLabel = [[UILabel alloc] initWithFrame:focusFoodBaseLabelFrame];
134 
135  [Z5DataController extraLabelize:focusFoodBaseLabel withText:@"Menu Items"];
136  [focusFoodLabel setMessageLabel:focusFoodBaseLabel];
137  [focusFoodLabel appear:tableBound];
138 
139  [controlBar appear:googDriveControlBarFrame];
140 
141  NSLog(@"V7GoogDriveViewController.viewWillAppear end");
142 }
144 {
145  // [self.view setBackgroundColor:[[Z5DataController sharedInstance] grapeSkinDeepPurple]];
146  // [self.view setBackgroundColor:[UIColor redColor]];
147  float snugMargin = 2.0;
148  CGRect totalFrame = self.view.frame;
149  float totalWidth = totalFrame.size.width - (2*snugMargin);
150  float tableWidth = totalFrame.size.width - (2*snugMargin);
151  CGRect topNavigationFrame = [[[self navigationController] navigationBar] frame];
152  float topOfContent = topNavigationFrame.origin.y + topNavigationFrame.size.height;
153 
154  float controlbarHeight = 52.0;
155  googDriveControlBarFrame = CGRectMake(snugMargin,
156  topOfContent+snugMargin,
157  totalWidth - (2*snugMargin),
158  controlbarHeight);
159  controlBar = [[V7GoogDriveControlbarView alloc] initWithDelegate:self andFrame:googDriveControlBarFrame];
160 
161  float tableTop = topOfContent + controlbarHeight+(2*snugMargin);
163  = CGRectMake(snugMargin,
164  tableTop,
165  tableWidth,
166  totalFrame.size.height - tableTop - 150);
167 
168  float focusFoodLabelFrameHeight = 60;
169  CGRect focusFoodLabelFrame = CGRectMake(4.0,
170  0.0,
171  tableWidth - 8.0,
172  focusFoodLabelFrameHeight);
173  focusFoodLabel = [[Z1ContainedLabel alloc] initWithFrame:focusFoodLabelFrame];
174 
175  NSNumber *labelHeight = [NSNumber numberWithFloat:36.0];
176  [focusFoodLabel setContainedHeight:labelHeight];
177  [focusFoodLabel setBackgroundColor:[UIColor greenColor]];
178 
180  initWithFrame:googDriveListTableViewFrame
181  andHeader:focusFoodLabel
182  inContainer:self];
183  [googDriveListTableView setDataSource:self];
184  [googDriveListTableView setDelegate:self];
185  [googDriveListTableView setTableCaption:focusFoodLabel];
186  [googDriveListTableView setBackgroundColor:[UIColor wheatColor]];
187 
188  [self.view addSubview:controlBar];
189  [self.view addSubview:googDriveListTableView];
190 }
191 
192 - (NSMutableArray *) provideFocusFoodListDriveArray
193 {
194  return focusFoodDriveArray;
195 }
197 {
198  // CGRect totalFrame = self.view.frame;
199  Z5GoogleLoginController *loginControl = [[[Z5DataController sharedInstance] remoteDataController] loginController];
200 
201  [loginControl configureGoogleSignIn];
202  GIDSignIn* signIn = [GIDSignIn sharedInstance];
203  signIn.uiDelegate = self;
204 
205  [controlBar placeLoginButton];
206 }
207 - (GTLRDriveService *) viewDidLoadLoggedIn:(GIDGoogleUser *) signedInUser
208 {
209  Z5GoogleDriveController *driveControl = [[[Z5DataController sharedInstance] remoteDataController] driveController];
210 
211  [driveControl signedIn:signedInUser];
212 
213  // [self loadViewLoggedIn];
214 
215  GTLRDriveService *ret = [driveControl service];
216 
217  return ret;
218 }
219 //- (void) loadViewLoggedIn
220 //{
221 // // CGRect totalFrame = self.view.frame;
222 //
230 //
231 // // Further
232 // // exerise 'listFiles' (really 'listRoot') and generate table of
233 // // folders and files encountered.
234 // // 'item-selected' response will be to do the same in the focus folder
240 //}
242 {
243  [self.listFilesButton removeFromSuperview];
244  [self viewDidLoadAnonymous];
245 }
246 - (void) signedIn: (GIDGoogleUser *)user
247 {
248  NSLog(@"GoogDriveViewController.signedIn: user-auth: %@", user.authentication.fetcherAuthorizer);
249 
250 // Z5GoogleDriveController *driveControl = [[[Z5DataController sharedInstance] remoteDataController] driveController];
251 // self.service = [driveControl service];
252 
253  // [_signInButton removeFromSuperview];
254  [controlBar userLoggedIn:YES];
255  // [self loadViewLoggedIn];
256 }
257 
258 - (void)signedOut:(GIDGoogleUser *)user {
259  // self.service = nil;
260  [controlBar userLoggedIn:NO];
261  [self unloadViewLoggedIn];
262  [self viewDidLoadAnonymous];
263 }
264 
265 #pragma mark - V7GoogDriveAPIProtocol
266 - (void) ticketCompleted:(GTLRServiceTicket *)ticket;
267 {
268  NSLog(@"GoogDriveViewController.ticketCompleted");
269 }
270 - (void) resultStage: (QueryStage)stage returnedFiles: (NSArray<GTLRDrive_File *> *)files
271 {
272  switch(stage){
273  case qNone:
274  {
275  NSLog(@"V7GoogDriveViewController.resultStage: qNone");
276  }
277  break;
278  case qRoot:
279  {
280  NSLog(@"V7GoogDriveViewController.resultStage: qRoot");
281  }
282  break;
283  case qJournalRoot:
284  {
285  NSLog(@"V7GoogDriveViewController.resultStage: qJournalRoot");
286 
287  // this is original work for chase-journal-root
288 // for (GTLRDrive_File *file in files) {
289 // [focusFoodDriveArray addObject:file];
290 //
291 // NSLog(@"V7GoogDriveViewController.resultStage: mimeType %@", file.mimeType);
292 //
293 // if ([file.mimeType isEqualToString:@"application/vnd.google-apps.folder"]) {
294 // NSLog(@"V7GoogDriveViewController.resultStage: Folder in Journal-Root, request parts");
295 // [driveControl listJournaItemPartRoot:file.identifier];
296 // } else {
297 // ;
298 // }
299 // }
300  [googDriveListTableView reloadData];
301 
302 
303  }
304  break;
305  case qJournalPartRoot:
306  {
307  NSLog(@"V7GoogDriveViewController.resultStage: qJournalPartRoot");
308 
309  }
310  break;
311  case kOblateSpheroid:
312  {
313  NSLog(@"V7GoogDriveViewController.resultStage: kOblateSpheroid");
314 
315  }
316  break;
317  }
318 
319 
320  }
321 #pragma mark - moved to APIController
322 
323 
324 #pragma mark - local controls
326 {
327  NSLog(@"V7GoogDriveViewController.createFoodItem");
328  /* Create folder within root directory'journalItemRoot' with name of food */
329  V7GoogDriveMenuItemViewController *driveMenuItem =
330  [[V7GoogDriveMenuItemViewController alloc] initWithNibName:nil bundle:nil];
331 
332  // [parameterView setText:@"from the Snippet controller"];
333 
334  [self.navigationController pushViewController:driveMenuItem animated:YES];
335 
336 }
338 {
339  NSLog(@"V7GoogDriveViewController.clickRecipeBuuton");
340 }
341 
342 #pragma mark - UITableViewDataSource
343 
344 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
345 {
346  NSInteger ret = 1;
347  // Z5LocalDataController *localData = [[Z5DataController sharedInstance] localDataController];
348 
349  NSLog(@"V7GoogDriveViewController.numberOfSectionsInTableView: %ld", (long)ret);
350 
351  return ret;
352 }
353 - (NSInteger)tableView:(UITableView *)tableView
354  numberOfRowsInSection:(NSInteger)section
355 {
356  NSInteger ret = [focusFoodDriveArray count];
357 
358  NSLog(@"V7GoogDriveViewController.numberOfRowsInSection: section# %ld, rows: %ld", (long)section, (long)ret);
359 
360  return ret;
361 }
362 
363 - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
364 
365  UITableViewCell *cell = nil;
366  // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"usda-data-display"];
367  // NSLog(@"U3parameterTableView.tableCellForRow: %ld cell: %@", (long)[indexPath row], cell);
368  if (cell == nil) {
369  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"usda-pdata-display"];
370 
371  cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
372 
373  CGRect contentRect = [cell.contentView frame];
374  CGRect fetchPublishButton1Frame = CGRectMake(contentRect.size.width - 86.0f, 5.0, 64.0f, contentRect.size.height - 10);
375  UIButton *pushMe = [[UIButton alloc] initWithFrame:fetchPublishButton1Frame];
376  [pushMe setBackgroundColor:[UIColor grayColor]];
377  [pushMe setTitle:@"GO" forState:UIControlStateNormal];
378  [pushMe setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
379 
380  [cell.contentView addSubview:pushMe];
381 
382  [cell.layer setCornerRadius:7.0f];
383  [cell.layer setMasksToBounds:YES];
384  [cell.layer setBorderWidth:1.0f];
385 
386  [cell.textLabel setTextColor:[UIColor purpleColor]];
387  [cell.textLabel setOpaque:YES];
388  }
389  [cell setBackgroundColor:[UIColor brownColor]];
390  NSInteger nComponents = [focusFoodDriveArray count];
391 
392  if (nComponents > [indexPath row]) {
393 
394  GTLRDrive_File *driveFile = [focusFoodDriveArray objectAtIndex:[indexPath row]];
395  [Z5DataController labelizeCell:cell withText:[driveFile name] inColor:[UIColor pearlColor] andDetail:nil];
396 
397  } else if (0 == nComponents) {
398  cell.textLabel.text = @"no food data";
399  }
400  // NSLog(@"U3parameterTableView.tableCellForRow: %ld return cell: %@", (long)[indexPath row], cell);
401  return cell;
402 }
403 
404 #pragma mark - UITableViewDelegate
405 
406 - (void)tableView:(UITableView *)tableView
407 didSelectRowAtIndexPath:(NSIndexPath *)indexPath
408 {
409  NSUInteger row_n = [indexPath row];
410  GTLRDrive_File *file = [focusFoodDriveArray objectAtIndex:row_n];
411  NSLog(@"V7GoogDriveViewController.didSelectRowAtIndexPath: %@, mimeType %@", [file name], file.mimeType);
412  if ([file.mimeType isEqualToString:@"application/vnd.google-apps.folder"]){
413  [driveControl listJournaItemPartRoot:file.identifier];
414  } else {
415  NSLog(@"V7GoogDriveViewController.didSelectRowAtIndexPath: no directory");
416  }
417 
418 }
419 
420 #pragma mark -
421 
423  [super didReceiveMemoryWarning];
424  // Dispose of any resources that can be recreated.
425 }
426 
427 @end
NSMutableArray * focusFoodDriveArray
GTLRDriveService * viewDidLoadLoggedIn:(GIDGoogleUser *signedInUser)
void extraLabelize:withText:(UILabel *targLabel, [withText] NSString *txt)
V7GoogDriveTableView * googDriveListTableView
NSString * foodName
CGRect googDriveControlBarFrame
instancetype sharedInstance()
id< GTMFetcherAuthorizationProtocol > fetcherAuthorizer()
Z5GoogleDriveController * driveControl
void signedIn:(GIDGoogleUser *user)
GTLRServiceTicket * listJournaItemPartRoot:(NSString *journalItemPartRootId)
NSMutableArray * provideFocusFoodListDriveArray()
id< GIDSignInUIDelegate > uiDelegate
Definition: GIDSignIn.h:106
Z1ContainedLabel * focusFoodLabel
Singleton interface to both core and remote data sources.
GIDSignIn * sharedInstance()
GIDAuthentication * authentication
Definition: GIDGoogleUser.h:27
void labelizeCell:withText:inColor:andDetail:(UITableViewCell *targCell, [withText] NSString *txt, [inColor] UIColor *color, [andDetail] NSString *detailTxt)
CGRect googDriveListTableViewFrame