public static CommunitySelection CreateDefault(Athlete myAthlete) { var myCountry = Country.Get(myAthlete.Country); 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 : "?" } } ; var selection = CommunitySelection.CreateAsMetro(myMetro); selection.IsMyMetro = true; return(selection); } else if (myCountry != null) { return(CommunitySelection.CreateAsCountry(myCountry)); } else { return(CommunitySelection.CreateAsPlanetEarth()); } }
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); } }