Nextrek
@ 530
Nextrek / iOS / SafariArte / trunk / SafariArte / Controllers / RoutesVC / RoutesVC.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 |
// // RoutesVC.m // SafariArte // // Created by IntellitronikaUser on 12/06/15. // Copyright (c) 2015 Nextrek. All rights reserved. // #import "RoutesVC.h" #import "NXTParser.h" #import "RoutesCell.h" #import "SFAPercorso.h" #import "UIImageView+AFNetworking.h" #import "AFHTTPRequestOperation.h" #import "DataManager.h" #import "PoiVC.h" #import "RouteDetailsVC.h" @interface RoutesVC ()<UITableViewDelegate,UIActionSheetDelegate> @end @implementation RoutesVC @synthesize routesTable; - (void)viewDidLoad { [super viewDidLoad]; self.title = self.titleValue; self.routesTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; if (self.routesDictionary.count >0){ self.lblNoRoutes.text=@""; if (self.isForGeoRoutes!=YES) routeKeysArray = [self.routesDictionary allKeys] ; else routeKeysArray=[[NSArray alloc]initWithArray:DATAMANAGER.orderedArray]; routeServerOrderDict =[[NSMutableDictionary alloc]initWithCapacity:[routeKeysArray count]]; routeLenghtDict =[[NSMutableDictionary alloc]initWithCapacity:[routeKeysArray count]]; routeDurationDict =[[NSMutableDictionary alloc]initWithCapacity:[routeKeysArray count]]; routeAlphOrderDict =[[NSMutableDictionary alloc]initWithCapacity:[routeKeysArray count]]; for (int n=0; n<[routeKeysArray count]; n++) { SFAPercorso *route = [self.routesDictionary objectForKey:routeKeysArray[n]]; [routeServerOrderDict setObject:route.routeLength[2] forKey:routeKeysArray[n]] ; [routeLenghtDict setObject:route.routeLength[2] forKey:routeKeysArray[n]] ; [routeAlphOrderDict setObject:route.routeLabel forKey:routeKeysArray[n]]; [routeDurationDict setObject:route.routeDuration[1] forKey:routeKeysArray[n]] ; } if (self.isForGeoRoutes!=YES) { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BtnOrder", nil) style:UIBarButtonItemStyleDone target:self action:@selector(showNormalActionSheet)]; [self orderDict:routeLenghtDict]; } else { if (self.gpsPosition==NO) [self orderDictAlpha:routeAlphOrderDict]; } } else self.lblNoRoutes.text=NSLocalizedString(@"NoRoutesOnTable", nil); self.routesTable.delegate=self; } - (void)viewDidAppear:(BOOL)animated{ [self.routesTable reloadInputViews]; } #pragma mark - Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[self.routesDictionary allKeys] count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 110.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"RoutesCell"; RoutesCell *cell = (RoutesCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; } NSString *routeKey = [routeKeysArray objectAtIndex:indexPath.row]; SFAPercorso *route = [self.routesDictionary objectForKey:routeKey]; if(self.allRoutes) { [cell.imageValue setImageWithURL:[NSURL URLWithString:route.routeImg2]]; } else { NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:route.routeImg2] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0f]; [cell.imageValue setImageWithURLRequest:imageRequest placeholderImage:nil success:nil failure:nil]; /* * //CACHE ALternative Method NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:route.routeFileImage] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0f]; UIImage *image = [[UIImageView sharedImageCache] cachedImageForRequest:urlRequest]; if (image != nil) { [cell.imageValue setImage:image]; return cell; } AFHTTPRequestOperation *postOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest]; postOperation.responseSerializer = [AFImageResponseSerializer serializer]; [postOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { UIImage *image = responseObject; [[UIImageView sharedImageCache] cacheImage:image forRequest:urlRequest]; [cell.imageValue setImage:image]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Image error: %@", error); }]; [postOperation start]; */ } cell.titleValue.text = !STR_ISNULL_OR_EMPTY(route.routeLabel) ? route.routeLabel : @"-"; cell.descrValue.text = !STR_ISNULL_OR_EMPTY(route.routeDescription) ? route.routeDescription : @"-"; cell.durationValue.text = [NSLocalizedString(@"RouteDuration", nil) stringByAppendingString: route.routeDuration[0]]; cell.lengthValue.text = ([[[NSUserDefaults standardUserDefaults] objectForKey:@"distanceUnit"] isEqualToString:@"Mile"])? route.routeLength[0]:route.routeLength[1] ; if (route.routePurchased){ cell.priceValue.text = @""; cell.priceValue.textColor = [UIColor blackColor]; if ([[DATAMANAGER poiForRoute:route] intValue] > 0 && [[DATAMANAGER poiForRoute:route] intValue] < route.routePois.count) { cell.buyLabel.text = NSLocalizedString(@"Iniziato", nil); } else if (route.routePois.count == [[DATAMANAGER poiForRoute:route] intValue]) { cell.buyLabel.text = NSLocalizedString(@"Completato", nil); } else if([[DATAMANAGER poiForRoute:route] intValue] == 0) { cell.priceValue.text = route.routePrice; cell.priceValue.textColor = [UIColor blackColor]; cell.buyLabel.text = ([route.routePrice isEqualToString: @"0"]) ? NSLocalizedString(@"Gratis", nil) : NSLocalizedString(@"BuyRoute", nil); if ([route.routePrice isEqualToString:@"0"]){ [cell.buyImageView setImage:[UIImage imageNamed:@"free_background"]]; cell.priceValue.text =@""; }else [cell.buyImageView setImage:[UIImage imageNamed:@"buy_background"]]; } [cell.buyImageView setImage:[UIImage imageNamed:@"buyed_background"]]; } else { cell.priceValue.text = route.routePrice; cell.priceValue.textColor = [UIColor blackColor]; cell.buyLabel.text = ([route.routePrice isEqualToString: @"0"]) ? NSLocalizedString(@"Gratis", nil) : NSLocalizedString(@"BuyRoute", nil); if ([route.routePrice isEqualToString:@"0"]){ [cell.buyImageView setImage:[UIImage imageNamed:@"free_background"]]; cell.priceValue.text =@""; }else [cell.buyImageView setImage:[UIImage imageNamed:@"buy_background"]]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *index=routeKeysArray[indexPath.row]; SFAPercorso *route = [self.routesDictionary objectForKey:index ]; if(route.routePois && !self.allRoutes) { [self goToRouteDetailController:[DATAMANAGER.user.percorsi objectForKey:route.routeId]]; } else { [self doGetRoutesRequest:route]; } [tableView deselectRowAtIndexPath:indexPath animated:NO]; } - (void) doGetRoutesRequest:(SFAPercorso*)route { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; [NXTNetwork doGetRoutesByIdWithSuccess:route.routeId successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; if([DATAMANAGER errorInside:response] == nil) { [NXTParser doParseRoutesById:response route:route]; if(self.allRoutes) { [self goToRouteDetailController:route]; } else { [self goToRouteDetailController:[DATAMANAGER.user.percorsi objectForKey:route.routeId]]; } [DATAMANAGER saveUser]; // [NXTNetwork doUserRoutesWithSuccess:@"" successBlock:^(NSDictionary *response) { // // if([DATAMANAGER errorInside:response] == nil) { // // NSLog(@"PERCORSI: %@", DATAMANAGER.user.percorsi); // DATAMANAGER.user.percorsi = [NXTParser doParseRoutes:response]; // // ((SFAPercorso*)[DATAMANAGER.user.percorsi objectForKey:route.routeId]).routePois = test; // [DATAMANAGER saveUser]; // // NSLog(@"PERCORSI: %@", DATAMANAGER.user.percorsi); // } // // } failure:^(NSError *error) { }]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } #pragma mark - Open RoutesVC Controller - (void) goToRouteDetailController:(SFAPercorso*)route { RouteDetailsVC *routeDetails = [[RouteDetailsVC alloc] init]; routeDetails.allRoutes = self.allRoutes; routeDetails.routeForDetail = route; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:routeDetails animated:YES]; } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex ==0) { [self orderDict:routeLenghtDict]; [self.routesTable reloadData]; }else if (buttonIndex ==1) { [self orderDict:routeDurationDict]; [self.routesTable reloadData]; } } -(void) orderDict:(NSDictionary *)dict { routeKeysArray = [dict keysSortedByValueUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult)NSOrderedAscending; } return (NSComparisonResult)NSOrderedSame; }]; } -(void) orderDictAlpha:(NSDictionary *)dict{ routeKeysArray = [dict keysSortedByValueUsingComparator: ^(id obj1, id obj2) { NSComparisonResult result = [obj1 caseInsensitiveCompare: obj2 ]; return result; }]; } -(void)showNormalActionSheet { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"SelectionOrder", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OrderByLenght", nil), NSLocalizedString(@"OrderByDuration", nil), nil]; [actionSheet showInView:self.view]; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Controllers/RoutesVC/RoutesVC.m
Revision | Author | Commited | Message |
---|---|---|---|
530 Diff | FAquili | Mon 24 Aug, 2015 10:51:56 +0000 | Bug fixing |
498 Diff | FPompili | Wed 12 Aug, 2015 12:27:23 +0000 | added Alphabetical order with no gps coor |
497 Diff | PBonamassa | Wed 12 Aug, 2015 09:53:26 +0000 | aggiunto metodo che restituisce tutti i percorsi nel caso in cui non viene definita la posizione gps dell utente |
488 Diff | PBonamassa | Mon 10 Aug, 2015 12:12:43 +0000 | added new images |
485 Diff | PBonamassa | Thu 06 Aug, 2015 15:12:03 +0000 | changed images menĂ¹ PoiVC, added localized string & fixed other problem |
484 Diff | PBonamassa | Thu 06 Aug, 2015 11:26:33 +0000 | modified label to list routes |
454 Diff | FPompili | Thu 30 Jul, 2015 15:26:46 +0000 | fixed bug |
452 Diff | FPompili | Thu 30 Jul, 2015 13:42:02 +0000 | removed sort selection on geoRoutes |
451 Diff | FPompili | Thu 30 Jul, 2015 13:34:10 +0000 | added orderByServer (geo order) for routes dict |
440 | PBonamassa | Mon 27 Jul, 2015 10:33:32 +0000 | added CongratulationVC and fixed other bug |