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
//
//  MapItemDetailVC.m
//  Location
//
//  Created by Fabrizio on 07/12/12.
//  Copyright (c) 2012 Odyssey. All rights reserved.
//

#import "MapItemDetailVC.h"
#import "MapAnnotation.h"
#import "MKCustomAnnotationView.h"

@interface MapItemDetailVC () {
    UIButton *fakeStarButton;
}

@end

@implementation MapItemDetailVC

@synthesize mapView;
@synthesize starI;
@synthesize starII;
@synthesize starIII;
@synthesize voteButton;
@synthesize backBtn;
@synthesize mapItem;
@synthesize indirizzoLabel;
@synthesize origin;
@synthesize votedView;

- (id)initWithMapItem:(MapItem *)aMapItem {
    self = [super initWithNibName:@"MapItemDetailVC" bundle:nil];
    if (self) {
        self.mapItem = aMapItem;
        
        fakeStarButton = [[UIButton alloc]init];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void) viewWillAppear:(BOOL)animated {
    
    if(mapItem.votes != 0) {
        votedView.hidden = NO;
        voteButton.enabled = NO;
    }
    else {
        votedView.hidden = YES;
        voteButton.enabled = YES;
    }
    
    starI_Selected = NO;
    starII_Selected = NO;
    starIII_Selected = NO;
    
    LOG_INFO_X(@"Voti inizializzazione: %d", mapItem.votes);
    fakeStarButton.tag = mapItem.votes;
    
    [self doSelectStar:fakeStarButton];
    
    CLLocationCoordinate2D coord = {.latitude = mapItem.lat , .longitude = mapItem.lon};
	
	MKCoordinateSpan span = {.latitudeDelta = 0.002, .longitudeDelta = 0.002};
	MKCoordinateRegion region = {coord, span};
	[mapView setRegion:region];
        
    MapAnnotation *mapItemAnnotation = [[MapAnnotation alloc] initWithCoordinate:coord  item:mapItem];
    [mapView addAnnotation:mapItemAnnotation];
    
    UIImage *from_map = [UIImage imageNamed:@"map.png"];
    UIImage *from_table = [UIImage imageNamed:@"menu.png"];
    
    switch (origin) {
        //MAP VIEW
        case 1:
            [backBtn setImage:from_map forState:UIControlStateNormal];
            break;
        //TABLE VIEW
        case 2:
            [backBtn setImage:from_table forState:UIControlStateNormal];
            break;
            
        //NEAREST BUTTON
        case 3:
            [backBtn setImage:from_map forState:UIControlStateNormal];
            [self showRoute];
            break;
            
        default:
            break;
    }
    
    indirizzoLabel.text = [NSString stringWithFormat:@"%@, %@", mapItem.indirizzo, mapItem.numero];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma -
#pragma MKAnnotationView handle

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation {
	
	if (! [annotation isKindOfClass:[MapAnnotation class]]) {
		return nil;
	}
    
	MKCustomAnnotationView *annView = [[MKCustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
	
	annView.frame = CGRectMake(0, 0, 38, 37);
    
	NSString *imgName = @"map_ico.png";
    annView.image = [UIImage imageNamed:imgName];
    
	return annView;
}

#pragma -
#pragma IBActions

- (IBAction) doBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)doSelectStar:(id)sender {
    
    UIButton *star = (UIButton*)sender;
    
    UIImage *star_full = [UIImage imageNamed:@"star_full.png"];
    UIImage *star_empty = [UIImage imageNamed:@"star_empty.png"];
    
    switch (star.tag) {
        case 1: {
            [starI setImage:star_full forState:UIControlStateNormal];
            [starII setImage:star_empty forState:UIControlStateNormal];
            [starIII setImage:star_empty forState:UIControlStateNormal];
            break;
        }
        case 2: {
            [starI setImage:star_full forState:UIControlStateNormal];
            [starII setImage:star_full forState:UIControlStateNormal];
            [starIII setImage:star_empty forState:UIControlStateNormal];
            break;
        }

        case 3: {
            [starI setImage:star_full forState:UIControlStateNormal];
            [starII setImage:star_full forState:UIControlStateNormal];
            [starIII setImage:star_full forState:UIControlStateNormal];
            break;
        }
        default: {
            [starI setImage:star_empty forState:UIControlStateNormal];
            [starII setImage:star_empty forState:UIControlStateNormal];
            [starIII setImage:star_empty forState:UIControlStateNormal];
            break;

        }
//        break;
    }
    
    votesForItem = star.tag;
}

- (IBAction) doVote {
    
    LOG_INFO_X(@"Indice: %d", [[DataManager getInstance].mapItems indexOfObject:mapItem]);
    
    ((MapItem*)[[DataManager getInstance].mapItems objectAtIndex:[[DataManager getInstance].mapItems indexOfObject:mapItem]]).votes = votesForItem;
    
    votedView.hidden = NO;
    voteButton.enabled = NO;
}

- (IBAction) showRoute {
	NSString* url;
	if ([DataManager getInstance].lastLocation)	{
                
		url = [NSString stringWithFormat:@"maps://maps.google.com/maps?xyz=xyz&saddr=%0.10f,%0.10f&daddr=%0.10f,%0.10f",[DataManager getInstance].lastLocation.coordinate.latitude,[DataManager getInstance].lastLocation.coordinate.longitude,mapItem.lat,mapItem.lon];
	}
	else {
		NSString *latlong = [NSString stringWithFormat:@"%0.10f,%0.10f",mapItem.lat,mapItem.lon];
		
		url = [NSString stringWithFormat: @"http://maps.google.com/maps?ll=%@",
               [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
		
	}
    
	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}

@end

Commits for Nextrek/iOS/Location/Location/MapItemDetailVC.m

Diff revisions: vs.
Revision Author Commited Message
63 FAquili picture FAquili Sat 18 Jan, 2014 16:59:40 +0000

Parcheggio Roma 1.0