Nextrek
@ 796
Nextrek / iOS / SafariArte / trunk / SafariArte / Controllers / RouteDetailsVC / RouteDetailsVC.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 |
// // RouteDetailsVC.m // SafariArte // // Created by IntellitronikaUser on 26/06/15. // Copyright (c) 2015 Nextrek. All rights reserved. // #import "RouteDetailsVC.h" #import "MenuItemCell.h" #import "SFAPoi.h" #import "PoiVC.h" #import "FinalQuizVC.h" #import "IAPVC.h" #import "NSData+AESCrypt.h" #import "NSString+AESCrypt.h" #import "UIImageView+AFNetworking.h" #import "AFHTTPRequestOperation.h" #import <FBSDKCoreKit/FBSDKCoreKit.h> #import <FBSDKShareKit/FBSDKShareKit.h> @interface RouteDetailsVC ()<UIAlertViewDelegate, FBSDKSharingDelegate> { BOOL tableIsHidden; PoiVC *poiVC; } @property (nonatomic, weak) IBOutlet UIImageView *routeImage; @property (nonatomic, weak) IBOutlet UILabel *routeDuration; @property (nonatomic, weak) IBOutlet UILabel *routeDistance; @property (nonatomic, weak) IBOutlet UILabel *routeTitle; @property (nonatomic, weak) IBOutlet UITextView *routeDescription; @property (nonatomic, weak) IBOutlet UIButton *routeDescButton; @property (nonatomic, weak) IBOutlet UITableView *routeTable; @property (nonatomic, weak) IBOutlet UIView *routeDescriptionView; @property (nonatomic, weak) IBOutlet UIButton *startBuyButton; @end @implementation RouteDetailsVC - (void)viewDidLoad { [super viewDidLoad]; self.routeTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; tableIsHidden = YES; self.routeTable.hidden = tableIsHidden; // if(self.allRoutes) { // // [self.routeImage setImage:[DATAMANAGER imageWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.routeForDetail.routeFileImg]]] scaledToWidth:[[UIScreen mainScreen] bounds].size.width]]; // //// [self.routeImage setImageWithURL:[NSURL URLWithString:self.routeForDetail.routeFileImg]]; // } // else { NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:self.routeForDetail.routeFileImg] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0f]; // [self.routeImage setImageWithURLRequest:imageRequest placeholderImage:nil success:nil failure:nil]; [self.routeImage setImageWithURLRequest:imageRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { [self.routeImage setImage:[DATAMANAGER imageWithImage:image scaledToWidth:[[UIScreen mainScreen] bounds].size.width]]; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { nil; }]; // } self.routeDistance.text = ([[[NSUserDefaults standardUserDefaults] objectForKey:@"distanceUnit"] isEqualToString:@"Mile"])? self.routeForDetail.routeLength[0]: self.routeForDetail.routeLength[1] ; self.routeTitle.text = self.routeForDetail.routeLabel; self.routeDuration.text =[NSLocalizedString(@"RouteDuration", nil) stringByAppendingString: self.routeForDetail.routeDuration[0]]; self.routeDescription.text = self.routeForDetail.routeDescription; self.routeDescription.textAlignment = NSTextAlignmentJustified; [self.routeDescription scrollRangeToVisible:NSMakeRange(0, 1)]; if ([[DATAMANAGER poiForRoute:self.routeForDetail] intValue] > 0 && self.routeForDetail.routePois.count && [[DATAMANAGER poiForRoute:self.routeForDetail] intValue] < self.routeForDetail.routePois.count){ [self.startBuyButton setTitle:NSLocalizedString(@"Continue", nil) forState:UIControlStateNormal]; }else if ((([[DATAMANAGER.user.percorsi allKeys] containsObject:self.routeForDetail.routeId] && [[DATAMANAGER poiForRoute:self.routeForDetail] intValue] == 0 )) ||self.routeForDetail.routePurchased){ [self.startBuyButton setTitle:NSLocalizedString(@"StartRoute", nil) forState:UIControlStateNormal]; }else { [self.startBuyButton setTitle:[self.routeForDetail.routePrice isEqualToString: @"0"] ? NSLocalizedString(@"StartRoute", nil) : NSLocalizedString(@"BuyRoute", nil) forState:UIControlStateNormal]; } if([[DATAMANAGER.user.scoreRoute objectForKey:self.routeForDetail.routeId] intValue]!=0){ [NXTNetwork doSetScoreWithSuccess:self.routeForDetail.routeId score:[DATAMANAGER.user.scoreRoute objectForKey:self.routeForDetail.routeId] duration: [NSNumber numberWithLong:[[DATAMANAGER.user.timeForRoute objectForKey:self.routeForDetail.routeId] intValue] * 1000 ] successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; NSLog(@"TOKEN: %@", response[@"response"][@"token"]); if([DATAMANAGER errorInside:response] == nil) { //added for reset timer [DATAMANAGER resetTimerForRouteID:self.routeForDetail]; [DATAMANAGER.user.scoreRoute setObject:0 forKey:self.routeForDetail.routeId]; [DATAMANAGER.user.pointsForRoute setObject:0 forKey:self.routeForDetail.routeId]; //[DATAMANAGER showAlert:self withTitle: @"Safari D'Arte" message:NSLocalizedString(@"Correctly", nil) tag:02]; } else if([DATAMANAGER errorInside:response].code ==111){ [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"ScoreAlreadySent", nil) tag:103]; //added for reset timer [DATAMANAGER resetTimerForRouteID:self.routeForDetail]; } else{ [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"ServerNotRespond", nil) tag:103]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"ErrorHasJustBeFound", nil) tag:104]; }]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.routeImage setContentMode:UIViewContentModeScaleAspectFit]; } #pragma mark - IBAction //- (IBAction)doShowHideRouteTable { // // tableIsHidden = !tableIsHidden; // // self.routeDescriptionView.hidden = !tableIsHidden; // self.routeTable.hidden = tableIsHidden; // // if(tableIsHidden) { // self.routeDescButton.layer.cornerRadius = 0; // [self.routeDescButton setBackgroundColor:[UIColor clearColor]]; // [self.routeDescButton setImage:[UIImage imageNamed:@"5"]forState:UIControlStateNormal]; // } // else { // self.routeDescButton.layer.cornerRadius = self.routeDescButton.frame.size.width / 2; // [self.routeDescButton setBackgroundColor:[UIColor lightGrayColor]]; // [self.routeDescButton setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal]; // } //} - (IBAction)doStartOrBuyRoute { if(self.routeForDetail.routePurchased == TRUE || [self.routeForDetail.routePrice isEqualToString: @"0"] || [[DATAMANAGER.user.percorsi allKeys] containsObject:self.routeForDetail.routeId]) { //[[dictionary allKeys] containsObject:@"key"] NSNumber *existingPoiIndexForRoute = [DATAMANAGER poiForRoute:self.routeForDetail]; poiVC = [[PoiVC alloc] init]; poiVC.allRoutes = self.allRoutes; poiVC.routeForDetail = self.routeForDetail; if(!existingPoiIndexForRoute || [existingPoiIndexForRoute intValue] == 0) { [DATAMANAGER.user.percorsi setObject:self.routeForDetail forKey:self.routeForDetail.routeId]; [DATAMANAGER saveUser]; poiVC.poiIndex = [NSNumber numberWithInt:0]; DATAMANAGER.secondsCount = 0; [DATAMANAGER showMessageWithAlert:self message:NSLocalizedString(@"ShareRoute", nil) tag:004]; } else { if(([existingPoiIndexForRoute intValue] + 1) < [self.routeForDetail.routePois count]) { poiVC.poiIndex = [NSNumber numberWithInt: [existingPoiIndexForRoute intValue] + 1]; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; }else { 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]; return; } } } else { if([DATAMANAGER.user.credits intValue] - [self.routeForDetail.routePrice intValue] >= 0) { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; [NXTNetwork doPurchaseAuthWithSuccess:self.routeForDetail.routeId successBlock:^(NSDictionary *response) { if([DATAMANAGER errorInside:response] == nil) { NSString *digest=response[@"response"][@"digest"]; NSLog(@"digest string with base64 : %@", digest ); NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:digest options:0]; NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding]; NSLog(@"digest string clear : %@", decodedString ); NSString *encryptedString = [digest AES256EncryptWithKey:CRYPTO_PASS]; decodedData = [[NSData alloc] initWithBase64EncodedString:encryptedString options:0]; decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding]; NSLog(@"Encrypted string without base64: %@", decodedString ); NSLog(@"Encrypted string with base64: %@", encryptedString ); [NXTNetwork doPurchaseRouteWithSuccess:self.routeForDetail.routeId cryptedString:encryptedString successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; if([DATAMANAGER errorInside:response] == nil) { self.routeForDetail.routePurchased = TRUE; DATAMANAGER.user.credits = [NSNumber numberWithInt:[DATAMANAGER.user.credits intValue] - [self.routeForDetail.routePrice intValue]]; [DATAMANAGER saveUser]; [DATAMANAGER showMessageWithAlert:self message:NSLocalizedString(@"WantToStart", nil) tag:002]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } else { [DATAMANAGER showErrorAlert2Btns:self message:NSLocalizedString(@"buyCredits", nil) tag:001]; } } } #pragma mark - Table view methods - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return NSLocalizedString(@"PercorsoHeader", nil); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.routeForDetail.routePois count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 44.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"MenuItemCell"; MenuItemCell *cell = (MenuItemCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; } SFAPoi *poi = [self.routeForDetail.routePois objectAtIndex:indexPath.row]; cell.itemValue.text = STR_ISNULL_OR_EMPTY(poi.poiLabel) ? @"-" : poi.poiLabel; cell.itemValue.textAlignment = NSTextAlignmentJustified; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; } - (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex { if(alertView.tag == 001) { if (buttonIndex==0) { IAPVC *iapVC = [[IAPVC alloc] init]; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:iapVC animated:YES]; // } // }else if(alertView.tag ==001){ // if (buttonIndex == 0) { self.startBuyButton.titleLabel.text = NSLocalizedString(@"StartRoute", nil); [self.startBuyButton reloadInputViews]; } }else if(alertView.tag == 002) { if (buttonIndex==0) { self.startBuyButton.titleLabel.text = NSLocalizedString(@"StartRoute", nil); [self.startBuyButton reloadInputViews]; }else{ self.startBuyButton.titleLabel.text = NSLocalizedString(@"scaricato", nil); [self.startBuyButton reloadInputViews]; [alertView close]; } } else if(alertView.tag == 004){ if(buttonIndex == 0){ NSDictionary *properties = @{ @"og:type": @"article", @"og:title": @"Safari D'arte iOS", @"og:description":[NSString stringWithFormat:NSLocalizedString(@"FBShareRoute", nil), self.routeForDetail.routeLabel] }; FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties]; // Create an action FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init]; action.actionType = @"news.publishes"; [action setObject:object forKey:@"article"]; FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init]; content.action = action; content.previewPropertyName = @"article"; [FBSDKShareDialog showFromViewController:self withContent:content delegate:self]; }else { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; } }else { if (buttonIndex==0) { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; } else { [self.startBuyButton setTitle: NSLocalizedString(@"StartRoute", nil) forState:UIControlStateNormal];; } } [alertView close]; } #pragma mark - FBSDKSharingDelegate - (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; } - (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; } - (void) sharerDidCancel:(id<FBSDKSharing>)sharer { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:poiVC animated:YES]; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Controllers/RouteDetailsVC/RouteDetailsVC.m
Revision | Author | Commited | Message |
---|---|---|---|
796 Diff | FAquili | Wed 07 Oct, 2015 07:46:13 +0000 | v.1 b.035 |
742 Diff | PBonamassa | Wed 16 Sep, 2015 09:15:34 +0000 | changed userImage , distanceToMeImage & message facebook. |
726 Diff | PBonamassa | Thu 10 Sep, 2015 14:43:14 +0000 | fixed bug |
722 Diff | PBonamassa | Tue 08 Sep, 2015 13:42:51 +0000 | fixed sent score route |
656 Diff | FPompili | Wed 02 Sep, 2015 13:46:36 +0000 | adesso le immagini vengono prese sempre dalla cache |
595 Diff | FAquili | Thu 27 Aug, 2015 15:20:48 +0000 | FOLDER UPDATE AFTER CRASHLYTHICS UPDATE |
588 Diff | PBonamassa | Thu 27 Aug, 2015 13:39:33 +0000 | fixed bug |
573 Diff | FAquili | Wed 26 Aug, 2015 14:27:40 +0000 | AGGIUNTO PARSER PER AVERE ETICHETTE PERCORSI UGUALI SIA UN PERCORSI GRATUITI CHE IN I MIEI PERCORSI |
484 Diff | PBonamassa | Thu 06 Aug, 2015 11:26:33 +0000 | modified label to list routes |
479 | FPompili | Tue 04 Aug, 2015 22:09:28 +0000 | aggiunta memorizzazione status poi (risposta ok, risposta errata , saltata) |