public FindPeopleControl(bool friendsByDefault)
        {
            this.Padding         = new Thickness(0);
            this.BackgroundColor = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorBackground : Config.ColorGrayBackground;

            StackLayout stack = new StackLayout();

            stack.Orientation = StackOrientation.Vertical;
            stack.Spacing     = 0;
            this.Content      = stack;

            var myAthlete = App.Repository.GetMyAthlete();

            /// Filters
            ///

            // community
            this.communitySelectorControl = new CommunitySelectorControl()
            {
                NameAsCommunity = false, AllowFriendsSelection = Config.App != MobileAppEnum.SnookerForVenues
            };
            if (friendsByDefault)
            {
                this.communitySelectorControl.Selection = CommunitySelection.CreateFriendsOnly();
            }
            this.communitySelectorControl.SelectionChanged += communitySelectorControl_SelectionChanged;
            stack.Children.Add(new StackLayout()
            {
                Orientation     = StackOrientation.Horizontal,
                Padding         = new Thickness(0, 5, 0, 5),
                HeightRequest   = Config.LargeButtonsHeight,// 40,
                Spacing         = 1,
                BackgroundColor = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorBackground : Config.ColorGrayBackground,
                Children        =
                {
                    communitySelectorControl,
                }
            });

            // search
            this.buttonClearFilters = new BybButton()
            {
                Text         = "x",
                Style        = (Style)App.Current.Resources["SimpleButtonStyle"],
                WidthRequest = 30,
                TextColor    = Config.App == MobileAppEnum.SnookerForVenues ? Color.White : Color.Black,
            };
            this.buttonClearFilters.Clicked += (s, e) =>
            {
                this.ignoreUIEvents   = true;
                this.entrySearch.Text = "";
                this.ignoreUIEvents   = false;
                this.reloadAsync();
            };
            this.entrySearch = new BybNoBorderEntry()
            {
                Placeholder       = "Search by name",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.Center,
                BackgroundColor   = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorBackground : Color.White,
                TextColor         = Config.App == MobileAppEnum.SnookerForVenues ? Color.White : Color.Black,
            };
            this.entrySearch.Completed += entrySearch_Completed;
            stack.Children.Add(new StackLayout()
            {
                Orientation     = StackOrientation.Horizontal,
                Padding         = new Thickness(Config.IsIOS ? 15 : 5, 0, 0, 0),
                HeightRequest   = Config.LargeButtonsHeight,//40,
                Spacing         = 1,
                BackgroundColor = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorBackground : Color.White,
                Children        =
                {
                    entrySearch,
                    buttonClearFilters,
                }
            });

            /// Status panel
            ///
            this.labelStatus = new BybLabel()
            {
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorTextOnBackgroundGrayed : Color.Black,
            };
            this.buttonSearchWorldwide = new BybButton()
            {
                Text              = "Search world-wide",
                Style             = (Style)App.Current.Resources["SimpleButtonStyle"],
                TextColor         = Config.App == MobileAppEnum.SnookerForVenues ? Color.White : Color.Black,
                HorizontalOptions = LayoutOptions.Center,
                IsVisible         = false,
            };
            this.buttonSearchWorldwide.Clicked += buttonSearchWorldwide_Clicked;
            this.panelStatus = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Padding     = new Thickness(0, 20, 0, 10),
                Children    =
                {
                    this.labelStatus,
                    this.buttonSearchWorldwide,
                }
            };
            stack.Children.Add(this.panelStatus);

            /// List of people
            ///
            this.listOfPeopleControl = new ListOfPeopleControl();
            this.listOfPeopleControl.IsDarkBackground = Config.App == MobileAppEnum.SnookerForVenues;
            if (Config.App == MobileAppEnum.SnookerForVenues)
            {
                this.listOfPeopleControl.BackgroundColor = Config.ColorBackground;
            }
            listOfPeopleControl.UserClickedOnPerson += (s1, e1) =>
            {
                if (this.UserClickedOnPerson != null)
                {
                    this.UserClickedOnPerson(this, e1);
                }
            };
            stack.Children.Add(new ScrollView()
            {
                Padding           = new Thickness(0, 0, 0, 0),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                Content           = this.listOfPeopleControl,
            });
        }
