Nextrek
@ 570
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 |
// // RouteQuestionsVC.m // SafariArte // // Created by Nextrek on 09/07/15. // Copyright (c) 2015 Nextrek. All rights reserved. // #import "RouteQuestionsVC.h" #import "QuizCell.h" #import "SFAPercorsoQuestion.h" #import "FinalQuizVC.h" #import "UIImageView+AFNetworking.h" #import "SFAPercorso.h" #import <AudioToolbox/AudioToolbox.h> #import <AVFoundation/AVAudioPlayer.h> @interface RouteQuestionsVC () { NSTimer *countTimer; AVAudioPlayer *player; } @property (nonatomic, weak) IBOutlet UIImageView *questionImage; @property (nonatomic, weak) IBOutlet UIButton *stepOverButton; @property (nonatomic, weak) IBOutlet UILabel *questionLabel; @property (nonatomic, strong) SFAPercorsoQuestion *percorsoQuestion; @property (weak, nonatomic) IBOutlet UITableView *qTable; @end @implementation RouteQuestionsVC - (void)viewDidLoad { [super viewDidLoad]; [self.stepOverButton setTitle:NSLocalizedString(@"StepOver", nil) forState:UIControlStateNormal]; self.questionIndex=[NSNumber numberWithInt:0]; self.percorsoQuestion=[self.routeForDetail.questions objectAtIndex:[self.questionIndex intValue]]; [self.questionImage setImageWithURL:[NSURL URLWithString:self.percorsoQuestion.fileImage]]; self.questionLabel.text=self.percorsoQuestion.label; [self.navigationItem setHidesBackButton:YES]; [self playSoundWithPath:@"ticchettio" withLoop:YES]; } -(void) viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (player) { [player play]; } [self timerStop]; // self.txtDuration.text =[NSString stringWithFormat:@"Durata %@",[DATAMANAGER getTime] ]; // countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self // selector:@selector(timeRun) // userInfo:nil // repeats:YES]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self timerStop]; // [DATAMANAGER saveTimerForRouteID:self.routeForDetail]; } #pragma mark - IBAction - (void)doOpenNewQuestion:(id)sender { /* Per ciascuna Risposta corretta al quiz finale: 20 punti */ if(sender) { [self playerStop]; [self.qTable setUserInteractionEnabled:NO]; UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview]; NSIndexPath *clickedButtonPath = [self.qTable indexPathForCell:clickedCell]; NSLog(@"CORRECT VALUE: %i - cell index: %li", [self.percorsoQuestion.correctAnswer intValue] +1, (long)clickedButtonPath.row ); if([self.percorsoQuestion.correctAnswer intValue] == clickedButtonPath.row +1) { [self playSoundWithPath:@"correctAnswer" withLoop:NO]; [DATAMANAGER setCellColorforTableview:self.qTable withColor:[UIColor greenColor] forIndexPath:clickedButtonPath andDuration:1]; int sum = [[DATAMANAGER.user.pointsForRoute objectForKey:self.routeForDetail.routeId] intValue]; sum = sum + POINTS_QUIZ; NSLog(@"SOMMA: %i", sum); [DATAMANAGER.user.pointsForRoute setObject:[NSNumber numberWithInt:sum] forKey:self.routeForDetail.routeId]; [DATAMANAGER saveUser]; } else{ [self playSoundWithPath:@"wrongAnswer" withLoop:NO]; [DATAMANAGER setCellColorforTableview:self.qTable withColor:[UIColor greenColor] forIndexPath:[NSIndexPath indexPathForRow:[self.percorsoQuestion.correctAnswer intValue]-1 inSection:0] andDuration:1]; [DATAMANAGER setCellColorforTableview:self.qTable withColor:[UIColor redColor] forIndexPath:clickedButtonPath andDuration:1]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self playerStop]; if (![self.questionIndex isEqualToNumber:[NSNumber numberWithInteger:[self.routeForDetail.questions count]-1]]) { self.questionIndex = [NSNumber numberWithInt:[self.questionIndex intValue]+1]; self.percorsoQuestion = [self.routeForDetail.questions objectAtIndex:[self.questionIndex intValue]]; [self.questionImage setImageWithURL:[NSURL URLWithString:self.percorsoQuestion.fileImage]]; self.questionLabel.text = self.percorsoQuestion.label; [self playSoundWithPath:@"ticchettio" withLoop:YES]; [self.qTable reloadData]; [self.qTable setUserInteractionEnabled:YES]; } else{ [self playerStop]; // [DATAMANAGER saveTimerForRouteID:self.routeForDetail]; FinalQuizVC *finalQuizVC = [[FinalQuizVC alloc] init]; finalQuizVC.routeForDetail = self.routeForDetail; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:finalQuizVC animated:YES]; } }); } else { if (![self.questionIndex isEqualToNumber:[NSNumber numberWithInteger:[self.routeForDetail.questions count]-1]]) { self.questionIndex = [NSNumber numberWithInt:[self.questionIndex intValue] +1]; self.percorsoQuestion = [self.routeForDetail.questions objectAtIndex:[self.questionIndex intValue]]; [self.questionImage setImageWithURL:[NSURL URLWithString:self.percorsoQuestion.fileImage]]; self.questionLabel.text = self.percorsoQuestion.label; [self.qTable reloadData]; [self.qTable setUserInteractionEnabled:YES]; } else{ [self playerStop]; // [DATAMANAGER saveTimerForRouteID:self.routeForDetail]; FinalQuizVC *finalQuizVC = [[FinalQuizVC alloc] init]; finalQuizVC.routeForDetail = self.routeForDetail; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:finalQuizVC animated:YES]; } } } - (IBAction)doStepOver { [self doOpenNewQuestion:nil]; } #pragma mark - Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.percorsoQuestion.answers count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"QuizCell"; QuizCell *cell = (QuizCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; } [cell.questionButton setTitle:[self.percorsoQuestion.answers objectAtIndex:indexPath.row] forState:UIControlStateNormal]; [cell.questionButton addTarget:self action:@selector(doOpenNewQuestion:) forControlEvents:UIControlEventTouchUpInside]; if([cell.questionButton.titleLabel.text length] > 0) { cell.questionButton.layer.borderWidth = 1; cell.questionButton.layer.borderColor = [[UIColor blackColor]CGColor]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Timer //-(void)timeRun{ // [DATAMANAGER timeInc]; // self.txtDuration.text = [NSString stringWithFormat:@"Durata %@", [DATAMANAGER getTime]]; //} -(void)timerStop{ if(countTimer){ [countTimer invalidate]; countTimer=Nil; } } -(void)playSoundWithPath:(NSString*)fileSound withLoop:(BOOL)val{ NSString *ext=@"wav"; if (val==NO) ext=@"mp3"; NSString *path = [[NSBundle mainBundle] pathForResource:fileSound ofType:ext]; NSURL *pathURL = [NSURL fileURLWithPath : path]; player = [[AVAudioPlayer alloc] initWithContentsOfURL:pathURL error:NULL]; [player setVolume:1.0]; if (val==YES) [player setNumberOfLoops:-1]; [player play]; } -(void)playerStop{ [player stop]; player =nil; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Commodities/SWRevealViewController/RouteQuestionsVC/RouteQuestionsVC.m
Revision | Author | Commited | Message |
---|---|---|---|
570 Diff | PBonamassa | Wed 26 Aug, 2015 10:15:47 +0000 | fixed image finalQuiz |
568 Diff | PBonamassa | Wed 26 Aug, 2015 09:47:30 +0000 | fixed bug timer & image final quiz |
457 Diff | PBonamassa | Fri 31 Jul, 2015 08:10:03 +0000 | fixed sounds |
456 Diff | FPompili | Thu 30 Jul, 2015 16:10:00 +0000 | fixed sounds |
453 Diff | PBonamassa | Thu 30 Jul, 2015 15:25:09 +0000 | added sound Frocix |
393 Diff | FPompili | Mon 20 Jul, 2015 08:57:38 +0000 | fixed stepover,fixed timer |
383 Diff | FPompili | Fri 17 Jul, 2015 13:59:00 +0000 | fixed asnwer index |
381 Diff | FPompili | Fri 17 Jul, 2015 13:18:02 +0000 | fixed index correct answer |
379 Diff | FPompili | Fri 17 Jul, 2015 11:37:10 +0000 | added facebook sharing |
351 | FPompili | Thu 16 Jul, 2015 09:57:31 +0000 | highlighted also correct answer when user select bad answer |