Ejemplo n.º 1
0
        private async void CreatePlaceSuggestion(View layout)
        {
            // Adding loader gif
            await AddLoaderToView(MainPanel);

            // Casting view to layout panel
            var stackLayout = layout as StackLayout;

            var place = places[currentPlaceIndex];

            Image image = new Image
            {
                Style = Application.Current.Resources["DefaultImageStyle"] as Style
            };

            // Retrieving the image from api
            if (!String.IsNullOrEmpty(place.ImageId))
            {
                ImageRequest imageRequest = new ImageRequest()
                {
                    ImageId = place.ImageId
                };

                var httpAddress   = AppSettings.GetValue("ImageRequestApi");
                var imageResponse = (Stream)(await imageRequest.SendAsync(httpAddress));
                var imageSource   = ImageSource.FromStream(() => imageResponse);
                image.Source = imageSource;
            }

            Label suggestion = new Label
            {
                Text  = "How about " + place.Name + "?",
                Style = Application.Current.Resources["DefaultLabelStyle"] as Style
            };

            List <View> suggestionList = new List <View>()
            {
                suggestion,
                image
            };

            // Creating panel for suggestion
            var suggestionLayout = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
            };

            Button nextBtn = new Button()
            {
                Text  = "Next",
                Style = Application.Current.Resources["DefaultButtonStyle"] as Style
            };

            Button interestedBtn = new Button()
            {
                Text  = "Interested",
                Style = Application.Current.Resources["DefaultButtonStyle"] as Style
            };

            List <View> buttons = new List <View>()
            {
                nextBtn,
                interestedBtn,
            };

            // Subscribe to click event
            nextBtn.Clicked       += NextBtn_Clicked;
            interestedBtn.Clicked += interestedBtn_Clicked;

            // Creating panel for the buttons
            var buttonsLayout = new StackLayout()
            {
                Spacing           = 10,
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.End
            };

            // Removing loading gif
            RemoveLoaderFromView(MainPanel);

            // Adding suggestion to layout
            AddItemsToView(suggestionLayout, suggestionList);
            stackLayout.Children.Add(suggestionLayout);

            // Adding buttons to layout
            AddItemsToView(buttonsLayout, buttons);
            stackLayout.Children.Add(buttonsLayout);
        }