Пример #1
0
        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;
                });
        }
Пример #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            fa = base.Activity;
            ll = (RelativeLayout)inflater.Inflate(Resource.Layout.ReportCruelty, container, false);

            //CrueltyNavMenuHelper.InitCrueltyNavMenu (this, CrueltyNavMenuItem.ReportIt);

            _crueltyReport = ((AfaApplication)fa.ApplicationContext).CrueltyReport;
            if (_crueltyReport == null)
            {
                _crueltyReport = new CrueltyReport();
                ((AfaApplication)fa.ApplicationContext).CrueltyReport = _crueltyReport;
            }

            _locationInput = ll.FindViewById<EditText>(Resource.Id.LocationInput);
            _crueltyTypeInput = ll.FindViewById<EditText>(Resource.Id.TypeOfCrueltyInput);

            if (_crueltyReport.PlaceSpecified)
            {
                var locationText = new StringBuilder();
                locationText.Append("<font color='#D34C96'><b>");
                locationText.Append(_crueltyReport.PlaceName);
                locationText.Append("</b></font>");
                locationText.Append("<br />");
                locationText.Append("<font color='#B5B5B5'><small>");
                locationText.Append(_crueltyReport.PlaceFormattedShortAddress);
                locationText.Append("</small></font>");
                var htmlText = locationText.ToString();
                _locationInput.SetText(Html.FromHtml(htmlText), TextView.BufferType.Spannable);
            }

            _crueltyTypeInput.Text = _crueltyReport.CrueltyType != null ? _crueltyReport.CrueltyType.Name : null;

            //_locationInput.FocusChange += (sender, args) =>
            //{
            //    if (args.HasFocus) {
            //        var intent = new Intent (fa, typeof(NearbyPlacesActivity));
            //        StartActivity (intent);
            //    }
            //};

            _locationInput.Click += (sender, args) =>
            {
                var intent = new Intent(fa, typeof(NearbyPlacesActivity));
                StartActivity(intent);
            };

            //_crueltyTypeInput.FocusChange += (sender, args) =>
            //{
            //    if (args.HasFocus) {
            //        var intent = new Intent (fa, typeof(CrueltyTypesActivity));
            //        StartActivity (intent);
            //    }
            //};

            _crueltyTypeInput.Click += (sender, args) =>
            {
                var intent = new Intent(fa, typeof(CrueltyTypesActivity));
                StartActivity(intent);
            };

            //// ToDo: This line hides the soft keyboard, but doing so makes the EditText only have 1 line.
            //// Look into alternative
            ////_locationInput.InputType = InputTypes.Null;
            //_crueltyTypeInput.InputType = InputTypes.Null;

            _submitButton = ll.FindViewById<Button>(Resource.Id.SubmitButton);
            _submitButton.Enabled = _crueltyReport.PlaceSpecified && _crueltyReport.CrueltyTypeSpecified;

            _submitButton.Click +=
                (sender, args) =>
                {
                    // Create a new Cruelty Spot
                    _loadingDialog = DialogManager.ShowSubmittingDialog(fa);
                    //CrueltySpotDto newCrueltySpot;
                    CrueltySpot newCrueltySpot;

                    if (_crueltyReport.IsGooglePlace())
                    {
                        // Fetch details from google
                        var googlePlaces = new GooglePlacesApi.GooglePlaces(AfaConfig.GoogleApiKey);
                        googlePlaces.GetDetails(_crueltyReport.GooglePlace.Reference, response =>
                        {
                            // ToDo: Check Status and handle non-OK
                            var placeDetails = response.result;

                            var latitude = placeDetails.geometry.location.lat;
                            var longitude = placeDetails.geometry.location.lng;
                            newCrueltySpot = new CrueltySpot
                            {
                                Name = placeDetails.name,
                                //Description = _descriptionInput.Text,
                                Address = placeDetails.Address,
                                City = placeDetails.City,
                                StateProvinceAbbreviation = placeDetails.StateOrProvince,
                                Zipcode = placeDetails.PostalCode,
                                PhoneNumber = placeDetails.formatted_phone_number,
                                WebpageUrl = placeDetails.website,
                                //Latitude = placeDetails.geometry.location.lat,
                                //Longitude = placeDetails.geometry.location.lng,
                                Location = new ParseGeoPoint(latitude, longitude),
                                //CrueltySpotCategoryId = _crueltyReport.CrueltyType.Id,
                                CrueltySpotCategory = ParseObject.CreateWithoutData<CrueltySpotCategory>(_crueltyReport.CrueltyType.Id),
                                GooglePlaceId = placeDetails.id
                            };

                            SubmitNewCrueltySpot(newCrueltySpot);

                        });
                    }
                    else
                    {
                        // Submit with user lat/lng
                        var gpsTracker = ((AfaApplication)fa.ApplicationContext).GetGpsTracker(fa);

                        var latitude = gpsTracker.Latitude;
                        var longitude = gpsTracker.Longitude;

                        newCrueltySpot = new CrueltySpot
                        {
                            Name = _crueltyReport.PlaceName,
                            //Description = _descriptionInput.Text,
                            Address = _crueltyReport.UserGeneratedPlace.Address,
                            City = _crueltyReport.UserGeneratedPlace.City,
                            StateProvinceAbbreviation = _crueltyReport.UserGeneratedPlace.StateProvinceAbbreviation,
                            Zipcode = _crueltyReport.UserGeneratedPlace.Zipcode,
                            //PhoneNumber = placeDetails.formatted_phone_number,
                            //WebpageUrl = placeDetails.website,
                            Email = _crueltyReport.UserGeneratedPlace.Email,
                            //Latitude = gpsTracker.Latitude,
                            //Longitude = gpsTracker.Longitude,
                            Location = new ParseGeoPoint(latitude, longitude),
                            //CrueltySpotCategoryId = _crueltyReport.CrueltyType.Id
                            CrueltySpotCategory = ParseObject.CreateWithoutData<CrueltySpotCategory>(_crueltyReport.CrueltyType.Id)
                        };

                        SubmitNewCrueltySpot(newCrueltySpot);
                    }


                };

            return ll;

        }
Пример #3
0
        /*
        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();
            });
        }