Nextrek
@ 588
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 |
// // 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]; // self.title = self.routeForDetail.routeLabel; tableIsHidden = YES; self.routeTable.hidden = tableIsHidden; if(self.allRoutes) { [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.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 scrollRangeToVisible:NSMakeRange(0, 1)]; if (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]; } } - (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 || [self.routeForDetail.routePrice isEqualToString: @"0"]) { 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 == 004){ if(buttonIndex == 0){ NSDictionary *properties = @{ @"og:type": @"article", @"og:title": self.routeForDetail.routeLabel, @"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 |
---|---|---|---|
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 Diff | FPompili | Tue 04 Aug, 2015 22:09:28 +0000 | aggiunta memorizzazione status poi (risposta ok, risposta errata , saltata) |
453 Diff | PBonamassa | Thu 30 Jul, 2015 15:25:09 +0000 | added sound Frocix |
450 Diff | PBonamassa | Thu 30 Jul, 2015 12:29:55 +0000 | fixed bug |
444 Diff | FPompili | Tue 28 Jul, 2015 14:26:36 +0000 | added customAlertView |
436 Diff | FPompili | Thu 23 Jul, 2015 18:00:23 +0000 | removed multi allocation of right button |
419 Diff | FPompili | Wed 22 Jul, 2015 11:15:17 +0000 | added order by lenght and duration inside routesvc |
416 | FPompili | Wed 22 Jul, 2015 09:47:23 +0000 | fixed purchase , setted api to v 2.0 |