-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPAImageDisplayAcoustic.m
More file actions
297 lines (230 loc) · 10.8 KB
/
PPAImageDisplayAcoustic.m
File metadata and controls
297 lines (230 loc) · 10.8 KB
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
//
// PPAImageDisplayAcoustic.m
// Personal Project App
//
// Created by Albert Kragl on 1/8/2014.
// Copyright (c) 2014 Albert Kragl. All rights reserved.
//
#import "PPAImageDisplayAcoustic.h"
#import "PPADecisionEngine.h"
#import "PPASolutions.h"
#import "PPAHomeScreen.h"
@interface PPAImageDisplayAcoustic ()
@end
@implementation PPAImageDisplayAcoustic
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
PPADecisionEngine *decisionEngine = [[PPADecisionEngine alloc] init];
PPASolutions *solutions = [[PPASolutions alloc] init];
self.solutions123 = [decisionEngine getSolutions];
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
// Finds standard screen size then multiplies by 2 to find retina size.
self.sizeSuffix = [NSString stringWithFormat:@" %1.0fx%1.0f", screenWidth * 2, screenHeight * 2];
// TBD write code to make OK button go back to home screen/gear list
if ([[self.solutions123 objectAtIndex:0] isEqualToString:@"-1"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"No solution found! Please double check your choices."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else {
//NSLog([self.solutions123 objectAtIndex:0]);
//NSLog([self.solutions123 objectAtIndex:1]);
//NSLog([self.solutions123 objectAtIndex:2]);
self.solution1 = [solutions getSolution:[self.solutions123 objectAtIndex:0]]; // First object = 0
self.totalSolution = [[NSMutableArray alloc] init];
solutions123Count = [self.solutions123 count];
solution1Count = [self.solution1 count];
[self.totalSolution addObjectsFromArray:self.solution1];
if ([[self.solutions123 objectAtIndex:1] isEqualToString:@"-1"]) { // if statement for solution 2 = @"-1" add an else
solution2Count = 0;
}
else {
self.solution2 = [solutions getSolution:[self.solutions123 objectAtIndex:1]];
solution2Count = [self.solution2 count];
[self.totalSolution addObjectsFromArray:self.solution2];
}
if ([[self.solutions123 objectAtIndex:2] isEqualToString:@"-1"]) { // if statement for solution 3 = @"-1"
solution3Count = 0;
}
else {
self.solution3 = [solutions getSolution:[self.solutions123 objectAtIndex:2]];
solution3Count = [self.solution3 count];
[self.totalSolution addObjectsFromArray:self.solution3];
}
totalSolutionCount = [self.totalSolution count];
totalSolutionIndex = 0; // Tells where the user currently is, number/value can change
NSString *fullImageName = [NSString stringWithFormat:@"%@%@%@", [self.solution1 objectAtIndex:0], self.sizeSuffix, @".png"];
//NSLog(fullImageName);
UIImage *img = [UIImage imageNamed:fullImageName];
[imageview setImage:img];
[leftButton setTitle:@"Home" forState:UIControlStateNormal];
if (totalSolutionCount == 1) {
rightButton.hidden = TRUE;
}
else if (totalSolutionCount > 1 && solution1Count > 1) {
[rightButton setTitle:@"Next" forState:UIControlStateNormal];
}
else {
[rightButton setTitle:@"2nd Best" forState:UIControlStateNormal];
}
[navBarTitle setTitle:@"Best Solution"];
}
// ERROR MESSAGES
/*
if ([[plistData objectAtIndex:1] isEqualToString:@"1"] &&
[[plistData objectAtIndex:3] isEqualToString:@"0"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note"
message:@"Computer and software type do not match."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
if ([[plistData objectAtIndex:1] isEqualToString:@"0"] &&
[[plistData objectAtIndex:3] isEqualToString:@"1"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note"
message:@"Computer and software type do not match."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
if () {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please select at least one piece of equipment."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
*/
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark alert dialogue handling method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PPAHomeScreen *homeScreen = (PPAHomeScreen *)[storyboard instantiateViewControllerWithIdentifier:@"Home Screen"];
[self presentViewController:homeScreen animated:YES completion:nil];
}
#pragma mark button handling methods
-(IBAction)previousSolutionImage {
if (totalSolutionIndex == 0) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
PPAHomeScreen *homeScreen = (PPAHomeScreen *)[storyboard instantiateViewControllerWithIdentifier:@"Home Screen"];
[self presentViewController:homeScreen animated:YES completion:nil];
}
if (totalSolutionIndex > 0) { // if index is not at very first picture, do this:
totalSolutionIndex--;
NSString *fullImageName = [NSString stringWithFormat:@"%@%@%@", [self.totalSolution objectAtIndex:totalSolutionIndex], self.sizeSuffix, @".png"];
//NSLog(fullImageName);
UIImage *img = [UIImage imageNamed:fullImageName];
[imageview setImage:img];
}
if (totalSolutionIndex != totalSolutionCount - 1) {
rightButton.hidden = FALSE;
}
if (totalSolutionIndex == 0) {
[leftButton setTitle:@"Home" forState:UIControlStateNormal];
}
// need if for left button special text 1 (back to first solution)
if (totalSolutionIndex == solution1Count) {
[leftButton setTitle: @"Best" forState:UIControlStateNormal];
}
else if (totalSolutionIndex == solution1Count + solution2Count) {
[leftButton setTitle: @"2nd Best" forState:UIControlStateNormal];
}
else if (totalSolutionIndex == 0) {
[leftButton setTitle:@"Home" forState:UIControlStateNormal];
}
else {
[leftButton setTitle: @"Previous" forState:UIControlStateNormal];
}
// need 1-2 ifs for right button text
if (totalSolutionIndex == solution1Count - 1) {
[rightButton setTitle: @"2nd Best" forState:UIControlStateNormal];
}
else if (totalSolutionIndex == solution1Count + solution2Count - 1) {
[rightButton setTitle: @"3rd Best" forState:UIControlStateNormal];
}
else {
[rightButton setTitle: @"Next" forState:UIControlStateNormal];
}
// Solution Title
if (totalSolutionIndex >= 0 && totalSolutionIndex <= solution1Count - 1) {
[navBarTitle setTitle:@"Best Solution"];
}
else if (totalSolutionIndex >= solution1Count && totalSolutionIndex <= solution1Count + solution2Count - 1) {
[navBarTitle setTitle:@"2nd Solution"];
}
else if (totalSolutionIndex >= solution1Count + solution2Count && totalSolutionIndex <= totalSolutionCount - 1) {
[navBarTitle setTitle:@"3rd Solution"];
}
}
-(IBAction)nextSolutionImage { // TBD Need to change IBAction names
if (totalSolutionIndex < totalSolutionCount - 1) { // if index is not at the last picture, do this:
totalSolutionIndex++;
NSString *fullImageName = [NSString stringWithFormat:@"%@%@%@", [self.totalSolution objectAtIndex:totalSolutionIndex], self.sizeSuffix, @".png"];
NSLog(fullImageName);
UIImage *img = [UIImage imageNamed:fullImageName];
/* [UIView transitionWithView:imageview
duration:0.5f
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
imageview.image = img;
} completion:nil]; */
[imageview setImage:img];
rightButton.hidden = FALSE;
}
if (totalSolutionIndex == totalSolutionCount - 1) {
rightButton.hidden = TRUE;
}
if (totalSolutionIndex == solution1Count - 1) {
[rightButton setTitle: @"2nd Best" forState:UIControlStateNormal];
}
else if (totalSolutionIndex == solution1Count + solution2Count - 1) {
[rightButton setTitle: @"3rd Best" forState:UIControlStateNormal];
}
else {
[rightButton setTitle: @"Next" forState:UIControlStateNormal];
}
if (totalSolutionIndex == solution1Count) {
[leftButton setTitle:@"Best" forState:UIControlStateNormal];
}
else if (totalSolutionIndex == solution1Count + solution2Count) {
[leftButton setTitle:@"2nd Best" forState:UIControlStateNormal];
}
else {
[leftButton setTitle:@"Previous" forState:UIControlStateNormal];
}
// Solution Title
if (totalSolutionIndex >= 0 && totalSolutionIndex <= solution1Count - 1) {
[navBarTitle setTitle:@"Best Solution"];
}
else if (totalSolutionIndex >= solution1Count && totalSolutionIndex <= solution1Count + solution2Count - 1) {
[navBarTitle setTitle:@"2nd Solution"];
}
else if (totalSolutionIndex >= solution1Count + solution2Count && totalSolutionIndex <= totalSolutionCount - 1) {
[navBarTitle setTitle:@"3rd Solution"];
}
}
@end