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 } }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.CrueltySpot); //_loadingDialog = LoadingDialogManager.ShowLoadingDialog(this); _loadingDialog = DialogManager.ShowLoadingDialog(this, "Retrieving Cruelty Spot Details"); // Event Handlers IssueButton.Click += (sender, args) => SetViewState(CrueltySpotViewState.TheIssue); TakeActionButton.Click += (sender, args) => SetViewState(CrueltySpotViewState.TakeAction); var crueltySpotId = Intent.GetStringExtra(AppConstants.CrueltySpotIdKey); var crueltySpotsService = new CrueltySpotsService(); _crueltySpot = await crueltySpotsService.GetByIdAsync(crueltySpotId, true); RunOnUiThread(() => { var formattedAddress = String.Format("{0}\n{1}", _crueltySpot.Address, _crueltySpot.CityStateAndZip); FindViewById<TextView>(Resource.Id.Name).Text = _crueltySpot.Name; FindViewById<TextView>(Resource.Id.Address).Text = formattedAddress; var resourceId = ResourceHelper.GetDrawableResourceId(this, _crueltySpot.CrueltySpotCategory.IconName, ResourceSize.Medium); FindViewById<ImageView>(Resource.Id.CrueltyTypeImage).SetImageResource(resourceId); SetViewState(CrueltySpotViewState.TakeAction); _loadingDialog.Hide(); var showSuccessAddedAlert = Intent.GetBooleanExtra(AppConstants.ShowCrueltySpotAddedSuccessfullyKey, false); if (showSuccessAddedAlert) { DialogManager.ShowAlertDialog(this, "Thanks!", "...for reporting animal cruelty here. This location is now on the map so others can take action!", true); } FindViewById<TextView>(Resource.Id.issueName).Text = _crueltySpot.CrueltySpotCategory.Name; FindViewById<TextView>(Resource.Id.issueDescription).Text = _crueltySpot.CrueltySpotCategory.Description; }); }
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); }); } }
/* public override bool OnCreateOptionsMenu (ActionBar_Sherlock.View.IMenu menu) { base.OnCreateOptionsMenu (menu); SupportMenuInflater.Inflate (Resource.Menu.report_menu, menu); return true; } */ private async void SubmitNewCrueltySpot(CrueltySpot newCrueltySpot) { var crueltySpotsService = new CrueltySpotsService(); var newCrueltySpotId = await crueltySpotsService.SaveAsync(newCrueltySpot); fa.RunOnUiThread(() => { var intent = new Intent(fa, typeof(CrueltySpotActivity)); intent.PutExtra(AppConstants.ShowCrueltySpotAddedSuccessfullyKey, true); intent.PutExtra(AppConstants.CrueltySpotIdKey, newCrueltySpotId); ClearAllUi(); _crueltyReport.ClearAll(); CommitCrueltyReport(); StartActivity(intent); _loadingDialog.Dismiss(); }); }
/// <summary> /// Get Reported Cruelty Spots with Google Place Ids /// ToDo: This method should accept a lat/lng so we don't retrieve more than we need /// </summary> /// <param name="callback"></param> private async void GetReportedCrueltySpotsAsync(Action<PlacesList> callback) { var crueltySpotsService = new CrueltySpotsService(); var googleCrueltySpots = await crueltySpotsService.GetAllGooglePlacesAsync(); _reportedGooglePlaces = new Dictionary<string, string>(); foreach (var crueltySpot in googleCrueltySpots) { if (!_reportedGooglePlaces.ContainsKey(crueltySpot.GooglePlaceId)) { _reportedGooglePlaces.Add(crueltySpot.GooglePlaceId, crueltySpot.ObjectId); } } _reportedGooglePlacesRetrieved = true; SearchCompleted(callback); }
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); } }); }; }; }