Example #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
			}           
		}
Example #2
0
        public async void SetupMapIfNeeded()
        {
            if (_map == null && _mapFragment != null)
            {
                _map = _mapFragment.Map;
            }
            if (_map != null)
            {

                LatLng myLocation = new LatLng(_gpsTracker.Latitude, _gpsTracker.Longitude);
                _crueltySpotsService = new CrueltySpotsService();


                _map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(myLocation, 11));

                List<String> categories = UserPreferencesHelper.GetFilterCategories();

                DebugHelper.WriteDebugEntry("Fetched categories for mapping (" + categories.Count + ")");

                if (!categories.Any())
                {
                    _crueltySpots = await _crueltySpotsService.GetManyAsync(new CrueltySpot(), true, CrueltySpotSortField.CreatedAt, SortDirection.Asc);

                }
                else
                {
                    _crueltySpots = await _crueltySpotsService.GetManyAsync(categories, true, CrueltySpotSortField.CreatedAt, SortDirection.Asc);
                }

                DebugHelper.WriteDebugEntry("Fetched CrueltySPots for mapping");

                RunOnUiThread(() =>
                              {
                                  MarkerOptions mapOption;
                                  LatLng crueltyLocation;
                                  LatLngBounds.Builder builder = new LatLngBounds.Builder();
                                  builder.Include(myLocation);
                                  foreach (CrueltySpot spot in _crueltySpots)
                                  { // Loop through List with foreach
                                      if (spot.Name.CompareTo("Universoul Circus") == 0)
                                      {
                                          continue;
                                      }
                                      crueltyLocation = new LatLng(spot.Latitude, spot.Longitude);
                                      builder.Include(crueltyLocation);

                                      float defaultValue = 33;

                                      if (_pinColorLookup.ContainsKey(spot.CrueltySpotCategory.IconName.Replace(".png", "pin")))
                                      {
                                          defaultValue = _pinColorLookup[spot.CrueltySpotCategory.IconName.Replace(".png", "pin")];
                                      }
                                      mapOption = new MarkerOptions()
                                          .SetPosition(crueltyLocation)
                                              .SetSnippet(spot.Address)
                                              .SetTitle(spot.Name)
                                              .InvokeIcon(BitmapDescriptorFactory.DefaultMarker(defaultValue));

                                      Marker marker = _map.AddMarker(mapOption);

                                      _crueltyLookup.Add(marker.Id, spot);

                                  }


                                  // Move the map so that it is showing the markers we added above.
                                  _map.SetInfoWindowAdapter(new CustomInfoWindowAdapter(this));

                                  // Set listeners for marker events.  See the bottom of this class for their behavior.

                                  _map.SetOnInfoWindowClickListener(this);
                              });
            }

        }
Example #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.AddPlace);

            _placeNameInput = FindViewById<EditText>(Resource.Id.PlaceName);
            _addressInput = FindViewById<EditText>(Resource.Id.StreetAddress);
            _cityInput = FindViewById<EditText>(Resource.Id.City);
            _stateInput = FindViewById<EditText>(Resource.Id.State);
            _zipInput = FindViewById<EditText>(Resource.Id.Zip);
            _submitButton = FindViewById<Button>(Resource.Id.SubmitButton);
            _submitButton.Enabled = false;

            var gpsTracker = ((AfaApplication)ApplicationContext).GetGpsTracker(this);

            var geocoder = new Geocoder(this, Locale.Default);
            var addresses = geocoder.GetFromLocation(gpsTracker.Latitude, gpsTracker.Longitude, 1);
            var myAddress = addresses.FirstOrDefault();
            if (myAddress != null)
            {
                var streetAddress = myAddress.GetAddressLine(0);
                //var city = address.SubAdminArea; // RETURNS NOTHING
                //var city = address.Locality; // RETURNS NOTHING
                //var city = myAddress.SubLocality; // e.g. Brooklyn

                // Try to get a city
                string city = myAddress.SubLocality;
                if (String.IsNullOrEmpty(city))
                {
                    city = myAddress.Locality;
                }

                var state = myAddress.AdminArea; // e.g. New York
                var zip = myAddress.PostalCode;

                if (!String.IsNullOrEmpty(streetAddress))
                {
                    _addressInput.Text = streetAddress;
                }

                if (!String.IsNullOrEmpty(city))
                {
                    _cityInput.Text = city;
                }

                if (!String.IsNullOrEmpty(state))
                {
                    _stateInput.Text = state;
                }

                if (!String.IsNullOrEmpty(zip))
                {
                    _zipInput.Text = zip;
                }
            }

            _placeNameInput.AfterTextChanged += (sender, args) => ValidateInput();
            _cityInput.AfterTextChanged += (sender, args) => ValidateInput();
            _stateInput.AfterTextChanged += (sender, args) => ValidateInput();

            _submitButton.Click += async delegate(object sender, EventArgs args)
                {
                    var validInput = ValidateInput();
                    if (!validInput)
                    {
                        DialogManager.ShowAlertDialog(this, "Incomplete Submission",
                                                           "Please supply a Name, City and State",
                                                           false);
                    }
                    else
                    {
                        var loadingDialog = DialogManager.ShowSubmittingDialog(this);
                        var name = _placeNameInput.Text;
                        var address = _addressInput.Text;
                        var city = _cityInput.Text;
                        var stateInput = _stateInput.Text;
                        var zipInput = _zipInput.Text;
                        var stateAbbreviation = stateInput.Length == 2 ? stateInput : StateNamesAndAbbreviations.StateAbbreviationLookup[stateInput];

                        var crueltySpotsService = new CrueltySpotsService();
                        var crueltySpots = await crueltySpotsService.GetManyAsync(new CrueltySpot
                                                                           {
                                                                               Name = name,
                                                                               City = city,
                                                                               StateProvinceAbbreviation = stateAbbreviation
                                                                           }, false, CrueltySpotSortField.CreatedAt, SortDirection.Asc);

                        RunOnUiThread(()
                            =>
                            {
                                if (crueltySpots.Any())
                                {
                                    //var existingPlaceId = crueltySpots.First().Id;
                                    var existingPlaceId = crueltySpots.First().ObjectId;

                                    new AlertDialog.Builder(this)
                                        .SetTitle("Cruelty already reported here")
                                        .SetMessage("The location you have chosen is already on the cruelty map.")
                                        .SetNegativeButton("Cancel", (o, args1) => { })
                                        .SetPositiveButton("Edit Info", (o, args1) =>
                                            {
                                                var intent = new Intent(this,typeof(CrueltySpotActivity));
                                                intent.PutExtra(AppConstants.CrueltySpotIdKey, existingPlaceId);
                                                StartActivity(intent);
                                            })
                                        .Show();
                                }
                                else
                                {
                                    CrueltyReport _crueltyReport = ((AfaApplication)ApplicationContext).CrueltyReport;
                                    _crueltyReport.UserGeneratedPlace = new UserGeneratedPlace
                                                                            {
                                                                                Name = name,
                                                                                Address = address,
                                                                                City = city,
                                                                                StateProvinceAbbreviation = stateAbbreviation,
                                                                                Zipcode = zipInput,
                                                                                Email = FindViewById<EditText>(Resource.Id.Email).Text
                                                                            };

                                    var intent = new Intent(this, typeof(ReportCrueltyFragment));
                                    StartActivity(intent);
                                }
                            });

                    };
                };
        }