Subversion Repository Public Repository

Nextrek

Diff Revisions 660 vs 691 for /Android/SmartCharging/SmartCharging_WP/SmartCharging/MapPage.xaml.cs

Diff revisions: vs.
  @@ -49,6 +49,7 @@
49 49 private ErrorHandler errorHandler;
50 50 double defaultLat, defaultLon;
51 51 int defaultZoom;
52 + private UserLocationHelper userLocationHelper;
52 53
53 54 public event PropertyChangedEventHandler PropertyChanged;
54 55 private SiteType selectedSiteType;
  @@ -77,6 +78,7 @@
77 78 resourceLoader = ResourceLoader.GetForCurrentView("Resources");
78 79 config = Config.Instance;
79 80 errorHandler = new ErrorHandler();
81 + userLocationHelper = new UserLocationHelper();
80 82 this.SMA = SmartChargeAPI.Instance;
81 83 }
82 84
  @@ -122,12 +124,12 @@
122 124 Longitude = defaultLon
123 125 });
124 126 MapControl.LandmarksVisible = true;
125 -
126 -
127 +
127 128 MapControl.Center = center;
128 129 MapControl.ZoomLevel = defaultZoom;
129 130 this.showLoading();
130 - Geopoint userLocation = await GetUserLocation();
131 +
132 + Geopoint userLocation = await userLocationHelper.GetUserLocation();
131 133 if (userLocation != null)
132 134 {
133 135
  @@ -161,7 +163,7 @@
161 163 }
162 164 else
163 165 {
164 - await this.AskForGps();
166 + await userLocationHelper.AskForGps();
165 167
166 168 }
167 169
  @@ -184,118 +186,7 @@
184 186
185 187 return await this.SMA.GetSites(position.Position, 500000, type);
186 188
187 - /*string lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
188 - ObservableCollection<Review> reviews = new ObservableCollection<Review>();
189 - reviews.Add(new Review() { ReviewerName = "Fabio", Chargers = 3, Description = lorem });
190 - reviews.Add(new Review() { ReviewerName = "Marco", Chargers = 4, Description = lorem });
191 - reviews.Add(new Review() { ReviewerName = "Patricco", Chargers = 1, Description = lorem });
192 - reviews.Add(new Review() { ReviewerName = "Michele", Chargers = 4, Description = lorem });
193 - reviews.Add(new Review() { ReviewerName = "Felice", Chargers = 2, Description = lorem });
194 -
195 -
196 - List<Site> POIs = new List<Site>();
197 - POIs.Add(new Site()
198 - {
199 - Id = "1",
200 - Name = "Locale1",
201 - Chargers = 1,
202 - Type = new SiteType() { Id = "0", Label = "Bar" },
203 - Address = "Via di casa mia 54",
204 - IconImageUrl = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRJJkFIfxS2b_x3Zhv-rcBY3xpnVIdmdaPQ4lIjzpXxWPOLSaHx0GDif9s",
205 - SiteImageUrls = new List<string>(){"https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRJJkFIfxS2b_x3Zhv-rcBY3xpnVIdmdaPQ4lIjzpXxWPOLSaHx0GDif9s",
206 - "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRJJkFIfxS2b_x3Zhv-rcBY3xpnVIdmdaPQ4lIjzpXxWPOLSaHx0GDif9s"},
207 - Description = "Locale dove si mangia",
208 - ReviewList = new ObservableCollection<Review>(reviews.Take(2)),
209 - Position = new Geopoint(new BasicGeoposition()
210 - {
211 - Latitude = 41.903128,
212 - Longitude = 12.455819
213 - }),
214 - NormalizedPoint = new Point(.5, .5)
215 - });
216 -
217 - POIs.Add(new Site()
218 - {
219 - Id = "2",
220 - Name = "Locale2",
221 - Chargers = 3,
222 - Type = new SiteType() { Id = "0", Label = "Ristorante" },
223 - Address = "Via di casa mia 55",
224 - IconImageUrl = "http://www.lagrottadiscoteca.it/DISCOTECA/FUMATORI/Grotta8.jpg",
225 - SiteImageUrls = new List<string>() { "http://www.lagrottadiscoteca.it/DISCOTECA/FUMATORI/Grotta8.jpg" },
226 - Description = "Locale dove si beve",
227 - ReviewList = new ObservableCollection<Review>(reviews.Take(1)),
228 - Position = new Geopoint(new BasicGeoposition()
229 - {
230 - Latitude = 41.8932513,
231 - Longitude = 12.4901912
232 - }),
233 - NormalizedPoint = new Point(.5, .5)
234 - });
235 -
236 - POIs.Add(new Site()
237 - {
238 - Id = "3",
239 - Name = "Locale3",
240 - Chargers = 5,
241 - Type = new SiteType() { Id = "0", Label = "Birreria" },
242 - Address = "Via di casa mia 56",
243 - IconImageUrl = "http://www.lagrottadiscoteca.it/DISCOTECA/FUMATORI/Grotta8.jpg",
244 - SiteImageUrls = new List<string>(){"http://www.lagrottadiscoteca.it/DISCOTECA/FUMATORI/Grotta8.jpg",
245 - "http://www.lagrottadiscoteca.it/DISCOTECA/FUMATORI/Grotta8.jpg"},
246 - Description = "Locale dove si beve e si mangia",
247 - ReviewList = reviews,
248 - Position = new Geopoint(new BasicGeoposition()
249 - {
250 - Latitude = 41.8666907,
251 - Longitude = 12.4871802
252 - }),
253 - NormalizedPoint = new Point(.5, .5)
254 - });
255 -
256 - POIs.Add(new Site()
257 - {
258 - Id = "4",
259 - Name = "Locale4",
260 - Chargers = 2,
261 - Type = new SiteType() { Id = "0", Label = "Pizzeria" },
262 - Address = "Via di casa mia 57",
263 - Description = "Locale dove si fuma",
264 - ReviewList = new ObservableCollection<Review>(reviews.Take(4)),
265 - IconImageUrl = "http://www.festeprivateroma.com/gallery/locale-feste-zona-prati.jpg",
266 - SiteImageUrls = new List<string>(){"http://www.festeprivateroma.com/gallery/locale-feste-zona-prati.jpg",
267 - "http://www.festeprivateroma.com/gallery/locale-feste-zona-prati.jpg",
268 - "http://www.festeprivateroma.com/gallery/locale-feste-zona-prati.jpg",
269 - "http://www.festeprivateroma.com/gallery/locale-feste-zona-prati.jpg"},
270 - Position = new Geopoint(new BasicGeoposition()
271 - {
272 - Latitude = 41.8730664,
273 - Longitude = 12.5263283
274 - }),
275 - NormalizedPoint = new Point(.5, .5)
276 - });
277 -
278 - POIs.Add(new Site()
279 - {
280 - Id = "5",
281 - Name = "Locale5",
282 - Chargers = 4,
283 - Address = "Via di casa mia 58",
284 - Type = new SiteType() { Id = "0", Label = "Pub" },
285 - IconImageUrl = "http://static.bakeca.it/immagini/641/6414e0e166f53ff07fff82985582a64f.jpg",
286 - SiteImageUrls = new List<string>(){"http://static.bakeca.it/immagini/641/6414e0e166f53ff07fff82985582a64f.jpg",
287 - "http://static.bakeca.it/immagini/641/6414e0e166f53ff07fff82985582a64f.jpg","http://static.bakeca.it/immagini/641/6414e0e166f53ff07fff82985582a64f.jpg"},
288 - Description = "Locale dove si beve e si fuma",
289 - ReviewList = new ObservableCollection<Review>(reviews.Take(3)),
290 - Position = new Geopoint(new BasicGeoposition()
291 - {
292 - Latitude = 41.8787212,
293 - Longitude = 12.5392825
294 - }),
295 - NormalizedPoint = new Point(.5, .5)
296 - });
297 -
298 - return POIs;*/
189 +
299 190 }
300 191
301 192 /// <summary>
  @@ -337,89 +228,7 @@
