This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
/
MLWSessionSurveyViewController.m
212 lines (179 loc) · 7.08 KB
/
MLWSessionSurveyViewController.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
//
// MLWSessionSurveyViewController.m
// MarkLogic World
//
// Created by Ryan Grimm on 4/6/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MLWSessionSurveyViewController.h"
#import "MLWSessionSurvey.h"
#import "UITableView+helpers.h"
@interface MLWSessionSurveyViewController ()
@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) MLWSession *session;
@property (nonatomic, retain) UISegmentedControl *speakerTabs;
@property (nonatomic, retain) UISegmentedControl *qualityTabs;
@property (nonatomic, retain) UITextView *comments;
- (void)submit:(UIBarButtonItem *)sender;
@end
@implementation MLWSessionSurveyViewController
@synthesize loadingView = _loadingView;
@synthesize tableView = _tableView;
@synthesize session = _session;
@synthesize speakerTabs = _speakerTabs;
@synthesize qualityTabs = _qualityTabs;
@synthesize comments = _comments;
- (id)initWithSession:(MLWSession *)session {
self = [super init];
if(self) {
self.session = session;
self.navigationItem.title = session.title;
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStyleDone target:self action:@selector(submit:)] autorelease];
}
return self;
}
- (void)loadView {
self.view = [[[UIView alloc] init] autorelease];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped] autorelease];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView applyBackground];
[self.view addSubview:self.tableView];
self.speakerTabs = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Poor", @"Fair", @"Avg", @"Good", @"Great", nil]] autorelease];
self.speakerTabs.tintColor = [UIColor colorWithWhite:0.5 alpha:1];
self.speakerTabs.segmentedControlStyle = UISegmentedControlStyleBar;
self.qualityTabs = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Poor", @"Fair", @"Avg", @"Good", @"Great", nil]] autorelease];
self.qualityTabs.tintColor = [UIColor colorWithWhite:0.5 alpha:1];
self.qualityTabs.segmentedControlStyle = UISegmentedControlStyleBar;
self.comments = [[[UITextView alloc] init] autorelease];
self.loadingView = [[[UIView alloc] initWithFrame:self.view.frame] autorelease];
self.loadingView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.loadingView.backgroundColor = [UIColor blackColor];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = self.loadingView.center;
spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[spinner startAnimating];
[self.loadingView addSubview:spinner];
[spinner release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *) tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger) section {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if(section == 0) {
return @"Effectiveness of speaker";
}
if(section == 1) {
return @"Quality of content";
}
if(section == 2) {
return @"Comments";
}
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if(sectionTitle == nil) {
return nil;
}
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 6, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0, 2.0);
label.font = [UIFont boldSystemFontOfSize:16];
label.text = sectionTitle;
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];
[view addSubview:label];
[label release];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 2) {
return 200;
}
return 44;
}
- (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect frame = cell.contentView.bounds;
frame.size.height = frame.size.height + 2;
if(indexPath.section == 0) {
self.speakerTabs.frame = frame;
[cell.contentView addSubview:self.speakerTabs];
}
else if(indexPath.section == 1) {
self.qualityTabs.frame = frame;
[cell.contentView addSubview:self.qualityTabs];
}
else if(indexPath.section == 2) {
self.comments.frame = CGRectInset(frame, 5, 5);
[cell.contentView addSubview:self.comments];
}
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
- (void)submit:(UIBarButtonItem *)sender {
self.loadingView.frame = self.view.frame;
[self.view addSubview:self.loadingView];
MLWSessionSurvey *survey = [[MLWSessionSurvey alloc] initWithSession:self.session];
if(self.speakerTabs.selectedSegmentIndex != UISegmentedControlNoSegment) {
survey.speakerRating = self.speakerTabs.selectedSegmentIndex + 1;
}
if(self.qualityTabs.selectedSegmentIndex != UISegmentedControlNoSegment) {
survey.contentRating = self.qualityTabs.selectedSegmentIndex + 1;
}
survey.comments = self.comments.text;
[survey submit:^(NSError *error) {
if(error == nil) {
[self.navigationController popViewControllerAnimated:YES];
}
}];
[survey release];
}
- (void)viewDidUnload {
self.loadingView = nil;
self.view = nil;
self.tableView = nil;
self.speakerTabs = nil;
self.qualityTabs = nil;
self.comments = nil;
[super viewDidUnload];
}
- (void)dealloc {
self.loadingView = nil;
self.view = nil;
self.tableView = nil;
self.session = nil;
self.speakerTabs = nil;
self.qualityTabs = nil;
self.comments = nil;
[super dealloc];
}
@end