

Nextrek
@ 789
Nextrek / iOS / SafariArte / trunk / SafariArte / Controllers / HomeVC / HomeVC.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 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
// // HomeVC.m // SafariArte // // Created by IntellitronikaUser on 18/06/15. // Copyright (c) 2015 Nextrek. All rights reserved. // #import "HomeVC.h" #import "HomeItemCell.h" #import "NXTParser.h" #import "GenericWebViewVC.h" #import "RoutesVC.h" #import "Reachability.h" #import "SearchVC.h" #import <AudioToolbox/AudioToolbox.h> @interface HomeVC ()<UIAlertViewDelegate,UIGestureRecognizerDelegate> { NSArray *itemsArray; NSArray *imagesForItemsArray; NSString *searchedText; } @property (weak, nonatomic) IBOutlet UITableView *tab; @property (weak, nonatomic) IBOutlet UIImageView *backGroundView; @property (nonatomic, strong) IBOutlet UITapGestureRecognizer *tapRecognizer; @property (nonatomic, weak) IBOutlet UISearchBar *searchBar; @property (strong, nonatomic) UIView *keyboardResponder; @property (nonatomic, weak) IBOutlet UIImageView *currLocationImage; @property (nonatomic, weak) IBOutlet UILabel *currLocationLabel; @property (nonatomic, weak) IBOutlet UIButton *currLocationBtn; @property (nonatomic, weak) IBOutlet UIButton *classificaBtn; @property (nonatomic, weak) IBOutlet UILabel *versionLabel; @end @implementation HomeVC{ Reachability *internetReachable; } - (void)viewDidLoad { [super viewDidLoad]; self.versionLabel.text = APP_VERSION_COMPLETE; self.keyboardResponder = nil; itemsArray = [NSArray arrayWithObjects: NSLocalizedString(@"home_0", nil), NSLocalizedString(@"home_1", nil), NSLocalizedString(@"home_2", nil), nil]; imagesForItemsArray = [NSArray arrayWithObjects: @"posizione_dispositivo", @"percorsi_gratuiti", @"tuoi_percorsi", nil]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconLogo"]]]; self.navigationItem.title = @"Safari D'Arte"; self.classificaBtn.layer.borderWidth = 1; self.classificaBtn.layer.borderColor = [UIColor whiteColor].CGColor; [self.classificaBtn setTitle:NSLocalizedString(@"classifica", nil) forState:UIControlStateNormal]; [self.tapRecognizer addTarget:self action:@selector(dismissKeyboard)]; self.tapRecognizer.delegate=self; } #pragma mark - IBActions - (IBAction) doOpenClassifica { if([DATAMANAGER testInternetConnection] == FALSE){ [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"FunctionNotAvailable", nil) tag:006]; }else{ GenericWebViewVC *genericWebViewVC = [[GenericWebViewVC alloc] init]; genericWebViewVC.title = NSLocalizedString(@"classifica", nil); NSString *urlToCall = [NSString stringWithFormat:@"http://svm19842.vps.tagadab.it:8084/SafariDarte/CtrlArea/ranking/?token=%@", DATAMANAGER.user.token]; genericWebViewVC.urlToCall = urlToCall; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:genericWebViewVC animated:YES]; } } #pragma mark - Open Free RoutesVC Controller - (void) goToFreeRoutesController:(NSMutableDictionary*)routes isForAllRoutes:(BOOL)isForAllRoutes { self.searchBar.text=@""; [self dismissKeyboard]; RoutesVC *routesVC = [[RoutesVC alloc] init]; routesVC.routesDictionary = routes; routesVC.allRoutes = isForAllRoutes; routesVC.titleValue = NSLocalizedString(@"home_1", nil); self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:routesVC animated:YES]; } #pragma mark - Open RoutesVC Controller - (void) goToRoutesController:(NSMutableDictionary*)routes isForAllRoutes:(BOOL)isForAllRoutes isFromGeoLocation:(BOOL)isFromGeoLocation withGpsPosition:(BOOL)gpsPosition { self.searchBar.text = @""; [self dismissKeyboard]; RoutesVC *routesVC = [[RoutesVC alloc] init]; routesVC.routesDictionary = routes; routesVC.allRoutes = isForAllRoutes; routesVC.titleValue = isForAllRoutes ? searchedText : NSLocalizedString(@"home_2", nil); if (isFromGeoLocation){ routesVC.titleValue=NSLocalizedString(@"home_3", nil); routesVC.isForGeoRoutes=YES; routesVC.gpsPosition=gpsPosition; } self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:routesVC animated:YES]; } #pragma mark - UITextField Delegate - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; searchedText = searchBar.text; SearchVC *searchVC = [[SearchVC alloc] init]; if([DATAMANAGER testInternetConnection] == FALSE){ [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"FunctionNotAvailable", nil) tag:006]; }else { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; [NXTNetwork doSearchRoutesWithSuccess:searchBar.text onlyFree:NO successBlock:^(NSDictionary *response) { if([DATAMANAGER errorInside:response] == nil) { searchVC.routesAllDictionary=[NXTParser doParseRoutes:response]; [NXTNetwork doSearchRoutesWithSuccess:searchBar.text onlyFree:YES successBlock:^(NSDictionary *response) { if([DATAMANAGER errorInside:response] == nil) { searchVC.routesFreeDictionary=[NXTParser doParseRoutes:response]; [NXTNetwork doUserRoutesWithSuccess:searchBar.text successBlock:^(NSDictionary *response) { if([DATAMANAGER errorInside:response] == nil) { searchVC.userRoutesDictionary = [NXTParser doParseRoutes:response]; searchVC.titleLabel=searchedText; [ActivityViewFramed hideActivityView]; self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; [self.navigationController pushViewController:searchVC animated:YES]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { self.keyboardResponder = searchBar; return YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } #pragma mark - Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [itemsArray count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 54.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"HomeItemCell"; HomeItemCell *cell = (HomeItemCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; } // cell.notificationView.hidden = indexPath.row != 2; cell.notificationView.hidden = YES; cell.imageValue.image = [UIImage imageNamed:[imagesForItemsArray objectAtIndex:indexPath.row]]; cell.itemValue.text = [itemsArray objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == 0) { [self getLocation]; } else if (indexPath.row == 1){ [self doOpenFreeRoutes]; } else if (indexPath.row == 2){ [self doOpenUserRoutes]; } [tableView deselectRowAtIndexPath:indexPath animated:NO]; } - (void) doOpenUserRoutes { if(DATAMANAGER.user.percorsi.count >0) { [self goToRoutesController:DATAMANAGER.user.percorsi isForAllRoutes:NO isFromGeoLocation:NO withGpsPosition:NO]; } else { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; [NXTNetwork doUserRoutesWithSuccess:@"" successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; if([DATAMANAGER errorInside:response] == nil) { // DATAMANAGER.user.percorsi = [NXTParser doParseRoutes:response]; // [DATAMANAGER saveUser]; [self goToRoutesController:DATAMANAGER.user.percorsi isForAllRoutes:NO isFromGeoLocation:NO withGpsPosition:NO]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } #pragma mark - OpenAllRoutes - (void)openAllRoutes{ [NXTNetwork doSearchRoutesWithSuccess:@"" onlyFree:NO successBlock:^(NSDictionary *response) { if([DATAMANAGER errorInside:response] == nil) { NSMutableDictionary *percorsi = [NXTParser doParseRoutes:response]; if([percorsi count]!=0) [self goToRoutesController:percorsi isForAllRoutes:YES isFromGeoLocation:YES withGpsPosition:NO ]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } - (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex { if (alertView.tag==1) { if (buttonIndex==1) { if (IS_OS_8_OR_LATER) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } else if(buttonIndex == 0) { [self openAllRoutes]; } } if (alertView.tag == 005) { [self openAllRoutes]; } if ( alertView.tag == 006){ [alertView close]; } [alertView close]; } #pragma mark - FREE ROUTES - (void) doOpenFreeRoutes { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; if([DATAMANAGER testInternetConnection] == FALSE){ [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"FunctionNotAvailable", nil) tag:006]; }else{ [NXTNetwork doSearchRoutesWithSuccess:@"" onlyFree:YES successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; if([DATAMANAGER errorInside:response] == nil) { [self goToFreeRoutesController:[NXTParser doParseRoutes:response] isForAllRoutes:YES]; } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; }]; } } #pragma mark - GPS Methods - (void) getLocation { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; if([DATAMANAGER testInternetConnection] == FALSE){ [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"FunctionNotAvailable", nil) tag:006]; }else{ if ( [CLLocationManager locationServicesEnabled] == YES && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) { if (locationManager == nil) { locationManager = [[CLLocationManager alloc] init]; } locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; if (IS_OS_8_OR_LATER && [CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined) { [locationManager requestWhenInUseAuthorization]; } [locationManager startUpdatingLocation]; }else { [ActivityViewFramed hideActivityView]; [DATAMANAGER showGPSAlert:self message:NSLocalizedString(@"ActivateLocalization", nil) tag:001]; } } } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { locationManager = nil; [ActivityViewFramed hideActivityView]; [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"ErrorPosition", nil) tag:005]; } - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation* location = [locations lastObject]; NSDate* eventDate = location.timestamp; NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; if (fabs(howRecent) < 15.0) { // If the event is recent, do something with it. NSLog(@"latitude %+.6f, longitude %+.6f\n", location.coordinate.latitude, location.coordinate.longitude); CLLocationCoordinate2D sessionLocation = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude); [self coordinateLocation:sessionLocation]; [locationManager stopUpdatingLocation]; locationManager = nil; } } - (void) coordinateLocation:(CLLocationCoordinate2D)sessionLocation { CLLocationCoordinate2D sessionLocationForDevice = sessionLocation; [NXTNetwork doGetGeoRoutesWithSuccess:DATAMANAGER.user.token latitude:[NSString stringWithFormat:@"%f",sessionLocationForDevice.latitude] longitude:[NSString stringWithFormat:@"%f",sessionLocationForDevice.longitude] successBlock:^(NSDictionary *response) { [ActivityViewFramed hideActivityView]; if([DATAMANAGER errorInside:response] == nil) { NSMutableDictionary *percorsi = [NXTParser doParseRoutes:response]; if([percorsi count]!=0) { [self goToRoutesController:percorsi isForAllRoutes:YES isFromGeoLocation:YES withGpsPosition:YES]; } else { [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"NoRoutesAvailable", nil) tag:002]; } } } failure:^(NSError *error) { [ActivityViewFramed hideActivityView]; // DA FARE }]; } -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if (status ==kCLAuthorizationStatusDenied) { NSLog(@"AUTORIZZAZIONE RIFIUTATA"); [ActivityViewFramed hideActivityView]; } } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if([touch.view class] == self.tab.class){ return NO; } return YES; } -(void)dismissKeyboard{ [self.searchBar resignFirstResponder]; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Controllers/HomeVC/HomeVC.m
Revision | Author | Commited | Message |
---|---|---|---|
789
![]() |
![]() |
Wed 30 Sep, 2015 10:29:27 +0000 | v.1 b.032 |
722
![]() |
![]() |
Tue 08 Sep, 2015 13:42:51 +0000 | fixed sent score route |
600
![]() |
![]() |
Fri 28 Aug, 2015 10:15:21 +0000 | fixed bug routes |
595
![]() |
![]() |
Thu 27 Aug, 2015 15:20:48 +0000 | FOLDER UPDATE AFTER CRASHLYTHICS UPDATE |
573
![]() |
![]() |
Wed 26 Aug, 2015 14:27:40 +0000 | AGGIUNTO PARSER PER AVERE ETICHETTE PERCORSI UGUALI SIA UN PERCORSI GRATUITI CHE IN I MIEI PERCORSI |
536
![]() |
![]() |
Mon 24 Aug, 2015 13:48:30 +0000 | Bug fixing |
502
![]() |
![]() |
Thu 13 Aug, 2015 13:53:08 +0000 | aggiunto salavataggio img offline con la routebyID |
499
![]() |
![]() |
Thu 13 Aug, 2015 08:42:15 +0000 | added zoom to image poi |
498
![]() |
![]() |
Wed 12 Aug, 2015 12:27:23 +0000 | added Alphabetical order with no gps coor |
497 |
![]() |
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 |