13 #import "NSDate+CalendarView.h" 62 NSString *imageName =
@"softGreenBackgroud.png";
63 self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]]];
67 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
68 [[NSNotificationCenter defaultCenter] addObserver:self
69 selector:@selector(deviceOrientationDidChange:)
70 name: UIDeviceOrientationDidChangeNotification
77 - (void)deviceOrientationDidChange:(NSNotification *)notification {
82 - (void) orientLoadUI {
84 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
87 case UIDeviceOrientationPortrait:
88 case UIDeviceOrientationFaceUp:
93 case UIDeviceOrientationLandscapeLeft:
94 case UIDeviceOrientationLandscapeRight:
101 NSLog(
@"B2CalendarViewController.orientLoadUI: unk orrientation");
106 - (void) viewDidLoadPortrait
108 CGSize totalFrameSize =
self.view.frame.size;
109 CGRect topNavigationFrame = [[[
self navigationController] navigationBar] frame];
110 float topOfPageF = topNavigationFrame.origin.y + topNavigationFrame.size.height;
113 float dirButtonWidth = 60.0;
114 float centerLabelWidth = totalFrameSize.width - (2 * dirButtonWidth) - 8.0;
115 float buttonHeight = 46.0;
117 UIColor *buttonBckgrndColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.60 alpha:0.9];
119 float bckMonthButtonLeftEdge = 4.0f;
120 CGRect bckMonthFrame = CGRectMake(bckMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
122 [bckMonthButton setBackgroundColor:buttonBckgrndColor];
123 [bckMonthButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
124 [bckMonthButton addGradientFace:gradientBandColor];
125 [bckMonthButton setTitle:@"<<" forState:UIControlStateNormal];
126 [bckMonthButton addTarget:self action:@selector(didClickPageBck) forControlEvents:UIControlEventTouchUpInside];
127 [
self.view addSubview:bckMonthButton];
129 float dateHeaderButtonLeftEdge = dirButtonWidth + 8.0f;
130 float labelWidth = centerLabelWidth-4.0;
131 CGRect dateHeaderButtonFrame = CGRectMake(dateHeaderButtonLeftEdge, topOfPageF, labelWidth, buttonHeight);
133 [dateHeaderButton setBackgroundColor:[UIColor whiteColor]];
134 [dateHeaderButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
135 [dateHeaderButton addGradientFace:gradientBandColor];
136 [dateHeaderButton addTarget:self action:@selector(didClickMonthHeader) forControlEvents:UIControlEventTouchUpInside];
137 [
self.view addSubview:dateHeaderButton];
139 float fwdMonthButtonLeftEdge =totalFrameSize.width - (dirButtonWidth+4.0);
140 CGRect fwdMonthFrame =CGRectMake(fwdMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
142 [fwdMonthButton setBackgroundColor:[UIColor whiteColor]];
143 [fwdMonthButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
144 [fwdMonthButton addGradientFace:gradientBandColor];
145 [fwdMonthButton setTitle:@">>" forState:UIControlStateNormal];
146 [fwdMonthButton addTarget:self action:@selector(didClickPageFwd) forControlEvents:UIControlEventTouchUpInside];
147 [
self.view addSubview:fwdMonthButton];
149 topOfPageF += buttonHeight;
153 [calendarView setPreferredWeekStartIndex:0];
154 [calendarView setCalendarDelegate:self];
157 float calendarWidth = totalFrameSize.width-12;
158 float calendarHeight = totalFrameSize.height-12-topOfPageF;
159 CGRect calendarFrame = CGRectMake(6, topOfPageF+6, calendarWidth, totalFrameSize.height-12-topOfPageF);
160 [calendarView setFrame:calendarFrame];
162 float dayCellWidth = calendarWidth/8;
163 float dayCellHeight = calendarHeight/6;
164 [calendarView setDayCellWidth:dayCellWidth];
165 [calendarView setDayCellHeight:dayCellHeight];
166 [calendarView refresh];
167 [
self.view addSubview:calendarView];
169 - (void) viewDidLoadLandscape
171 CGSize totalFrameSize =
self.view.frame.size;
172 CGRect topNavigationFrame = [[[
self navigationController] navigationBar] frame];
173 float topOfPageF = topNavigationFrame.origin.y + topNavigationFrame.size.height;
176 float dirButtonWidth = 60.0;
177 float centerLabelWidth = totalFrameSize.width - (2 * dirButtonWidth) - 8.0;
178 float buttonHeight = 46.0;
180 UIColor *buttonBckgrndColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.60 alpha:0.9];
183 float bckMonthButtonLeftEdge = 4.0f;
184 CGRect bckMonthFrame =CGRectMake(bckMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
186 [bckMonthButton setBackgroundColor:buttonBckgrndColor];
187 [bckMonthButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
188 [bckMonthButton addGradientFace:gradientBandColor];
189 [bckMonthButton setTitle:@"<<" forState:UIControlStateNormal];
190 [bckMonthButton addTarget:self action:@selector(didClickPageBck) forControlEvents:UIControlEventTouchUpInside];
191 [
self.view addSubview:bckMonthButton];
193 float dateHeaderButtonLeftEdge = dirButtonWidth + 8.0f;
194 float labelWidth = centerLabelWidth-4.0;
195 CGRect dateHeaderButtonFrame = CGRectMake(dateHeaderButtonLeftEdge, topOfPageF, labelWidth, buttonHeight);
197 [dateHeaderButton setBackgroundColor:[UIColor whiteColor]];
198 [dateHeaderButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
199 [dateHeaderButton addGradientFace:gradientBandColor];
200 [dateHeaderButton addTarget:self action:@selector(didClickMonthHeader) forControlEvents:UIControlEventTouchUpInside];
201 [
self.view addSubview:dateHeaderButton];
203 float fwdMonthButtonLeftEdge =totalFrameSize.width - (dirButtonWidth+4.0);
204 CGRect fwdMonthFrame =CGRectMake(fwdMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
206 [fwdMonthButton setBackgroundColor:[UIColor whiteColor]];
207 [fwdMonthButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
208 [fwdMonthButton addGradientFace:gradientBandColor];
209 [fwdMonthButton setTitle:@">>" forState:UIControlStateNormal];
210 [fwdMonthButton addTarget:self action:@selector(didClickPageFwd) forControlEvents:UIControlEventTouchUpInside];
211 [
self.view addSubview:fwdMonthButton];
214 topOfPageF += buttonHeight;
218 [calendarView setPreferredWeekStartIndex:0];
219 [calendarView setCalendarDelegate:self];
222 float calendarWidth = totalFrameSize.width-12;
223 float calendarHeight = totalFrameSize.height-12-topOfPageF;
224 CGRect calendarFrame = CGRectMake(6, topOfPageF+6, calendarWidth, totalFrameSize.height-12-topOfPageF);
225 [calendarView setFrame:calendarFrame];
227 float dayCellWidth = calendarWidth/8;
228 float dayCellHeight = calendarHeight/6;
229 [calendarView setDayCellWidth:dayCellWidth];
230 [calendarView setDayCellHeight:dayCellHeight];
231 [calendarView refresh];
232 [
self.view addSubview:calendarView];
235 - (void) orientAppearUI {
236 NSLog(
@"B2CalendarViewController.orientAppearUI");
237 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
240 case UIDeviceOrientationPortrait:
241 case UIDeviceOrientationFaceUp:
246 case UIDeviceOrientationLandscapeLeft:
247 case UIDeviceOrientationLandscapeRight:
254 NSLog(
@"B2CalendarViewController.viewDidLoad: unk orrientation");
259 - (void) viewDidAppearPortrait
261 CGSize totalFrameSize =
self.view.frame.size;
262 CGRect topNavigationFrame = [[[
self navigationController] navigationBar] frame];
263 float topOfPageF = topNavigationFrame.origin.y + topNavigationFrame.size.height;
266 float dirButtonWidth = 60.0;
267 float centerLabelWidth = totalFrameSize.width - (2 * dirButtonWidth) - 8.0;
268 float buttonHeight = 46.0;
270 float bckMonthButtonLeftEdge = 4.0f;
271 CGRect bckMonthFrame =CGRectMake(bckMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
272 [bckMonthButton setFrame:bckMonthFrame];
274 float dateHeaderButtonLeftEdge = dirButtonWidth + 8.0f;
275 float labelWidth = centerLabelWidth-4.0;
276 CGRect dateHeaderButtonFrame = CGRectMake(dateHeaderButtonLeftEdge, topOfPageF, labelWidth, buttonHeight);
277 [dateHeaderButton setFrame:dateHeaderButtonFrame];
279 float fwdMonthButtonLeftEdge =totalFrameSize.width - (dirButtonWidth+4.0);
280 CGRect fwdMonthFrame =CGRectMake(fwdMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
281 [fwdMonthButton setFrame:fwdMonthFrame];
283 topOfPageF += buttonHeight;
291 float calendarWidth = totalFrameSize.width-12;
292 float calendarHeight = totalFrameSize.height-12-topOfPageF;
293 CGRect calendarFrame = CGRectMake(6, topOfPageF+6, calendarWidth, totalFrameSize.height-12-topOfPageF);
294 [calendarView setFrame:calendarFrame];
296 float dayCellWidth = calendarWidth/8;
297 float dayCellHeight = calendarHeight/6;
298 [calendarView setDayCellWidth:dayCellWidth];
299 [calendarView setDayCellHeight:dayCellHeight];
300 [calendarView refresh];
302 - (void) viewDidAppearLandscape
304 CGSize totalFrameSize =
self.view.frame.size;
305 CGRect topNavigationFrame = [[[
self navigationController] navigationBar] frame];
306 float topOfPageF = topNavigationFrame.origin.y + topNavigationFrame.size.height;
309 float dirButtonWidth = 60.0;
310 float centerLabelWidth = totalFrameSize.width - (2 * dirButtonWidth) - 8.0;
311 float buttonHeight = 46.0;
313 float bckMonthButtonLeftEdge = 4.0f;
314 CGRect bckMonthFrame =CGRectMake(bckMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
315 [bckMonthButton setFrame:bckMonthFrame];
317 float dateHeaderButtonLeftEdge = dirButtonWidth + 8.0f;
318 float labelWidth = centerLabelWidth-4.0;
319 CGRect dateHeaderButtonFrame = CGRectMake(dateHeaderButtonLeftEdge, topOfPageF, labelWidth, buttonHeight);
320 [dateHeaderButton setFrame:dateHeaderButtonFrame];
322 float fwdMonthButtonLeftEdge =totalFrameSize.width - (dirButtonWidth+4.0);
323 CGRect fwdMonthFrame =CGRectMake(fwdMonthButtonLeftEdge, topOfPageF, dirButtonWidth, buttonHeight);
324 [fwdMonthButton setFrame:fwdMonthFrame];
327 topOfPageF += buttonHeight;
334 float calendarWidth = totalFrameSize.width-12;
335 float calendarHeight = totalFrameSize.height-12-topOfPageF;
336 CGRect calendarFrame = CGRectMake(6, topOfPageF+6, calendarWidth, totalFrameSize.height-12-topOfPageF);
337 [calendarView setFrame:calendarFrame];
339 float dayCellWidth = calendarWidth/8;
340 float dayCellHeight = calendarHeight/6;
341 [calendarView setDayCellWidth:dayCellWidth];
342 [calendarView setDayCellHeight:dayCellHeight];
343 [calendarView refresh];
346 - (void) viewWillAppear:(BOOL)animated
351 [dateHeaderButton setTitle:monthLabel forState:UIControlStateNormal];
353 [calendarView refreshCalendar];
355 #pragma mark - CalendarViewDelegate 358 - (void)didChangeCalendarDate:(NSDate *)date
360 NSLog(
@"B2CalendarViewController.didChangeCalendarDate: date: %@", date);
365 - (void)didChangeCalendarDate:(NSDate *)date withType:(NSInteger)type withEvent:(NSInteger)event
367 NSLog(
@"B2CalendarViewController.didChangeCalendarDate: %@ withType: %ld withEvent: %ld", date, (
long)type, (
long)event);
370 NSLog(
@"B2CalendarViewController.didChangeCalendarDate: chg adv/rev by month");
380 if (0 < [dayMeals count]) {
382 [menuPostVC setPostedMeals:dayMeals];
383 [menuPostVC setPostingDate:date];
385 NSLog(
@"B2CalendarViewController.didChangeCalendarDate");
387 [
self.navigationController pushViewController:menuPostVC animated:YES];
394 - (void)didDoubleTapCalendar:(NSDate *)date withType:(NSInteger)type
396 NSLog(
@"B2CalendarViewController.didDoubleTapCalendar");
399 - (void)didSelectRangeForStartDate:(NSDate *) startDate andEndDate:(NSDate *) endDate
401 [mDateFormatter setDateStyle:NSDateFormatterMediumStyle];
402 [mDateFormatter setTimeStyle:NSDateFormatterShortStyle];
404 NSLog(
@"B2CalendarViewController.didSelectRangeForStartDate: %@ and EndDate: %@", [
mDateFormatter stringFromDate:startDate], [
mDateFormatter stringFromDate:endDate]);
407 #pragma mark - Local controls 409 - (NSString *) produceDateLabelText
425 NSString *monthLabel = [mDateFormatter stringFromDate:[calendarView currentDate]];
429 - (void) didClickMonthHeader
432 [
self.navigationController pushViewController:menuPostVC animated:YES];
434 - (void) didClickPageBck
436 [calendarView rewindCalendarContents];
438 [dateHeaderButton setTitle:monthLabel forState:UIControlStateNormal];
440 [calendarView refreshCalendar];
443 - (void) didClickPageFwd
445 [calendarView advanceCalendarContents];
447 [dateHeaderButton setTitle:monthLabel forState:UIControlStateNormal];
450 #pragma mark - Safety 452 - (void)didReceiveMemoryWarning {
453 [
super didReceiveMemoryWarning];
void viewDidAppearPortrait()
instancetype sharedInstance()
NSDateFormatter * mDateFormatter
NSArray< Meal * > * findMealsWithDate:(NSDate *findDate)
NSString * produceDateLabelText()
UIButton * dateHeaderButton
void viewDidAppearLandscape()
B2NutritionCalendarView * calendarView
UIButton * fwdMonthButton
Singleton interface to both core and remote data sources.
void viewDidLoadLandscape()
void viewDidLoadPortrait()
UIButton * bckMonthButton