Today's Menu  Portugal
journal and plan nutrition
V7GoogleLoginControlbar.m
Go to the documentation of this file.
1 //
2 // V7GoogDriveMenuItemControlbar.m
3 // TodaysMenu
4 //
5 // Created by Don Zeek on 12/29/18.
6 // Copyright © 2018 net.dzeek.y2015.ios.portfolio. All rights reserved.
7 //
8 
12 #import "Z5DataController.h"
13 
14 @implementation V7GoogleLoginControlbar
15 {
16  UILabel *loginInfoLabel;
17  CGRect controlbarFrame;
18 }
20 
21 id<V7GoogleLoginProtocol> loginGoogleDelegate;
22 
23 - (instancetype) initWithFrame:(CGRect)frame andDelegate:(id<V7GoogleLoginProtocol>)delegate
24 {
25  self = [super initWithFrame:frame];
26  if (self) {
28  controlbarFrame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
29  loginInfoViewHeight = frame.size.height - 2.0;
30  }
31  return self;
32 }
33 //+ (float) heightRequirement
34 //{
35 // return 48;
36 //}
38 {
39  return 56.0;
40 }
41 - (void) appear
42 {
43  [self appear:controlbarFrame];
44 }
45 - (void) appear:(CGRect)bound
46 {
47  Z5GoogleLoginController *loginControl = [[[Z5DataController sharedInstance] remoteDataController] loginController];
48 
49  [loginControl addLoginListener:self];
50  // Boolean isLoggedIn = [[loginControl signedIn] boolValue];
51  Boolean isLoggedIn;
52  if (nil==[loginControl username]) {
53  isLoggedIn = NO;
54  NSLog(@"V7GoogleLoginControlbar.appear: not logged in");
55  } else {
56  isLoggedIn = YES;
57  NSLog(@"V7GoogleLoginControlbar.appear: user: %@",
58  [loginControl username]);
59  }
60  if (isLoggedIn) {
61  [self setBackgroundColor:[UIColor greenColor]];
62 
63  float submitButtonWidth = 132;
64  float submitButtonHeight = 32;
65  CGRect logOutFrame = CGRectMake(bound.size.width - (submitButtonWidth+ 20.0), 2.0, submitButtonWidth, submitButtonHeight);
66  CGRect forwardButtonFrame = CGRectMake(bound.size.width - 76, 4, 48, 48);
67  _forwardButton = [[UIButton alloc] initWithFrame: forwardButtonFrame];
68  [_forwardButton addTarget:self action:@selector(createEntryOnDrive) forControlEvents:UIControlEventTouchUpInside];
69  UIImage *forwardButtonImage = [UIImage imageNamed:@"forwardButton.png"];
70  [_forwardButton setImage:forwardButtonImage forState:UIControlStateNormal];
71  [self addSubview:_forwardButton];
72 
73  // ==========================
74 
75  CGRect loginInfoLabelFrame = CGRectMake(2.0, 2.0, bound.size.width/2, loginInfoViewHeight - 4.0);
76 
77  loginInfoLabel = [[UILabel alloc] initWithFrame:loginInfoLabelFrame];
78  [loginInfoLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]];
79  NSString *loginName = [[loginControl getLoggedInProfile] name];
80  [loginInfoLabel postAttributedText:loginName];
81  [loginInfoLabel setTextAlignment:NSTextAlignmentCenter];
82  [loginInfoLabel setBackgroundColor:[[Z5DataController sharedInstance] wheatColor]];
83  [loginInfoLabel.layer setBorderColor: [[UIColor blackColor] CGColor]];
84  [loginInfoLabel.layer setBorderWidth: 2.0];
85  loginInfoLabel.layer.cornerRadius = 8.0f;
86  loginInfoLabel.layer.masksToBounds = YES;
87  [self addSubview:loginInfoLabel];
88  } else {
89  [self setBackgroundColor:[UIColor cyanColor]];
90 
91  CGRect signInButtonFrame = CGRectMake(bound.size.width/2 + 2,
92  2.0,
93  bound.size.width/2 - 4,
95 
96 
97 
98 
99  [loginControl configureGoogleSignIn];
100  GIDSignIn* signIn = [GIDSignIn sharedInstance];
101  signIn.uiDelegate = (id<GIDSignInUIDelegate>)self;
102  signIn.delegate = loginControl;
103 
104  _signInButton = [[GIDSignInButton alloc] init];
105  [_signInButton setFrame:signInButtonFrame];
106  _signInButton.layer.cornerRadius = 8;
107  _signInButton.layer.borderColor = [[UIColor blackColor] CGColor];
108  _signInButton.layer.borderWidth = 3.0;
109  _signInButton .clipsToBounds = YES;
110  [self addSubview:_signInButton];
111  }
112 
113 }
114 
115 - (void) logOutGoogle
116 {
117  Z5GoogleLoginController *loginControl = [[[Z5DataController sharedInstance] remoteDataController] loginController];
118  [loginControl logOutGoogle];
119 // [loginGoogleDelegate regenerateLoginView];
120 }
121 
123 {
124  NSLog(@"V7GoogleLoginControlbar.createEntryOnDrive");
125  Z5GoogleDriveController *driveController = [[[Z5DataController sharedInstance] remoteDataController] driveController];
126  // TODO: FIX [driveController placeRecipe];
127 }
128 
129 #pragma mark - GIDSignInUIDelegate
130 
135 - (void) signInWillDispatch:(GIDSignIn *)signIn
136  error:(NSError *) error
137 {
138  NSLog(@"V7GoogleLoginControlbar.signInWillDispatch");
139 }
140 
148 - (void) signIn:(GIDSignIn *) signIn presentViewController:(UIViewController *) viewController
149 {
150  NSLog(@"V7GoogleLoginControlbar.presentViewController: %@",
151  NSStringFromClass([viewController class]));
152 }
153 
159 - (void) signIn:(GIDSignIn *) signIn dismissViewController: (UIViewController *) viewController
160 {
161  NSLog(@"V7GoogleLoginControlbar.dismissViewController: %@",
162  NSStringFromClass([viewController class]));
163 }
164 
165 /*
166 // Only override drawRect: if you perform custom drawing.
167 // An empty implementation adversely affects performance during animation.
168 - (void)drawRect:(CGRect)rect {
169  // Drawing code
170 }
171 */
172 
173 - (void) signedIn: (GIDGoogleUser *)user
174 {
175  NSLog(@"V7GoogleLoginControlbar.signedIn: %@", user.profile.name);
176  [loginGoogleDelegate regenerateLoginView];
177 }
178 
179 - (void)signedOut:(GIDGoogleUser *)user
180 {
181  [loginGoogleDelegate regenerateLoginView];
182 }
183 
184 
185 @end
id< GIDSignInDelegate > delegate
Definition: GIDSignIn.h:103
GIDProfileData * profile
Definition: GIDGoogleUser.h:24
void addLoginListener:(id< Z5GoogleLoginListener > ear)
instancetype sharedInstance()
CGRect controlbarFrame
float loginInfoViewHeight
UILabel * loginInfoLabel
id< U7ParamEditControlDelegate > delegate
id< GIDSignInUIDelegate > uiDelegate
Definition: GIDSignIn.h:106
id< V7GoogleLoginProtocol > loginGoogleDelegate
GIDProfileData * getLoggedInProfile()
Singleton interface to both core and remote data sources.
NSString * name
GIDSignIn * sharedInstance()