-
Notifications
You must be signed in to change notification settings - Fork 0
/
PLSelectMainsViewController.m
160 lines (129 loc) · 4.88 KB
/
PLSelectMainsViewController.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
//
// PLSelectMainsViewController.m
// Plate
//
// Created by emileleon on 11/30/13.
// Copyright (c) 2013 Plate SF. All rights reserved.
//
#import "PLSelectMainsViewController.h"
#import "PLSelectSidesViewController.h"
#import "PLPlateStore.h"
#import "PLMenu.h"
#import "PLBasketStore.h"
#import "PLPlate.h"
#import "Colours.h"
#import "PLPlateTypeSize.h"
#import "PLPlateSize.h"
@interface PLSelectMainsViewController ()
@end
@implementation PLSelectMainsViewController
@synthesize sidesController;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"];
}
cell.layer.borderWidth = 1.0f;
cell.layer.borderColor = [[UIColor blackColor] CGColor];
cell.layer.masksToBounds = YES;
cell.layer.cornerRadius = 12.0f;
cell.layer.backgroundColor = [[UIColor grayColor] CGColor];
cell.textLabel.textColor = [UIColor moneyGreenColor];
[[cell textLabel] setText:[[mains objectAtIndex:[indexPath row]] name]];
if ((PLMenuItem *)[mains objectAtIndex:[indexPath row]] == [[[PLBasketStore sharedStore] plateBuilder] main]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
-(float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[PLBasketStore sharedStore] setPlateMain:[mains objectAtIndex:[indexPath row]]];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mains count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)fetchMains
{
UIView *currentTitleView = [[self navigationItem] titleView];
UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[[self navigationItem] setTitleView:aiView];
[aiView startAnimating];
__weak PLSelectMainsViewController *weakSelf = self;
PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder];
[[PLPlateStore sharedStore] getPlateMenu:[plate plateSize] plateType:[plate plateTypeSize] forBlock:^(PLMenu *menuResult, NSError *err) {
[[weakSelf navigationItem] setTitleView:currentTitleView];
if (!err) {
mains = [menuResult mains];
[[weakSelf tableMains] reloadData];
} else {
UIAlertView *av =[[UIAlertView alloc]
initWithTitle:@"Error"
message:[err localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
}
}];
}
#pragma INITIALIZERS
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableMains reloadData];
[super displayBasketInNavBar];
UIBarButtonItem *statusButton = [[self toolbarItems] objectAtIndex:0];
[statusButton setTitle:@"Select 1 Main"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self setTitle:@"Mains"];
[[self tableMains] setTableHeaderView:nil];
[self fetchMains];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionContinue:(id)sender {
PLPlate *plate = [[PLBasketStore sharedStore] plateBuilder];
if ([plate main] == nil) {
NSString *msg = [NSString stringWithFormat:@"Select a Main"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:msg
message:@"Please select a main entree"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
} else {
self.sidesController = [[PLSelectSidesViewController alloc] init];
[[self navigationController] pushViewController:[self sidesController] animated:YES];
}
}
@end