Exemplo n.º 1
0
		private async Task LoadCrueltySpots()
		{
			var crueltySpotsService = new CrueltySpotsService ();

			List<String> categories = UserPreferencesHelper.GetFilterCategories ();
			GeoQueryRequest geoQueryRequest = null;
			if (UserPreferencesHelper.getClosestSpotsFilter () == true) {
				geoQueryRequest = new GeoQueryRequest ();
				geoQueryRequest.Latitude = _gpsTracker.Latitude;
				geoQueryRequest.Longititude = _gpsTracker.Longitude;
				geoQueryRequest.DistanceInMiles = 50;
			}

			if (!categories.Any()) {
				if (geoQueryRequest != null) {
				
					_crueltySpots = await crueltySpotsService.GetManyAsync (geoQueryRequest, 
					                                                        true, 
					                                                        CrueltySpotSortField.CreatedAt,
					                                                        SortDirection.Asc);
				} 
				else {
					_crueltySpots = await crueltySpotsService.GetAllAsync (true);
				}


			} else {
				if (geoQueryRequest != null) {
					_crueltySpots = await crueltySpotsService.GetManyAsync (geoQueryRequest, categories, true, CrueltySpotSortField.CreatedAt, SortDirection.Asc);
				} else {
					_crueltySpots = await crueltySpotsService.GetManyAsync (categories, true, CrueltySpotSortField.CreatedAt, SortDirection.Asc);
				}
			}

			if (_crueltySpots.Any ()) {
				fa.RunOnUiThread (() => {
					_crueltySpotsList.Adapter = new CrueltySpotsAdapter (fa, _crueltySpots);
					_loadingDialog.Dismiss();

				});               
			} else {
                _loadingDialog.Dismiss();
				// ToDo: Handle case where there are no cruelty spots
			}           
		}