예제 #1
0
        // When user is done adding attractions
        async void OnDoneButtonClicked(object sender, EventArgs e)
        {
            SearchResults.DataDisplay data = SearchResults.displayedData;
            var searchResultsPage          = new SearchResults(data.Dest, data.StartDate, data.EndDate, data.Attractions, data.Ratings, data.ReviewCounts, data.ImageURLs, data.Durations, data.Descriptions, data.Addresses);

            // Disable back button on next page
            NavigationPage.SetHasBackButton(searchResultsPage, false);
            await Navigation.PushAsync(searchResultsPage);
        }
예제 #2
0
        async void OnSavedTripClicked(object sender, EventArgs e)
        {
            var    destLabel    = sender as Label;
            string tripIndexStr = destLabel.BindingContext as string;
            int    tripIndex    = Int32.Parse(tripIndexStr);

            SearchResults.DataDisplay data = AllTripsDataDisplayed[tripIndex];
            if (SearchResults.displayedData != null)
            {
                var searchResultsPage = new SearchResults(data.Dest, data.StartDate, data.EndDate, data.Attractions, data.Ratings, data.ReviewCounts, data.ImageURLs, data.Durations, data.Descriptions, data.Addresses);

                // Disable back button on next page
                NavigationPage.SetHasBackButton(searchResultsPage, false);
                await Navigation.PushAsync(searchResultsPage);
            }
        }