Exemple #2
0
        void fillTop()
        {
            this.stackTop.Children.Clear();

            // friends
            if (AllowFriendsSelection)
            {
                this.stackTop.Children.Add(this.createItem(CommunitySelection.CreateFriendsOnly()));
            }

            // planet Earth
            this.stackTop.Children.Add(this.createItem(CommunitySelection.CreateAsPlanetEarth()));

            // your city
            if (myAthlete.MetroID > 0)
            {
                var myMetro = App.Cache.Metroes.Get(myAthlete.MetroID);
                if (myMetro == null)
                {
                    myMetro = new MetroWebModel()
                    {
                        ID = myAthlete.MetroID, Name = "Your city", Country = myCountry != null ? myCountry.ThreeLetterCode : "?"
                    }
                }
                ;
                this.stackTop.Children.Add(this.createItem(CommunitySelection.CreateAsMetro(myMetro)));
            }
        }

        void fillCountries(bool showAll)
        {
            // list of countries
            List <Country> listOfCountries;

            if (showAll)
            {
                listOfCountries = Country.ListWithoutImportance0.ToList();
                if (myCountry != null)
                {
                    listOfCountries.Insert(0, myCountry);
                }
            }
            else
            {
                listOfCountries = Country.List.Where(i => i.Snooker == CountryImportanceEnum.Importance9).ToList();
                if (this.Selection != null && this.Selection.Country != null && listOfCountries.Contains(this.Selection.Country) == false)
                {
                    listOfCountries.Insert(0, this.Selection.Country);
                }
                if (myCountry != null && listOfCountries.Contains(myCountry) == false)
                {
                    listOfCountries.Insert(0, myCountry);
                }
            }

            // fill the stack
            this.stackCountries.Children.Clear();
            foreach (var country in listOfCountries)
            {
                this.stackCountries.Children.Add(this.createItem(CommunitySelection.CreateAsCountry(country)));
            }

            if (showAll == false)
            {
                var labelShowAll = new BybLabel()
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    HeightRequest     = itemHeight,
                    FontSize          = Config.LargerFontSize,
                    TextColor         = Color.White,
                    Text = "More countries...",
                    HorizontalTextAlignment = TextAlignment.Start,
                    VerticalTextAlignment   = TextAlignment.Center,
                };
                this.stackCountries.Children.Add(new StackLayout
                {
                    Orientation       = StackOrientation.Horizontal,
                    BackgroundColor   = Config.ColorBlackBackground,
                    HorizontalOptions = LayoutOptions.Fill,
                    VerticalOptions   = LayoutOptions.Fill,
                    Padding           = new Thickness(15, 0, 0, 0),
                    HeightRequest     = itemHeight,
                    Children          =
                    {
                        labelShowAll
                    }
                });
                labelShowAll.GestureRecognizers.Add(new TapGestureRecognizer()
                {
                    Command = new Command(() => { this.fillCountries(true); })
                });
            }
        }

        async Task fillMetros()
        {
            this.stackMetros.Children.Clear();

            if (this.Selection == null || this.Selection.Country == null)
            {
                this.stackMetros.Children.Add(this.createInfoLabel("Cities populate when the country is picked", false));
                return;
            }

            // load metros
            this.stackMetros.Children.Add(this.createInfoLabel("Loading cities...", false));
            var metros = await App.WebService.GetMetros(this.Selection.Country.ThreeLetterCode);

            if (metros == null)
            {
                this.stackMetros.Children.Clear();
                this.stackMetros.Children.Add(this.createInfoLabel("Couldn't load cities. Internet issues?", false));
                return;
            }

            // save metros to cache
            App.Cache.Metroes.Put(metros);

            // fill metros
            metros = (from i in metros
                      orderby i.Name
                      select i).ToList();
            this.stackMetros.Children.Clear();
            foreach (var metro in metros)
            {
                this.stackMetros.Children.Add(this.createItem(CommunitySelection.CreateAsMetro(metro)));
            }
        }

        StackLayout createDivider(string text)
        {
            return(new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Config.ColorBackground,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions = LayoutOptions.Fill,
                Padding = new Thickness(15, 0, 0, 0),
                HeightRequest = itemHeight,
                Children =
                {
                    new BybLabel()
                    {
                        Text = text,
                        FontSize = Config.LargerFontSize,
                        VerticalOptions = LayoutOptions.Center,
                        TextColor = Config.ColorTextOnBackgroundGrayed,
                    }
                }
            });
        }

        StackLayout createInfoLabel(string text, bool error)
        {
            return(new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Config.ColorBlackBackground,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions = LayoutOptions.Fill,
                Padding = new Thickness(15, 0, 0, 0),
                HeightRequest = itemHeight,
                Children =
                {
                    new BybLabel()
                    {
                        Text = text,
                        FontSize = Config.LargerFontSize,
                        VerticalOptions = LayoutOptions.Center,
                        TextColor = error ? Color.Red : Color.White,
                    }
                }
            });
        }

        StackLayout createItem(CommunitySelection item)
        {
            StackLayout stack = new StackLayout()
            {
                Orientation       = StackOrientation.Horizontal,
                BackgroundColor   = Config.ColorBlackBackground,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = itemHeight,
                Padding           = new Thickness(15, 0, 15, 0),
            };

            if (DoNotCheckSelection == false && Selection != null &&
                item.Country == Selection.Country && item.MetroID == Selection.MetroID && item.IsFriendsOnly == Selection.IsFriendsOnly)
            {
                var image = new Image()
                {
                    Source = new FileImageSource()
                    {
                        File = "checkmarkRed.png"
                    },
                    HeightRequest = itemHeight * 0.4,
                    WidthRequest  = itemHeight * 0.4,
                };
                stack.Children.Add(image);
            }

            stack.Children.Add(new BybLabel()
            {
                FontSize                = Config.LargerFontSize,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                VerticalOptions         = LayoutOptions.Center,
                TextColor               = Color.White,
                BackgroundColor         = Config.ColorBlackBackground,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalTextAlignment   = TextAlignment.Center,
                Text = item.ToString(),
            });

            stack.GestureRecognizers.Add(new TapGestureRecognizer()
            {
                Command = new Command(async() =>
                {
                    this.Selection = item;
                    await App.Navigator.NavPage.Navigation.PopModalAsync();
                    if (this.SelectionChanged != null)
                    {
                        this.SelectionChanged(this, EventArgs.Empty);
                    }
                })
            });

            return(stack);
        }
    }