Subversion Repository Public Repository

Nextrek

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
//
//  FinalQuizVC.m
//  SafariArte
//
//  Created by Pier Domenico Bonamassa on 08/07/15.
//  Copyright (c) 2015 Nextrek. All rights reserved.
//

#import "FinalQuizVC.h"
#import <Social/Social.h>
#import "Reachability.h"
#import "SFAPercorso.h"
#import "GenericWebViewVC.h"
#import "FinalQuiz1Cell.h"
#import "FInalQuiz2Cell.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>



@interface FinalQuizVC ()<FBSDKSharingDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *labelName;
@property (weak, nonatomic) IBOutlet UILabel *labelRoute;
@property (weak, nonatomic) IBOutlet UIButton *classificaBtn;
@property (weak, nonatomic) IBOutlet UIButton *btnShareFB;
@property (weak, nonatomic) IBOutlet UIButton *btnHome;
@property (weak, nonatomic) IBOutlet UIButton *btnSendResult;

@end


@implementation FinalQuizVC {
    Reachability *internetReachable;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self.navigationItem setHidesBackButton:YES];

    self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    self.btnSendResult.titleLabel.text = NSLocalizedString(@"SendResult", nil);
    
    self.btnHome.titleLabel.text = NSLocalizedString(@"NewRoute", nil);
    
    self.btnShareFB.titleLabel.text = NSLocalizedString(@"ShareFb", nil);
    
    self.classificaBtn.titleLabel.text = NSLocalizedString(@"Ranking", nil);
    
    self.title = NSLocalizedString(@"RouteEnd", nil);
    
    if ([DATAMANAGER.user.name isEqualToString:@"Anonimo"]){
        [self.image setImage:[UIImage imageNamed:@"male_user"]];
        
    }else {
        if ([DATAMANAGER.user.sex isEqualToString:@"M"]){
            
            [self.image setImage:[UIImage imageNamed:@"male_user"]];
            
        }else{
            [self.image setImage:[UIImage imageNamed:@"female_user"]];
        }
    }
    self.labelRoute.text=self.routeForDetail.routeLabel;
    self.labelName.text = DATAMANAGER.user.name;
        
    [DATAMANAGER clearPOIforRoute:self.routeForDetail];
    
    [self.table reloadData];
    
    [DATAMANAGER showMessageWithAlert:self message:[NSString stringWithFormat:NSLocalizedString(@"FBPopup", nil),self.routeForDetail.routeLabel] tag:004];
    
}

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    


}


#pragma mark - Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row==3) {
        return 141.0f;
    }
   return 44.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    

    if (indexPath.row == 3) {
        
        FInalQuiz2Cell * cell = (FInalQuiz2Cell *)[tableView dequeueReusableCellWithIdentifier:@"FInalQuiz2Cell"];
        
        if (cell == nil)	{
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"FInalQuiz2Cell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
            cell.labelTitleCell.text = NSLocalizedString(@"ValutationTitle", nil);
       
        if ([[DATAMANAGER.user.pointsForRoute objectForKey:self.routeForDetail.routeId] intValue]> 702) {
            
            cell.textViewCell.text = NSLocalizedString(@"masterHunter", nil);
        
        }else if([[DATAMANAGER.user.pointsForRoute objectForKey:self.routeForDetail.routeId] intValue]< 546){
        
            cell.textViewCell.text =NSLocalizedString(@"hunterApprentice", nil);
        
        }else{
            
            cell.textViewCell.text = NSLocalizedString(@"professionalHunter", nil);
        }
            
        cell.separatorInset=UIEdgeInsetsMake(0.f, self.view.frame.size.width, 0.f, 0.f);
        [cell.textViewCell setFont:[UIFont systemFontOfSize:16.0]];

        
        return cell;

        }else {
        
        NSArray *images=@[@"timerFinal",@"clip",@"flag"];
        
        NSArray *title=@[ NSLocalizedString(@"TimeElapsed", nil) ,NSLocalizedString(@"CluesFound", nil),NSLocalizedString(@"FinalScore", nil)];
       
        NSArray *values=@[[DATAMANAGER getTimeForRoute:self.routeForDetail],[NSString stringWithFormat:@"%i",[[DATAMANAGER.user.cluesForRoute objectForKey:self.routeForDetail.routeId] intValue]], [NSString stringWithFormat:@"%i", [[DATAMANAGER.user.pointsForRoute objectForKey:self.routeForDetail.routeId] intValue ]]] ;
        
        FinalQuiz1Cell *cell = (FinalQuiz1Cell *)[tableView dequeueReusableCellWithIdentifier:@"FinalQuiz1Cell"];
    
        if (cell == nil)	{
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"FinalQuiz1Cell" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }
            
            [cell.imageCell setImage:[UIImage imageNamed:images[indexPath.row]]];
            cell.labelCell.text = title[indexPath.row];
            cell.valueLabelCell.text = values[indexPath.row];
            
            
        
        return cell;

}

    
    }
  