337 228
338 229 #endregion
339 230
340 - private async Task<bool> AskForGps(){
341 -
342 - MessageDialog dialogbox = new MessageDialog(resourceLoader.GetString("GPSRequestMessage"));
343 -
344 -
345 - //OK Button
346 - UICommand okBtn = new UICommand(resourceLoader.GetString("OK"));
347 - okBtn.Invoked = (s) => {
348 - Launcher.LaunchUriAsync(new Uri("ms-settings-location:"));
349 - };
350 - dialogbox.Commands.Add(okBtn);
351 -
352 -
353 - //Show message
354 - await dialogbox.ShowAsync();
355 - return true;
356 -
357 - }
358 -
359 - private async Task<Geopoint> GetUserLocation()
360 - {
361 - /*get user's position;
362 - * if this operation succeeds
363 - * save the position and continue
364 - * else
365 - * retrieve the last save position
366 - * if no last saved position
367 - * show error message
368 - * else
369 - * continue
370 - */
371 - var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
372 - Geolocator geolocator = new Geolocator();
373 - Geopoint ret;
374 - geolocator.DesiredAccuracyInMeters = 50;
375 - try
376 - {
377 - Geoposition geoposition = await geolocator.GetGeopositionAsync(
378 - maximumAge: TimeSpan.FromMinutes(5),
379 - timeout: TimeSpan.FromSeconds(6)
380 - );
381 -
382 - ret = new Geopoint(new BasicGeoposition()
383 - {
384 - Latitude = geoposition.Coordinate.Point.Position.Latitude,
385 - Longitude = geoposition.Coordinate.Point.Position.Longitude
386 - });
387 - this.SavePosition(ret);
388 -
389 - }
390 - catch
391 - {
392 - ret = this.GetLastSavedPosition();
393 - }
394 -
395 -
396 - return ret;
397 - }
398 -
399 - private Geopoint GetLastSavedPosition()
400 - {
401 - var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
402 - string toBeParsed = (string)localSettings.Values["LastSavedPostition"];
403 - Geopoint ret = null;
404 - if (toBeParsed != null && !toBeParsed.Equals(""))
405 - {
406 - ret = new Geopoint(new BasicGeoposition() {
407 - Latitude = double.Parse(toBeParsed.Split('|')[0]),
408 - Longitude = double.Parse(toBeParsed.Split('|')[1])
409 - });
410 - }
411 - return ret;
412 - }
413 -
414 - private void SavePosition(Geopoint position)
415 - {
416 - var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
417 -
418 - localSettings.Values["LastSavedPostition"] = position.Position.Latitude + "|" + position.Position.Longitude;
419 -
420 -
421 -
422 - }
231 +
423 232
424 233 /*load data for the selected site and apply it as datacontext for ui binding*/
425 234 private async Task setSelectedSite(Site site){