Nextrek
@ 588
Nextrek / iOS / SafariArte / trunk / SafariArte / Commodities / DataManager.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 |
// // DataManager.m // Location // // Created by Fabrizio on 11/12/12. // Copyright (c) 2012 Odyssey. All rights reserved. // #import "DataManager.h" #import "SFAPercorso.h" #import "LoginVC.h" #import "AlertVC.h" #import "SFAPoi.h" @implementation DataManager { Reachability *internetReachable; } #pragma mark - DataManager Initialization static DataManager *instance; +(DataManager *) getInstance { if (!instance) { instance = [[DataManager alloc] init]; } return instance; } - (id) init { if((self = [super init])) { instance = self; } return self; } #pragma mark - Error Management - (NSError *)errorInside:(NSDictionary *)response { if(STR_ISNULL_OR_EMPTY(response[@"error_code"])) return nil; NSLog(@"ERROR CODE: %@", response[@"error_code"]); NSMutableDictionary* details = [NSMutableDictionary dictionary]; [details setValue:response[@"error_message"] forKey:NSLocalizedDescriptionKey]; NSError *error = [NSError errorWithDomain:@"NXTApp" code:[response[@"error_code"] integerValue] userInfo:details]; [ActivityViewFramed hideActivityView]; // [DATAMANAGER showErrorAlert:self message:error.localizedDescription tag:error.code]; return error; } - (void) defineLanguage { NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0]; if ([language rangeOfString:@"en"].location != NSNotFound) { self.user.language = @"en_US"; } else if ([language rangeOfString:@"it"].location != NSNotFound) { self.user.language = @"it_IT"; } else { self.user.language = @"it_IT"; } NSLog(@"USER LANG: %@", self.user.language); } #pragma mark - USER DATA - (void)saveUser { NSString *key = @"appUser"; NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:self.user]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:encodedObject forKey:key]; [defaults synchronize]; // [self loadUser]; } - (void)loadUser { NSString *key = @"appUser"; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *encodedObject = [defaults objectForKey:key]; self.user = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject]; } #pragma mark - UIALERT - (void) showMessageWithAlert:(id)delegate message:(NSString*)message tag:(NSInteger)tag{ CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[self createAlertViewWithMessage:@"Safari D'Arte" :message]]; [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil]]; [alertView setDelegate:delegate]; [alertView setUseMotionEffects:true]; alertView.tag=tag; [alertView show]; } - (void) showAlert:(id)delegate withTitle:(NSString*)title message:(NSString*)message tag:(NSInteger)tag{ CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[self createAlertViewWithMessage:title :message]]; [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"Ok", nil), nil]]; [alertView setDelegate:delegate]; [alertView setUseMotionEffects:true]; alertView.tag=tag; [alertView show]; } - (void) showErrorAlert:(id)delegate message:(NSString*)message tag:(NSInteger)tag { CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[self createAlertViewWithMessage:@"Safari D'Arte" :message]]; [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"Ok", nil), nil]]; alertView.tag=tag; [alertView setDelegate:delegate]; [alertView setUseMotionEffects:true]; [alertView show]; } - (void) showErrorAlert2Btns:(id)delegate message:(NSString*)message tag:(NSInteger)tag { CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[self createAlertViewWithMessage:@"Safari D'Arte" :message]]; [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"Yes", nil), NSLocalizedString(@"No", nil), nil]]; alertView.tag=tag; [alertView setDelegate:delegate]; [alertView setUseMotionEffects:true]; [alertView show]; } - (void) showGPSAlert:(id)delegate message:(NSString*)message tag:(NSInteger)tag { CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[self createAlertViewWithMessage:@"Safari D'Arte" :message]]; [alertView setButtonTitles:[NSMutableArray arrayWithObjects:NSLocalizedString(@"Cancel", nil), NSLocalizedString(@"menu_4", nil), nil]]; alertView.tag=tag; [alertView setDelegate:delegate]; [alertView setUseMotionEffects:true]; [alertView show]; } - (UIView *)createAlertViewWithMessage:(NSString*)title :(NSString *)message { NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"AlertVC" owner:self options:nil]; UIView *aView = [[nibObjects objectAtIndex:0]initWithMessage:title :message]; return aView; } - (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex { if(alertView.tag == 107 || alertView.tag == 101) { LoginVC *loginVC = [[LoginVC alloc] init]; APPDEL.nc.viewControllers = @[loginVC]; } [alertView close]; } #pragma mark - POIs Management - Stored data - (void) savePOIforRoute:(SFAPercorso*)route poiIndex:(NSNumber*)poiIndex { [self.user.poiForRoute setObject:poiIndex forKey:route.routeId]; [DATAMANAGER saveUser]; } - (void) clearPOIforRoute:(SFAPercorso*)route { [self.user.poiForRoute setObject:[NSNumber numberWithInt:0] forKey:route.routeId]; [DATAMANAGER saveUser]; } - (NSNumber*) poiForRoute:(SFAPercorso*)route { NSNumber *poiIndexForARoute = [self.user.poiForRoute objectForKey:route.routeId]; return poiIndexForARoute; } -(void) resetPoisForRoute:(SFAPercorso*)route { SFAPercorso *percorso = (SFAPercorso*)[self.user.percorsi objectForKey:route.routeId]; for(SFAPoi *poi in percorso.routePois) { [poi setStatus:@""]; } [self saveUser]; } #pragma mark - SET DURATION ROUTES - (NSArray *) setDurationRoutes:(NSString *)duration{ int milliseconds = [duration intValue]; int seconds = milliseconds / 1000.0; int minutes = seconds / 60.0; int finalMinutes= minutes % 60; int hours = minutes / 60.0; return @[[NSString stringWithFormat:@"%ih e %imin",hours,finalMinutes] , duration] ; } #pragma mark - SET ROUTE LENGTH - (NSArray *) setRouteLength:(NSString *)length{ float len = [length floatValue]; float km = len /1000; // int metri = len % 1000; // NSString *mt = [NSString stringWithFormat:@"%i", metri]; float miles = km / 0.6214; return @[[NSString stringWithFormat:@"%.02f mi",miles] , [NSString stringWithFormat:@"%.02f Km",km] , length] ; } #pragma - SET DISTANCE TO ME - (NSArray *) setDistanceToMe:(NSString *)distanceToMe{ float len = [distanceToMe floatValue]; float km = len /1000; float miles = km / 0.6214; return @[[NSString stringWithFormat:@"%.02f mi",miles] , [NSString stringWithFormat:@"%.02f Km",km] , distanceToMe] ; } #pragma mark - Timer -(void)timeInc{ DATAMANAGER.secondsCount =[NSNumber numberWithInt:[DATAMANAGER.secondsCount intValue]+1]; } -(BOOL) saveTimerForRouteID:(SFAPercorso*)route { NSLog(@"%@ %@",route.routeId,DATAMANAGER.secondsCount); [DATAMANAGER.user.timeForRoute setObject:DATAMANAGER.secondsCount forKey:route.routeId]; [DATAMANAGER saveUser]; return YES; } -(BOOL) resetTimerForRouteID:(SFAPercorso*)route { // NSLog(@"%@ %@",route.routeId,DATAMANAGER.secondsCount); [DATAMANAGER.user.timeForRoute setObject:[NSNumber numberWithInt:0] forKey:route.routeId]; [DATAMANAGER saveUser]; return YES; } -(BOOL) saveClues:(SFAPercorso*)route { NSNumber *clues=[DATAMANAGER.user.cluesForRoute objectForKey:route.routeId]; [DATAMANAGER.user.cluesForRoute setObject:[NSNumber numberWithInt:[clues intValue]+1] forKey:route.routeId] ; [DATAMANAGER saveUser]; return YES; } -(NSString *)getTime{ NSNumber *seconds=[NSNumber numberWithInt:[DATAMANAGER.secondsCount intValue]]; return [self printTimer:seconds]; } - (NSString *)printTimer:(NSNumber*)nSeconds{ int hours= [nSeconds intValue] / 3600; int seconds= [nSeconds intValue] % 3600; int minutes = seconds / 60; seconds = seconds % 60; return [NSString stringWithFormat:@"%02d:%02d:%02d", (int)hours,(int)minutes,(int)seconds]; } - (NSString *)getTimeForRoute:(SFAPercorso*)route{ NSNumber *seconds=[NSNumber numberWithInt:[[DATAMANAGER.user.timeForRoute objectForKey:route.routeId ] intValue]]; return [self printTimer:seconds]; } #pragma mark - Color Tableview - (void)setCellColorforTableview:(UITableView*)tableview withColor:(UIColor *)color forIndexPath:(NSIndexPath*)indexPath andDuration:(int)duration{ [UIView animateWithDuration:duration animations:^{ [[tableview cellForRowAtIndexPath:indexPath] setBackgroundColor:color]; } completion:^(BOOL finished) { [[tableview cellForRowAtIndexPath:indexPath] setBackgroundColor:color]; }]; } - (NSString*) km2mile:(float)km{ int miles= km / 0.6214; return [NSString stringWithFormat:@"%i mi",miles]; } #pragma Test Internet Connection - (BOOL)testInternetConnection { internetReachable = [Reachability reachabilityWithHostname:@"www.google.com"]; if (internetReachable.isReachable) return TRUE; else return FALSE; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Commodities/DataManager.m
Revision | Author | Commited | Message |
---|---|---|---|
588 Diff | PBonamassa | Thu 27 Aug, 2015 13:39:33 +0000 | fixed bug |
568 Diff | PBonamassa | Wed 26 Aug, 2015 09:47:30 +0000 | fixed bug timer & image final quiz |
536 Diff | PBonamassa | Mon 24 Aug, 2015 13:48:30 +0000 | Bug fixing |
534 Diff | FAquili | Mon 24 Aug, 2015 13:15:05 +0000 | Bug fixing |
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 |
487 Diff | PBonamassa | Fri 07 Aug, 2015 15:04:09 +0000 | fixed bug score sent, added other icon & localize string |
482 Diff | PBonamassa | Thu 06 Aug, 2015 07:23:06 +0000 | change text color alert – added alert to button stepOver in PoiVC – removed button StepOver in |
453 Diff | PBonamassa | Thu 30 Jul, 2015 15:25:09 +0000 | added sound Frocix |
444 Diff | FPompili | Tue 28 Jul, 2015 14:26:36 +0000 | added customAlertView |
419 | FPompili | Wed 22 Jul, 2015 11:15:17 +0000 | added order by lenght and duration inside routesvc |