#pragma mark - Share results on Facebook

- (IBAction)doShareResultToFB:(id)sender {
    
    
   

    
  // FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
  // photo.image=[UIImage imageNamed:self.routeForDetail.routeFileImg];
    
    // Create an object
    NSDictionary *properties = @{
                                 @"og:type": @"article",
                                 @"og:title": @"Safari D'arte iOS",
                                 @"og:description": [NSString stringWithFormat:NSLocalizedString(@"FBSharingMessage", 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];

    
}
- (IBAction)sendScoreToServer:(id)sender {
    
    if (![self testInternetConnection]) {
        

        
        NSLog(@"PUNTEGGIO FINALEEEEEE : %@ , routeID : %@",[DATAMANAGER.user.scoreRoute objectForKey:self.routeForDetail.routeId] , self.routeForDetail.routeId);
        
        [DATAMANAGER showErrorAlert:self message:NSLocalizedString(@"PleaseTryAgain", nil) tag:102];
        
    }
    
    else {
    
    [ActivityViewFramed showActivityWithSuperView:APPDEL.window];
    


    [NXTNetwork doSetScoreWithSuccess:self.routeForDetail.routeId score:[DATAMANAGER.user.pointsForRoute 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 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];
    }];
    
    }
}

#pragma mark - IBAction

- (IBAction)goToHome:(id)sender {
    
    //added for reset timer
    [DATAMANAGER resetTimerForRouteID:self.routeForDetail];
    [DATAMANAGER.user.poiForRoute setObject:@"-2" forKey:self.routeForDetail.routeId];
    [DATAMANAGER saveUser];
    [self.navigationController popToRootViewControllerAnimated:TRUE];
}

- (IBAction) doOpenClassifica {
    
    
    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 - MemoryWarning

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (BOOL)testInternetConnection
{
    internetReachable = [Reachability reachabilityWithHostname:@"www.google.com"];
    
    
    if (internetReachable.isReachable)
        return TRUE;
    else
        return FALSE;
    
}

- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
   
    if(alertView.tag == 02) {
        [alertView close];
        
        
        [self goToHome:self];
     
    }
    if (alertView.tag == 004) {
        if (buttonIndex == 0) {
            
            
            NSDictionary *properties = @{
                                         @"og:type": @"article",
                                         @"og:title": @"Safari D'arte iOS",
                                         @"og:description": [NSString stringWithFormat:NSLocalizedString(@"FBSharingMessage", 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
        {
            [alertView close];
        }
        
        

    }if(alertView.tag == 103 || alertView.tag == 105 || alertView.tag == 102)  {
        
        [alertView close];
    }
}


#pragma mark - FBSDKSharingDelegate

- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
    
    NSLog(@"Facebook sharing completed: %@", results);
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
    
    NSLog(@"Facebook sharing failed: %@", error);
}

- (void) sharerDidCancel:(id<FBSDKSharing>)sharer {
    
    NSLog(@"Facebook sharing cancelled.");
}
@end

Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Controllers/FinalQuizVC/FinalQuizVC.m

Diff revisions: vs.
Revision Author Commited Message
831 Diff Diff FPompili picture FPompili Sat 24 Oct, 2015 07:24:22 +0000

final

801 Diff Diff FPompili picture FPompili Thu 15 Oct, 2015 17:42:20 +0000

release 0.39

742 Diff Diff PBonamassa picture PBonamassa Wed 16 Sep, 2015 09:15:34 +0000

changed userImage , distanceToMeImage & message facebook.

724 Diff Diff PBonamassa picture PBonamassa Wed 09 Sep, 2015 06:42:24 +0000

fixed sent score route & final valutation

722 Diff Diff PBonamassa picture PBonamassa Tue 08 Sep, 2015 13:42:51 +0000

fixed sent score route

693 Diff Diff FPompili picture FPompili Mon 07 Sep, 2015 06:09:19 +0000

rimossa la richiesta del permesso “publish action” nel login fb
aggiunto caricamento delle immagini dalla cache nella lista dei poi fatti/da fare...
aggiunto caricamento dell’immagine corretta (uomo/donna) nel riepilogo finale del percorso

673 Diff Diff PBonamassa picture PBonamassa Fri 04 Sep, 2015 12:53:28 +0000

modified dimension font

655 Diff Diff PBonamassa picture PBonamassa Wed 02 Sep, 2015 13:34:39 +0000

added final valutation

610 Diff Diff PBonamassa picture PBonamassa Fri 28 Aug, 2015 15:06:12 +0000

fixed bug alert

568 PBonamassa picture PBonamassa Wed 26 Aug, 2015 09:47:30 +0000

fixed bug timer & image final quiz