Example #1
0
 public void fireLoadBallotFromPhotoSubmission(BallotFromPhotoSubmissionEventArgs ballotEvt)
 {
     if (LoadBallotFromPhotoSubmission != null)
     {
         LoadBallotFromPhotoSubmission(this, ballotEvt);
     }
 }
Example #2
0
        // click handler for SubmitCurrentPicture.
        protected async virtual void OnSubmitCurrentPicture(object sender, EventArgs e)
        {
            Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture start");
            if (canClickSubmit == false)
            {
                tagsEntry.FontAttributes = FontAttributes.Bold;
                await tagsEntry.FadeTo(0, 350);

                await tagsEntry.FadeTo(1, 350);

                await Task.Delay(150);

                tagsEntry.FontAttributes = FontAttributes.None;
                return;
            }
            alertBulb.IsVisible = false;

            // check that button is enabled... xamarin has weak-fu here.
            // now doing special handling...
            //if (((Button)sender).IsEnabled == false) { return; }

            // prevent multiple click attempts; we heard ya
            //submitCurrentPictureP.IsEnabled = false;
            //submitCurrentPictureL.IsEnabled = false;
            canClickSubmit             = false;
            submitCurrentPictureP.Text = "Submitting!";

            Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture pre async call");
            if (animate != null)
            {
                animate(this, new EventArgs());
            }

            debug_checkImgSquare();

            //string result = await sendSubmitAsync(latestTakenImgBytes);
            //string result = await sendSubmitAsync(GlobalStatusSingleton.mostRecentImgBytes);
            while (submitResult.Equals(""))
            {
                await Task.Delay(250);
            }
            this.animationActive = false;
            Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture post async call");
            try {
                BallotJSONExtended response = JsonConvert.DeserializeObject <BallotJSONExtended>(submitResult);
                Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture post json deserialize");
                if (response.pid > 0)
                {
                    await photoUpdate(response.pid);
                }
                if (response.ballots != null)
                {
                    //if (response.message.Equals(PhotoSubmitResponseJSON.SUCCESS_MSG)) {
                    // success. update the UI
                    submitCurrentPictureP.Text = "Congratulations, you're in!";
                    //submitCurrentPictureL.Text = "Congratulations, you're in!";

                    // buildUI();  this now generates the null ref pointer bug. remove. as i think it's irrelevant to how the ui
                    //   now works anyway.
                    //setView();
                    Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture end");
                    cameraPage.switchToSelectView();
                    //BallotFromPhotoSubmissionEventArgs ballotEvt = new BallotFromPhotoSubmissionEventArgs { ballotString = result, };
                    var ballotSubset = new { response.category, response.ballots };
                    BallotFromPhotoSubmissionEventArgs ballotEvt = new BallotFromPhotoSubmissionEventArgs {
                        ballotString = JsonConvert.SerializeObject(ballotSubset),
                    };
                    cameraPage.fireLoadBallotFromPhotoSubmission(ballotEvt);
                }
                else
                {
                    // try a photo deserialize. no ballot was returned, so probably no enough pics!
                    // actually... we already processed the fail case in submitAsync... so here we are good.
                    submitCurrentPictureP.Text = "Congratulations, you're in!";
                    cameraPage.switchToSelectView();
                }
            } catch (Exception err) {
                Debug.WriteLine("DHB:CameraContentPage:OnSubmitCurrentPicture invalid response json: " + submitResult);
                Debug.WriteLine(err.ToString());
                submitCurrentPictureP.Text = "Entry failed - try again";
                //submitCurrentPictureP.IsEnabled = true;
                canClickSubmit      = true;
                bulb.IsVisible      = false;
                animationActive     = false;
                alertBulb.IsVisible = true;
                //buildUI();
            } finally {
                submitResult   = "";
                tagsEntry.Text = "";
                uploadStarted  = false; // reset so we can try again.
            }

            // only enable on picture taking.
            //((Button)sender).IsEnabled = true;

            // was this line needed?
            //Content = portraitLayout;
            return;
        }