예제 #3
0
        public AddAttractions(string dest, string startDate, string endDate, List <List <string> > attractions, List <List <string> > ratings, List <List <string> > reviewCounts, List <List <string> > imageURLs, List <List <string> > durations, List <List <string> > descriptions, List <List <string> > addresses)
        {
            InitializeComponent();

            // Store database query results in global variables
            addAttractionPageData = new SearchResults.DataDisplay
            {
                Dest         = dest,
                StartDate    = startDate,
                EndDate      = endDate,
                Attractions  = attractions,
                Ratings      = ratings,
                ReviewCounts = reviewCounts,
                ImageURLs    = imageURLs,
                Durations    = durations,
                Descriptions = descriptions,
                Addresses    = addresses
            };

            // Grid for date
            var dateGrid = new Grid {
                Padding = new Thickness(30, 30, 30, 20)
            };

            dateGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            dateGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            DateTime startDateObj = DateTime.ParseExact(startDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            DateTime endDateObj   = DateTime.ParseExact(endDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            // List of days in trip
            List <string> daysInTrip = new List <string>();

            for (int i = 0; i < (endDateObj - startDateObj).TotalDays + 1; i++)
            {
                DateTime currDateObj = startDateObj.AddDays(i);
                daysInTrip.Add((currDateObj).ToString("MMM. dd, yyyy"));
            }

            // Add items to picker
            foreach (string day in daysInTrip)
            {
                datePicker.Items.Add(day);
            }

            // Add to grid
            dateGrid.Children.Add(datePicker, 0, 0);
            // Add to stack layout
            AddAttractionsStack.Children.Add(dateGrid);

            bool areThereAttractionsLeft = true;

            // For each day in trip
            for (int i = 0; i < attractions.Count; i++)
            {
                // Create new list of grids for current day
                List <Grid> currDayImgGrid = new List <Grid>();
                imgGrids.Add(currDayImgGrid);
                List <Grid> currDayTextGrid = new List <Grid>();
                textGrids.Add(currDayTextGrid);
                List <ImageButton> currDayAttractionImgBtns = new List <ImageButton>();
                attractionImgBtns.Add(currDayAttractionImgBtns);
                List <ImageButton> currDayImgBtns = new List <ImageButton>();
                imgBtns.Add(currDayImgBtns);

                // For each attraction planned on current day in trip
                for (int j = 0; j < attractions[i].Count; j++)
                {
                    // Grid for text
                    var grid = new Grid {
                        Padding = new Thickness(30, 0, 30, 30)
                    };

                    // If no more attraction results to display (no more database results)
                    if (String.IsNullOrEmpty(attractions[i][j]))
                    {
                        // Create 1x1 grid for text
                        grid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        grid.ColumnDefinitions.Add(new ColumnDefinition {
                            Width = new GridLength(1, GridUnitType.Star)
                        });

                        // Heading
                        var noActivitiesLabel = new Label {
                            Text = "No activities to display.", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Center
                        };

                        // Add to grid
                        grid.Children.Add(noActivitiesLabel, 0, 0);
                        // Add to stack layout
                        AddAttractionsStack.Children.Add(grid);

                        areThereAttractionsLeft = false;
                        break;
                    }

                    // Create 4x5 grid for image
                    var imgGrid = new Grid {
                        Padding = new Thickness(30, 20, 30, 20), HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill
                    };
                    imgGrid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(140)
                    });
                    imgGrid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(60)
                    });
                    imgGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                    currDayImgGrid.Add(imgGrid);

                    // Boxviews
                    var currBoxview = new BoxView {
                        CornerRadius = 10, HorizontalOptions = LayoutOptions.Fill, BackgroundColor = Color.FromHex("#72D5E6"), Opacity = 0.2
                    };

                    // Image
                    string bindingContextAttractionImgBtn = String.Format("{0},{1}", i, j);
                    var    attractionImg = new ImageButton();
                    var    noImageLabel  = new Label();

                    // Check if image URL is a valid URL
                    Uri  uriResult;
                    bool isImageURLValid = Uri.TryCreate(imageURLs[i][j], UriKind.Absolute, out uriResult) &&
                                           (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

                    // If there is an image available
                    if (!String.IsNullOrEmpty(imageURLs[i][j]) && isImageURLValid == true)
                    {
                        attractionImg = new ImageButton
                        {
                            Source            = imageURLs[i][j],
                            Aspect            = Aspect.AspectFill,
                            HorizontalOptions = LayoutOptions.Fill,
                            VerticalOptions   = LayoutOptions.Fill,
                            BindingContext    = bindingContextAttractionImgBtn
                        };
                    }
                    // If no image available
                    else
                    {
                        attractionImg = new ImageButton
                        {
                            Aspect            = Aspect.AspectFill,
                            HorizontalOptions = LayoutOptions.Fill,
                            VerticalOptions   = LayoutOptions.Fill,
                            BindingContext    = bindingContextAttractionImgBtn
                        };

                        // Heading
                        noImageLabel = new Label {
                            Text = "No image found", TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center
                        };
                    }
                    currDayAttractionImgBtns.Add(attractionImg);
                    attractionImgBtns[i][j].Clicked += OnAttractionImgBtnClicked;

                    /* var attractionImg = new ImageButton { Source = imageURLs[i][j], Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, BindingContext = bindingContextAttractionImgBtn };
                     * currDayAttractionImgBtns.Add(attractionImg);
                     * attractionImgBtns[i][j].Clicked += OnAttractionImgBtnClicked; */

                    // Plus image button
                    string bindingContextPlusImgBtn = String.Format("{0},{1}", i, j);
                    var    plusImgBtn = new ImageButton {
                        Source = "Plus.png", Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.End, BindingContext = bindingContextPlusImgBtn
                    };
                    currDayImgBtns.Add(plusImgBtn);
                    // Event handler - when click minus button
                    imgBtns[i][j].Clicked += OnImgBtnClicked;

                    // Frame with rounded corners for image
                    var imgFrame = new Frame
                    {
                        Content           = attractionImg,
                        CornerRadius      = 10,
                        Margin            = new Thickness(0),
                        Padding           = new Thickness(0),
                        IsClippedToBounds = true
                    };

                    // Add to image grid
                    imgGrid.Children.Add(currBoxview, 0, 1, 0, 2);

                    // If there is an image available
                    if (!String.IsNullOrEmpty(imageURLs[i][j]) && isImageURLValid == true)
                    {
                        imgGrid.Children.Add(imgFrame, 0, 1, 0, 2);
                    }
                    else
                    {
                        imgGrid.Children.Add(noImageLabel, 0, 1, 0, 2);
                    }

                    imgGrid.Children.Add(plusImgBtn, 0, 1);

                    // Create 3x2 grid for text
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(7, GridUnitType.Star)
                    });
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(5, GridUnitType.Star)
                    });
                    currDayTextGrid.Add(grid);

                    // Heading
                    var attractionHeading = new Label {
                        Text = "Attraction: ", TextColor = Color.Black
                    };
                    // Get current attraction for the current day in trip
                    var currAttraction = new Label {
                        Text = attractions[i][j].Trim(), TextColor = Color.Red
                    };

                    // Heading
                    var ratingHeading = new Label {
                        Text = "Rating: ", TextColor = Color.Black
                    };
                    // Get rating for the current attraction
                    var currRating = new Label {
                        Text = ratings[i][j].Trim(), TextColor = Color.Red
                    };

                    // Heading
                    var reviewCountHeading = new Label {
                        Text = "Number of Reviews: ", TextColor = Color.Black
                    };
                    // Get number of reviews for the current attraction
                    var currReviewCount = new Label {
                        Text = reviewCounts[i][j].Trim(), TextColor = Color.Red
                    };

                    // Heading
                    var durationHeading = new Label {
                        Text = "Estimated Duration: ", TextColor = Color.Black
                    };

                    // Get estimated duration for the current attraction
                    string currDurationStr = "";

                    // If duration is not an empty string
                    if (!String.IsNullOrEmpty(durations[i][j].Trim()))
                    {
                        if (Int32.Parse(durations[i][j].Trim()) == 0)
                        {
                            currDurationStr = "< 1 hour";
                        }
                        else if (Int32.Parse(durations[i][j].Trim()) == 1)
                        {
                            currDurationStr = "1-2 hours";
                        }
                        else if (Int32.Parse(durations[i][j].Trim()) == 2)
                        {
                            currDurationStr = "2-3 hours";
                        }
                        else
                        {
                            currDurationStr = "> 3 hours";
                        }
                    }
                    var currDuration = new Label {
                        Text = currDurationStr, TextColor = Color.Red
                    };

                    // Add to grid
                    grid.Children.Add(attractionHeading, 0, 0);
                    grid.Children.Add(currAttraction, 1, 0);
                    grid.Children.Add(ratingHeading, 0, 1);
                    grid.Children.Add(currRating, 1, 1);
                    grid.Children.Add(reviewCountHeading, 0, 2);
                    grid.Children.Add(currReviewCount, 1, 2);
                    grid.Children.Add(durationHeading, 0, 3);
                    grid.Children.Add(currDuration, 1, 3);

                    // Add to stack layout
                    AddAttractionsStack.Children.Add(imgGrid);
                    AddAttractionsStack.Children.Add(grid);
                }

                if (areThereAttractionsLeft == false)
                {
                    break;
                }
            }
        }