-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarViewController.m
698 lines (567 loc) · 29.5 KB
/
CalendarViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
//
// CalendarViewController.m
// CourseShopper
//
// Created by Noah Fradin on 11/20/13.
// Copyright (c) 2013 Noah Fradin. All rights reserved.
//
#import "CalendarViewController.h"
#import "DepartmentTableViewController.h"
#import "TWTSideMenuViewController.h"
#import "CourseViewController.h"
#import "CCCourseButton.h"
#import "ConflictViewController.h"
@interface CalendarViewController (){
double startTimeDouble;
double endTimeDouble;
NSInteger day;
UIView *emptyCartView;
}
#define SCREEN_WIDTH 320
#warning set screen height conditionally based on model
#define SCREEN_HEIGHT 568 //iPhone 5 and up in future will set conditional based on phone type
#define DAY_WIDTH 61 // 64 = 320width/5days
#define HOUR_HEIGHT 47 // = 568height/12hours
#define TOPBAR_HEIGHT 64 //Statusbar height plus nav bar height w/out daybar
//Need to define sidebar and daybar width/height
#define DAYBAR_HEIGHT 34
#define HOUR_BLOCK 34
#define MINUTE_BLOCK .57
#define HOURS_TO_SHOW 12
#define degreesToRadians(degrees) (M_PI * degrees / 180.0)
#define buttonPaneHeight self.view.frame.size.height*46/64
#define buttonPaneWidth self.view.frame.size.width*18/20
#define labelHeight buttonPaneHeight/10
#define offset buttonPaneHeight/30
#define textViewWidth buttonPaneWidth- 2*offset
#define textViewHeight buttonPaneHeight - 4*offset - 2*labelHeight
#define cancelHeight labelHeight
@end
@implementation CalendarViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewWillAppear:(BOOL)animated{
[self.view setBackgroundColor:[UIColor whiteColor]];
}
//So we can do stuff in this method you want to happen preload.. good place to put navbar stuff
-(void)viewDidAppear:(BOOL)animated{
[[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
/////////////////////////////////////////////////////////
//General structural setup and enable for menu controller
/////////////////////////////////////////////////////////
//Set the background color to white to hide hidden views
[self.view setBackgroundColor:[UIColor whiteColor]];
//Add swipe gesture recognizer to menu
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(menuButtonWasPressed)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRecognizer];
//////////////////////
//Setup and add dayBar
//////////////////////
NSArray *cartArray = [self.cart getCartArray];
// if ([cartArray count]<2) {
// [self displayEmptyCartView];
// }
//Initial configuration and data needs like array of day title strings
self.dayBar = [[UIView alloc]initWithFrame:CGRectMake(0, TOPBAR_HEIGHT, SCREEN_WIDTH, DAYBAR_HEIGHT)];
[self.dayBar setBackgroundColor:[UIColor whiteColor]];
NSArray *dayInitials = [NSArray arrayWithObjects:@"M", @"T", @"W",@"TH",@"F", nil];
//1px line at bottom of the bar
// UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, TOPBAR_HEIGHT+DAYBAR_HEIGHT, SCREEN_WIDTH, 1)];
// [line setBackgroundColor:[UIColor grayColor]];
// [self.view addSubview:line];
//Set up day buttons
for (int j=0; j<5; j++) {
//Initialize day button
UIButton *dayButton = [[UIButton alloc]initWithFrame:CGRectMake(15+j*DAY_WIDTH, 0, DAY_WIDTH, DAYBAR_HEIGHT)];
[dayButton setBackgroundColor:[UIColor whiteColor]];
dayButton.tag = j;
[dayButton addTarget:self action:@selector(dayButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
//Day label for button
NSString *dayInitial = [dayInitials objectAtIndex:j];
UILabel *dayInitialLabel = [[UILabel alloc] initWithFrame:CGRectMake(DAY_WIDTH/2-8, 0, DAY_WIDTH, DAYBAR_HEIGHT)];//8 is an offset to visually center text
[dayInitialLabel setText:dayInitial];
[dayInitialLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:17]];
//Add day label to day button and daybutton to daybar
[dayButton addSubview:dayInitialLabel];
[self.dayBar addSubview:dayButton];
}
[self.view addSubview:self.dayBar];
// [self loadData];
// NSArray *cartArray = [self.cart getCartArray];
for (int i = 0; i<[cartArray count]; i++) {
[self compileCourseInfo:cartArray[i]];
//Test data
float startTime = 9.0+i*2;
float duration = 1.0;
float position = startTime - 9;
float day = 0+i;
//End of test/example data
// if (day == 0||day==2||day==4) {
//
// for (int j = 0; j<4; j++) {
// if (j== 0||j==2||j==4){
// UIButton *courseButton = [[UIButton alloc] initWithFrame:CGRectMake(day*DAY_WIDTH, position*HOUR_HEIGHT+TOPBAR_HEIGHT+DAYBAR_HEIGHT, DAY_WIDTH, HOUR_HEIGHT*duration)];
// courseButton.tag = i;
// [courseButton addTarget:self action:@selector(courseButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
// [courseButton setBackgroundColor:[UIColor grayColor]];
// [self.view addSubview:courseButton];
// }
// }
// }
}
//Create and display timebar
int hour_font_size = 12;
UIView *timeBar = [[UIView alloc] initWithFrame:CGRectMake(0, DAYBAR_HEIGHT+TOPBAR_HEIGHT, 15, SCREEN_HEIGHT-34)];
for (int i = 0; i<HOURS_TO_SHOW; i++) {
UILabel *hourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, i*HOUR_HEIGHT, timeBar.frame.size.width, hour_font_size+2)];
int rawTime = i+8;
int modTime = rawTime % 12;
if (rawTime == 12) {
modTime = 12;
}
[hourLabel setText:[NSString stringWithFormat:@"%i",modTime]];
[hourLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:hour_font_size]];
[timeBar addSubview:hourLabel];
}
[self.view addSubview:timeBar];
//Navbar stuff
//Setting the title but in the future this will be dynamic based on chosen cart
self.navigationItem.title = @"Da Best Cart";
self.navigationItem.title = self.cart.title;
NSLog(@"I'm here");
//If we want to customize we'd just make this a normal button with a normal cgrect frame and add a button background
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStylePlain target:self action:@selector(addButtonWasPressed)];
self.navigationItem.rightBarButtonItem = addButton;
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:@"Carts" style:UIBarButtonItemStylePlain target:self action:@selector(menuButtonWasPressed)];
self.navigationItem.leftBarButtonItem = menuButton;
////////////////////////////////
//Now for populating the calendar
///////////////////////////////
// if (self.cart) {
// NSArray *cartArray = [self.cart getCartArray];
if ([cartArray count]==0) {
[self displayEmptyCartView];
}
else{
[emptyCartView setHidden:YES];
for (int i = 0; i<[cartArray count]; i++) {
[self compileCourseInfo:cartArray[i]];
[self addToCalendarView:cartArray[i]];
}
}
}
//And this is a place for post view load stuff anything happening on the main view is cool to put here usually
- (void)viewDidLoad
{
[super viewDidLoad];
}
//
//-(void) setCart:(Cart *)cart{
// self.cart = cart;
//}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)addButtonWasPressed{
DepartmentTableViewController *addView = [[DepartmentTableViewController alloc] init];
addView.cart = self.cart;
[self.navigationController pushViewController:addView animated:YES];
}
-(void) menuButtonWasPressed{
NSLog(@"Menubutton was tapped real nice");
[self.sideMenuViewController openMenuAnimated:YES completion:nil];
//Will present side menubar view here
}
//////////////////////////////////////////////////////////////////////
#pragma courseButtonWasPressed
//Takes a unique CCCoursebutton
//Passes all necessary course into to courseViewController and Pushes courseViewController
//////////////////////////////////////////////////////////////////////
-(void) courseButtonWasPressed:(CCCourseButton*)sender{
if (sender.conflict) {
NSLog(@"Conflict");
// ConflictViewController *alert = [[ConflictViewController alloc] init];
// alert.conflictArray = sender.conflictArray;
// alert.cart = self.cart;
// [self.view addSubview:alert.view];
_buttonPane = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/20,self.view.frame.size.height*9/64, self.view.frame.size.width*18/20,buttonPaneHeight)];
UIColor *color = [UIColor grayColor];
_buttonPane.backgroundColor = color;
_buttonPane.alpha = .95f;
[self.view addSubview:_buttonPane];
UIFont *buttonFont = [UIFont fontWithName:@"Helvetica Light" size:24.0];
UILabel *bookListLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, offset, buttonPaneWidth, labelHeight)];
bookListLabel.text = @"Course Conflict";
UIColor *timeLabelFontColor = [UIColor whiteColor];
bookListLabel.textAlignment = UITextAlignmentCenter;
bookListLabel.textColor = timeLabelFontColor;
bookListLabel.font = buttonFont;
[_buttonPane addSubview: bookListLabel];
UIFont *buttonFont2 = [UIFont fontWithName:@"Helvetica Light" size:20.0];
int buttonHeight = 60;
int buttonWidth = buttonPaneWidth;
for (int i = 0; i<[sender.conflictArray count]; i++) {
Course *course = sender.conflictArray[i];
Department *department = course.department;
CCCourseButton *courseButton = [[CCCourseButton alloc] initWithFrame:CGRectMake(0, offset + 50+buttonHeight*i, buttonWidth, buttonHeight)];
[courseButton setBackgroundColor:department.color];
courseButton.course = course;
[courseButton setTitle:course.title forState:UIControlStateNormal];
[courseButton addTarget:self action:@selector(alertCourseButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
[_buttonPane addSubview:courseButton];
[_buttonPane bringSubviewToFront:courseButton];
}
UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(offset, labelHeight+textViewHeight+3*offset, textViewWidth, cancelHeight)];
[cancel addTarget:self action:@selector(cancelButtonWasPressed) forControlEvents:UIControlEventTouchUpInside];
cancel.layer.borderColor = [[UIColor whiteColor] CGColor];
cancel.layer.borderWidth = 2;
cancel.layer.backgroundColor = [[UIColor grayColor] CGColor];
[[cancel titleLabel] setFont:buttonFont];
[cancel setTitle:@"Cancel" forState: UIControlStateNormal];
[_buttonPane addSubview:cancel];
}
else{
Course *course = sender.course;
//Then instantiate the course detail view and set the title and the correct course
//Anything else we need to pass can go here as well
CourseViewController *courseView = [[CourseViewController alloc] init];
courseView.courseTitle = course.title;
courseView.course = course;
courseView.currentCart = self.cart;
NSString *abbrev = course.department.abbrev;
NSString *abbrevNum = [abbrev stringByAppendingString:course.number];
courseView.navigationItem.title = abbrevNum;
courseView.abbrevNum = abbrevNum;
courseView.departmentColor = course.department.color;
[self.navigationController pushViewController:courseView animated:YES];
}
}
//////////////////////////////////////////////////////////////////////
#pragma dayButtonWasPressed
//Takes a numbe day of week 0-4 (sender.tag)
//Displays single day calendar and animates initial to full day name
//////////////////////////////////////////////////////////////////////
//-(void)dayButtonWasPressed:(UIButton*)sender{
// NSLog(@"dayButtonWasPressed");
//
// //Hide all other buttons
// UIView *whiteOut = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, DAYBAR_HEIGHT)];
// [whiteOut setBackgroundColor:[UIColor whiteColor]];
// [self.dayBar addSubview:whiteOut];
// [self.dayBar bringSubviewToFront:whiteOut];
// [self.dayBar bringSubviewToFront:sender];
//
// //Animate movement of day initial to left of dayBar
// [UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{[sender setFrame:CGRectMake(0, 0, SCREEN_WIDTH, DAYBAR_HEIGHT)];} completion:^(BOOL finished){
// //Complete day title here based on day array yet to be constructed
// UILabel *fullDayLabel = [[UILabel alloc] init];
// [fullDayLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:17]];
// float offset = 0;
// switch (sender.tag) {
// case 0:
// offset = 6;
// [fullDayLabel setText:@"ONDAY"];
// break;
// case 1:
// offset = 1;
// [fullDayLabel setText:@"UESDAY"];
// break;
// case 2:
// offset = 7;
// [fullDayLabel setText:@"EDNESDAY"];
// break;
// case 3:
// offset = 13;
// [fullDayLabel setText:@"URSDAY"];
// break;
// case 4:
// offset = 2;
// [fullDayLabel setText:@"RIDAY"];
// break;
//
// default:
// break;
// }
//
// [fullDayLabel setFrame:CGRectMake(DAY_WIDTH/2+offset, 0, SCREEN_WIDTH, DAYBAR_HEIGHT)];
// [sender addSubview:fullDayLabel];
//
// }];
//
//#warning Still need to add back button and get rid of add and menu buttons in nav bar
//
//
//}
-(void)loadData{
// NSMutableArray course
NSMutableArray *temp = [self.cart getCartArray];
for (int i= 0; i<temp.count; i++) {
Course *course = temp[i];
[self.course_title_array addObject:course.title];
}
}
-(NSInteger)numberToTime{
return 0;
}
-(void)compileCourseInfo:(Course *) course{
NSString *timeString = course.time;
NSLog(course.time);
if ([timeString hasPrefix:@"MWF"]) {
day = 0;//Set day to MWF
NSString *timeStringCopy = [NSString stringWithString:timeString];
NSString *startTimeStringCopy = [NSString stringWithString:timeString];
NSString *endTimeStringCopy = [NSString stringWithString:timeString];
// timeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(4, 7)];
NSLog(@"Monday/Wednesday/Friday");
NSRange start = [timeStringCopy rangeOfString:@" "];
NSRange end = [timeStringCopy rangeOfString:@"-"];
if (start.location != NSNotFound && end.location != NSNotFound && end.location > start.location) {
startTimeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(start.location+1, end.location-(start.location+1))];
}
startTimeDouble = [startTimeStringCopy doubleValue];
NSLog(@"%li",(long)startTimeDouble);
NSRange newstart = [timeStringCopy rangeOfString:@"-"];
NSRange newend = [timeStringCopy rangeOfString:@"}"];
if (newstart.location != NSNotFound && newend.location != NSNotFound && newend.location > newstart.location) {
endTimeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(newstart.location+1, newend.location-(newstart.location+1))];
}
endTimeDouble = [endTimeStringCopy doubleValue];
NSLog(@"%li",(long)endTimeDouble);
}
else if([timeString hasPrefix:@"TR"]){
day = 1;
NSString *timeStringCopy = [NSString stringWithString:timeString];
NSString *startTimeStringCopy = [NSString stringWithString:timeString];
NSString *endTimeStringCopy = [NSString stringWithString:timeString];
// timeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(4, 7)];
NSLog(@"Tuesday/Thursday");
NSRange start = [timeStringCopy rangeOfString:@" "];
NSRange end = [timeStringCopy rangeOfString:@"-"];
if (start.location != NSNotFound && end.location != NSNotFound && end.location > start.location) {
startTimeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(start.location+1, end.location-(start.location+1))];
}
startTimeDouble = [startTimeStringCopy doubleValue];
NSLog(@"%li",(long)startTimeDouble);
NSRange newstart = [timeStringCopy rangeOfString:@"-"];
NSRange newend = [timeStringCopy rangeOfString:@"}"];
if (newstart.location != NSNotFound && newend.location != NSNotFound && newend.location > newstart.location) {
endTimeStringCopy = [timeStringCopy substringWithRange:NSMakeRange(newstart.location+1, newend.location-(newstart.location+1))];
}
endTimeDouble = [endTimeStringCopy doubleValue];
NSLog(@"%li",(long)endTimeDouble);
NSLog(@"###################END%li", (long)startTimeDouble);
NSLog(@"###################START%li", (long)endTimeDouble);
}
}
-(void)addToCalendarView:(Course *) course{
//Check for course conflict.. this is pretty primitive only matches exact time matches in future need to store actual start and end time with each course to compare for overlaps.. could run through array and parse but think we should add actual time numbers to course objects. Right now core data is optimized for display with strings.. thats silly.
//If we changed the times to 24 hour clock we could just mod it everywhere else
if (startTimeDouble < 8) {//Afternoon courses
startTimeDouble = startTimeDouble +12;
}
if (endTimeDouble < 8) {//Afternoon courses
endTimeDouble = endTimeDouble +12;
}
double duration = endTimeDouble - startTimeDouble;
double startTime = startTimeDouble-8;//Start 8am classes at position 0
UIColor *lightGrey= [UIColor colorWithRed:0.925 green:0.941 blue:0.945 alpha:1]; /*#ecf0f1*/
if (day == 0) {
for (int i = 0; i<5; i++) {
if (i == 0 || i==2 || i==4) {
CCCourseButton *courseButton = [[CCCourseButton alloc] initWithFrame:CGRectMake(15+i*DAY_WIDTH, startTime*HOUR_HEIGHT+TOPBAR_HEIGHT+DAYBAR_HEIGHT, DAY_WIDTH, HOUR_HEIGHT*duration)];
[courseButton addTarget:self action:@selector(courseButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
[courseButton setBackgroundColor:lightGrey];
//Create top color bumper
[self addTitleToView:course withCourseButton:courseButton];
[self.view addSubview:courseButton];
}
}
}
else if (day == 1) {
for (int i = 0; i<5; i++) {
if (i == 1 || i==3) {
CCCourseButton *courseButton = [[CCCourseButton alloc] initWithFrame:CGRectMake(15+i*DAY_WIDTH, startTime*HOUR_HEIGHT+TOPBAR_HEIGHT+DAYBAR_HEIGHT, DAY_WIDTH, HOUR_HEIGHT*duration)];
[courseButton addTarget:self action:@selector(courseButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
[courseButton setBackgroundColor:lightGrey];
//Create top color bumper
[self addTitleToView:course withCourseButton:courseButton];
[self.view addSubview:courseButton];
}
}
}
}
-(void)addTitleToView:(Course *)course withCourseButton:(CCCourseButton *)courseButton{
courseButton.course = course;//Set course property of course button
courseButton.conflict = NO;
courseButton.conflictArray = [[NSMutableArray alloc] init];;
NSArray *cartArray = [self.cart getCartArray];
for (int i = 0; i<[cartArray count]; i++) {
Course *compCourse = cartArray[i];
if ([compCourse.time isEqualToString:course.time]) {
[courseButton.conflictArray addObject:compCourse];
}
}
if ([courseButton.conflictArray count]>1) {
courseButton.conflict = YES;
}
UIColor *darkGrey = [UIColor colorWithRed:0.498 green:0.549 blue:0.553 alpha:1]; /*#7f8c8d*/
//Add course data to view
//Start with title
int small_font_size = 11;
if (courseButton.conflict) {
for (int i = 0; i<[courseButton.conflictArray count]; i++) {
Course *c = courseButton.conflictArray[i];
NSString *abbrev = c.department.abbrev;
NSString *abbrevNum = [abbrev stringByAppendingString:c.number];
UIColor *deptColor = c.department.color;
UILabel *deptAbbrevLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 13+small_font_size*i, DAY_WIDTH, small_font_size+2)];
[deptAbbrevLabel setText:abbrevNum];
[deptAbbrevLabel setTextColor:darkGrey];
[deptAbbrevLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:small_font_size]];
[courseButton addSubview:deptAbbrevLabel];
int color_bumper_width = DAY_WIDTH/[courseButton.conflictArray count];
UIView *colorBumper = [[UIView alloc] initWithFrame:CGRectMake(color_bumper_width*i, 0, color_bumper_width, 10)];
[colorBumper setBackgroundColor:deptColor];
if (![self.cart isRegistered:c]) {
[colorBumper setAlpha:.4];
UIView *crossBumper = [[UIView alloc] initWithFrame:CGRectMake(color_bumper_width*i, 0, color_bumper_width, 10)];
UIImage *image = [UIImage imageNamed:@"lines.png"];
crossBumper.backgroundColor = [UIColor colorWithPatternImage:image];
[crossBumper setAlpha:.6];
[courseButton addSubview:crossBumper];
}
//Primitive cross hatch
// for (int i = 0; i<11; i++) {
// UIView *colorBumperLineR = [[UIView alloc] initWithFrame:CGRectMake(i*5, 5, 12, 1)];
// [colorBumperLineR setBackgroundColor:deptColor];
//
// colorBumperLineR.transform = CGAffineTransformIdentity;
//
// colorBumperLineR.transform = CGAffineTransformMakeRotation(degreesToRadians(45));
// colorBumperLineR.transform = CGAffineTransformRotate(colorBumperLineR.transform, degreesToRadians(90));
// [courseButton addSubview:colorBumperLineR];
//
// UIView *colorBumperLineL = [[UIView alloc] initWithFrame:CGRectMake(i*5, 5, 12, 1)];
// [colorBumperLineL setBackgroundColor:deptColor];
//
// colorBumperLineL.transform = CGAffineTransformIdentity;
//
// colorBumperLineL.transform = CGAffineTransformMakeRotation(degreesToRadians(135));
// colorBumperLineL.transform = CGAffineTransformRotate(colorBumperLineL.transform, degreesToRadians(90));
// [courseButton addSubview:colorBumperLineL];
// }
[courseButton addSubview:colorBumper];
}
}
else{
NSString *abbrev = course.department.abbrev;
NSString *abbrevNum = course.number;
UILabel *deptAbbrevLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 13, DAY_WIDTH, 15)];
[deptAbbrevLabel setText:abbrev];
[deptAbbrevLabel setTextColor:darkGrey];
[deptAbbrevLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:16]];
[courseButton addSubview:deptAbbrevLabel];
UILabel *courseNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(2, 28, DAY_WIDTH, 15)];
[courseNumberLabel setText:abbrevNum];
[courseNumberLabel setTextColor:darkGrey];
[courseNumberLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:12]];
[courseButton addSubview:courseNumberLabel];
UIView *colorBumper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DAY_WIDTH, 10)];
UIColor *deptColor = course.department.color;
[colorBumper setBackgroundColor:deptColor];
if (![self.cart isRegistered:course]) {
[colorBumper setAlpha:.4];
UIView *crossBumper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DAY_WIDTH, 10)];
UIImage *image = [UIImage imageNamed:@"lines.png"];
crossBumper.backgroundColor = [UIColor colorWithPatternImage:image];
[crossBumper setAlpha:.6];
[courseButton addSubview:crossBumper];
}
//Primitive cross hatch
// for (int i = 0; i<11; i++) {
// UIView *colorBumperLineR = [[UIView alloc] initWithFrame:CGRectMake(i*5, 5, 12, 1)];
// [colorBumperLineR setBackgroundColor:deptColor];
//
// colorBumperLineR.transform = CGAffineTransformIdentity;
//
// colorBumperLineR.transform = CGAffineTransformMakeRotation(degreesToRadians(45));
// colorBumperLineR.transform = CGAffineTransformRotate(colorBumperLineR.transform, degreesToRadians(90));
// [courseButton addSubview:colorBumperLineR];
//
// UIView *colorBumperLineL = [[UIView alloc] initWithFrame:CGRectMake(i*5, 5, 12, 1)];
// [colorBumperLineL setBackgroundColor:deptColor];
//
// colorBumperLineL.transform = CGAffineTransformIdentity;
//
// colorBumperLineL.transform = CGAffineTransformMakeRotation(degreesToRadians(135));
// colorBumperLineL.transform = CGAffineTransformRotate(colorBumperLineL.transform, degreesToRadians(90));
// [courseButton addSubview:colorBumperLineL];
// }
[courseButton addSubview:colorBumper];
}
}
-(void)displayEmptyCartView{
emptyCartView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[emptyCartView setBackgroundColor:[UIColor whiteColor]];
UIColor *silver = [UIColor colorWithRed:0.741 green:0.765 blue:0.78 alpha:1]; /*#bdc3c7*/
//Set header and add it
UILabel *emptyHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 50)];
[emptyHeaderLabel setTextAlignment:NSTextAlignmentCenter];
[emptyHeaderLabel setText:@"Empty Cart"];
[emptyHeaderLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:25]];
[emptyHeaderLabel setTextColor:silver];
[emptyCartView addSubview:emptyHeaderLabel];
[emptyCartView bringSubviewToFront:emptyHeaderLabel];
//Set message and add it
UILabel *emptyMessageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, 30)];
[emptyMessageLabel setTextAlignment:NSTextAlignmentCenter];
[emptyMessageLabel setText:@"Courses you add to the cart will show up here"];
[emptyMessageLabel setFont:[UIFont fontWithName:@"Helvetica Light" size:15]];
[emptyMessageLabel setTextColor:silver];
[emptyCartView addSubview:emptyMessageLabel];
UIImage *books = [UIImage imageNamed:@"book_stack"];
UIImageView *booksImageView = [[UIImageView alloc] initWithFrame:CGRectMake(90, 250, books.size.width, books.size.height)];
[booksImageView setImage:books];
[emptyCartView addSubview:booksImageView];
[self.view addSubview:emptyCartView];
// [self.view bringSubviewToFront:emptyCartView];
}
-(void) showBlur{
[UIView animateWithDuration:.3 animations: ^{
self.view.alpha=1;
}];
}
-(void)cancelButtonWasPressed{
for (UIView *subView in self.view.subviews) {
[subView removeFromSuperview];
}
for (UIView *subView in self.view.superview.subviews) {
subView.userInteractionEnabled = YES;
}
[self.view removeFromSuperview];
}
-(void)alertCourseButtonWasPressed:(CCCourseButton *) sender{
Course *course = sender.course;
//Then instantiate the course detail view and set the title and the correct course
//Anything else we need to pass can go here as well
CourseViewController *courseView = [[CourseViewController alloc] init];
courseView.courseTitle = course.title;
courseView.course = course;
courseView.currentCart = self.cart;
NSString *abbrev = course.department.abbrev;
NSString *abbrevNum = [abbrev stringByAppendingString:course.number];
courseView.navigationItem.title = abbrevNum;
courseView.abbrevNum = abbrevNum;
courseView.departmentColor = course.department.color;
[self.navigationController pushViewController:courseView animated:YES];
}
@end