Example #1
0
        private async Task refreshReportList()
        {
            reportItems.Clear();
            reports.Clear();

            StorageFolder unsentReportFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Unsent_Reports", CreationCollisionOption.OpenIfExists);

            reportFiles = await unsentReportFolder.GetFilesAsync();

            for (int i = 0; i < reportFiles.Count; i++)
            {
                //Read file, split itno info bits.


                StorageFile currFile = reportFiles.ElementAt(i);
                string      fileContent;
                using (StreamReader s = new StreamReader(await currFile.OpenStreamForReadAsync()))
                {
                    fileContent = await s.ReadToEndAsync();

                    s.Dispose();
                }
                Debug.WriteLine(fileContent + "\n");
                //Report currReport = new Report(fileContent);
                Report currReport = await Report.GenerateFromString(fileContent);

                //string[] reportComponents = fileContent.Split(new String[]{":~:"},StringSplitOptions.None);
                //create preview
                //image block preview
                Image previewImage = new Image();
                previewImage.Source = new BitmapImage(new Uri(currReport.getImage().Path));
                previewImage.HorizontalAlignment = HorizontalAlignment.Left;
                previewImage.Stretch             = Stretch.UniformToFill;
                previewImage.Margin = new Thickness(5, 5, 5, 5);

                //List View Item (outer wrapper)
                ListViewItem currFileItem = new ListViewItem();
                currFileItem.Name       = currFile.Name;
                currFileItem.Background = new SolidColorBrush(itemBackground);
                currFileItem.Content    = previewImage;
                currFileItem.Height     = 100;
                currFileItem.Margin     = new Thickness(0, 5, 0, 5);
                currFileItem.Tapped    += currFileItem_Tapped;

                reports.Add(currReport);
                reportItems.Add(currFileItem);
            }
            UnsentReportList.ItemsSource = reportItems;
        }
Example #2
0
        private async Task DisplayReportContent()
        {
            string fileContent;

            using (StreamReader s = new StreamReader(await currentReportFile.OpenStreamForReadAsync()))
            {
                fileContent = await s.ReadToEndAsync();

                s.Dispose();
            }
            //Report currReport = new Report(fileContent);
            currentReport = await Report.GenerateFromString(fileContent);

            PageTitle.Text              = currentReport.getReportName();
            imagePreview.Source         = new BitmapImage(new Uri(currentReport.getImage().Path));
            GeolocationToolTip.FontSize = 15;
            GeolocationToolTip.Text     = "Latitude: " + currentReport.getLatitude() + "\n\nLongitude: " + currentReport.getLongitude();
            if (!currentReport.isTagsReady())
            {
                TagsToolTip.FontSize = 20;
                TagsToolTip.Text     = "No tags";
            }
            else
            {
                // display as much selected tags
                String t        = "";
                int    NoOfTags = currentReport.getTags().Count;

                if (NoOfTags == 0)
                {
                    TagsToolTip.FontSize = 20;
                    TagsToolTip.Text     = "No tags";
                    currentReport.setTagsNotReady();
                }
                else
                {
                    int TagCount = 0;
                    int TagLimit = 8;

                    int LineCount = 0;
                    int LineLimit = 3;

                    foreach (String element in currentReport.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);

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

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

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

                if (desc.Length == 0)
                {
                    DescriptionToolTip.FontSize = 20;
                    DescriptionToolTip.Text     = "No description";
                    currentReport.setDescriptionNotReady();
                }
                else
                {
                    // need to parse out trailing whitespace
                    DescriptionToolTip.FontSize = 15;
                    DescriptionToolTip.Text     = desc.Trim();
                }
            }
        }
        private async Task DisplayReportContent()
        {
            string fileContent;
            using (StreamReader s = new StreamReader(await currentReportFile.OpenStreamForReadAsync()))
            {
                fileContent = await s.ReadToEndAsync();
                s.Dispose();
            }
            //Report currReport = new Report(fileContent);
            currentReport = await Report.GenerateFromString(fileContent);
            
            PageTitle.Text = currentReport.getReportName();
            imagePreview.Source = new BitmapImage(new Uri(currentReport.getImage().Path));
            GeolocationToolTip.FontSize = 15;
            GeolocationToolTip.Text = "Latitude: " + currentReport.getLatitude() + "\n\nLongitude: " + currentReport.getLongitude();
            if (!currentReport.isTagsReady())
            {
                TagsToolTip.FontSize = 20;
                TagsToolTip.Text = "No tags";
            }
            else
            {
                // display as much selected tags
                String t = "";
                int NoOfTags = currentReport.getTags().Count;

                if (NoOfTags == 0)
                {
                    TagsToolTip.FontSize = 20;
                    TagsToolTip.Text = "No tags";
                    currentReport.setTagsNotReady();
                }
                else
                {
                    int TagCount = 0;
                    int TagLimit = 8;

                    int LineCount = 0;
                    int LineLimit = 3;

                    foreach (String element in currentReport.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);

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

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

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

                if (desc.Length == 0)
                {
                    DescriptionToolTip.FontSize = 20;
                    DescriptionToolTip.Text = "No description";
                    currentReport.setDescriptionNotReady();
                }
                else
                {
                    // need to parse out trailing whitespace
                    DescriptionToolTip.FontSize = 15;
                    DescriptionToolTip.Text = desc.Trim();
                }
            }
        }
        /**
         * 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();
                }
            }
        }