Exemple #1
0
 public async Task MinimalReportTest()
 {
     String date = dt.ToString("dd_MM_yyyy_H_mm_ss");
     Report r = new Report();
     var localStorage = ApplicationData.Current.LocalFolder;
     var file = await localStorage.CreateFileAsync("RiverWatchImage_" + date + ".jpg");
     r.setImage(file);            
    while (!r.isGeolocationReady())
    {
        await Task.Delay(2000);
    }
     Assert.AreEqual(r.isReportReady(), true);
 }
        /**
         * Updates the Current Pollution Report by checking if certain fields have been filled in.
         * If they are not, their section within the page remains as the pre-programmed message.
         * For Tags and Description sections, the option of removing the entered information is possible.
         * Hence, we need this update.
         */
        public void UpdatePollutionReport()
        {
            // display image
            if (report.getImage() == null)
            {
                ImageToolTip.Text = "Take a photo";
            }
            else
            {
                ImageToolTip.Text   = "";
                imagePreview.Source = new BitmapImage(new Uri(report.getImage().Path));
            }

            // display geolocation
            if (!report.isGeolocationReady())
            {
                if (report.getImage() == null)
                {
                    GeolocationToolTip.FontSize = 20;
                    GeolocationToolTip.Text     = "Awaiting photo";
                }
                else
                {
                    GeolocationToolTip.FontSize = 20;
                    GeolocationToolTip.Text     = "Finding coordinates...";

                    // if we've got an image, start async method that
                    // sends request to report class every 10s to see if
                    // geolocation is ready to be displayed on UI

                    checkGeolocation();
                }
            }
            else
            {
                GeolocationToolTip.FontSize = 15;
                GeolocationToolTip.Text     = "Latitude: " + report.getLatitude() + "\n\nLongitude: " + report.getLongitude();
            }

            // display tags
            if (!report.isTagsReady())
            {
                TagsToolTip.FontSize = 20;
                TagsToolTip.Text     = "Select tags";
            }
            else
            {
                // display as much selected tags
                String t        = "";
                int    NoOfTags = report.getTags().Count;

                if (NoOfTags == 0)
                {
                    TagsToolTip.FontSize = 20;
                    TagsToolTip.Text     = "Select tags";
                    report.setTagsNotReady();
                }
                else
                {
                    int TagCount = 0;
                    int TagLimit = 6;

                    int LineCount = 0;
                    int LineLimit = 2;

                    foreach (String element in report.getTags())
                    {
                        // if we've displayed 6 tags
                        if (TagCount >= TagLimit)
                        {
                            break;
                        }

                        // if we've got two tags on a line
                        if (!(LineCount < LineLimit))
                        {
                            t        += "\n";
                            LineCount = 0;
                        }

                        // append tag
                        t += "#" + element + ", ";
                        LineCount++;
                        TagCount++;
                    }

                    // remove extra comma
                    t = t.Substring(0, t.Length - 2);
                    Debug.WriteLine(t);

                    // if user selected more than 6 tags, add a ...
                    if (NoOfTags > 6)
                    {
                        t += "...";
                    }

                    // display tags
                    TagsToolTip.FontSize = 15;
                    TagsToolTip.Text     = t;
                }
            }

            // display description
            if (!report.isDescriptionReady())
            {
                DescriptionToolTip.FontSize = 20;
                DescriptionToolTip.Text     = "Add description";
            }
            else
            {
                String desc = report.getDescription();

                if (desc.Length == 0)
                {
                    DescriptionToolTip.FontSize = 20;
                    DescriptionToolTip.Text     = "Add description";
                    report.setDescriptionNotReady();
                }
                else
                {
                    // need to parse out trailing whitespace
                    DescriptionToolTip.FontSize = 15;
                    DescriptionToolTip.Text     = desc.Trim();
                }
            }

            // if report is complete, we need to compact the grids and display submit button
            if (report.isReportReady())
            {
                if (UIReadyToSend == false)
                {
                    UIReadyToSend = true;
                    Debug.WriteLine("Report is now ready to send");
                    animateReadyToSend();
                }
            }
            else
            {
                if (UIReadyToSend == true)
                {
                    UIReadyToSend = false;
                    Debug.WriteLine("Report is now not ready to send");
                    animateNotReadyToSend();
                }
            }
        }