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()); } }
public static CommunitySelection CreateAsMetro(MetroWebModel metro) { return(new CommunitySelection() { Country = Country.Get(metro.Country), MetroID = metro.ID, MetroName = metro.Name, }); }
public void Put(MetroWebModel metro) { var item = items.Where(i => i.Metro.ID == metro.ID).FirstOrDefault(); if (item != null) { items.Remove(item); } items.Add(new CacheItem() { Metro = metro, TimeLoaded = DateTimeHelper.GetUtcNow() }); }
public async Task <MetroWebModel> GetMetro(int metroID) { string url = WebApiUrl + "Metros?id=" + metroID; try { string responseJson = await this.sendGetRequestAndReceiveResponse(url, true); MetroWebModel metro = JsonConvert.DeserializeObject <MetroWebModel>(responseJson); return(metro); } catch (Exception exc) { LastException = exc; LastExceptionUrl = url; return(null); } }
public static string BuildUrl(MetroWebModel metro, CommunityPageEnum page = CommunityPageEnum.Default) { Country countryObj = Country.Get(metro.Country); string countryStr = countryObj != null ? countryObj.UrlName : "unknown"; string url = "/" + countryStr + "/" + HttpUtility.UrlEncode(metro.UrlName); if (page == CommunityPageEnum.Players) { url += "/players"; } else if (page == CommunityPageEnum.Venues) { url += "/venues"; } if (IsInIFrame) { url += "?IsInIFrame=true"; } return(url.ToLower()); }
void parseCountryAndMetro(string country, string metro, out Country countryObj, out MetroWebModel metroObj) { // country countryObj = Country.Get(country); if (countryObj == null) { throw new Exception("Unknown country - " + country); } // metro metroObj = null; if (string.IsNullOrEmpty(metro) == false && metro.ToLower() != "all") { metroObj = new MetrosLogic(db).Get(countryObj.ThreeLetterCode, metro); if (metroObj == null) { throw new Exception("Unknown metro - " + metro); } } }
public NewPostPage(Country country, int metroID) { this.country = country; this.metroID = metroID; this.BackgroundColor = Color.White; // label this.labelWhere = new BybLabel() { Text = "", TextColor = Config.ColorBlackTextOnWhite, }; if (metroID == 0) { this.labelWhere.Text = country.Name; } else { MetroWebModel metro = App.Cache.Metroes.Get(metroID); if (metro != null) { this.labelWhere.Text = metro.Name; } else { this.labelWhere.Text = "Metro #" + metroID; } } // entry this.editorText = new BybEditor() { HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 50, }; // ok, cancel Button buttonOk = new BybButton { Style = (Style)App.Current.Resources["LargeButtonStyle"], Text = "OK" }; Button buttonCancel = new BybButton { Text = "Cancel", Style = (Style)App.Current.Resources["BlackButtonStyle"] }; buttonOk.Clicked += buttonOk_Clicked; buttonCancel.Clicked += buttonCancel_Clicked; var stackLayout = new StackLayout { Spacing = 5, Padding = new Thickness(0), Children = { new BybTitle("Make a Public Post") { VerticalOptions = LayoutOptions.Start }, new StackLayout { Padding = new Thickness(10, 10, 10, 0), Children = { new StackLayout { Orientation = StackOrientation.Horizontal, Spacing = 10, Children = { new BybLabel { Text = "Post to:", TextColor = Config.ColorGrayTextOnWhite, VerticalTextAlignment = TextAlignment.Center }, labelWhere, } }, new BybLabel { Text = "Text to post:", TextColor = Config.ColorGrayTextOnWhite, VerticalTextAlignment = TextAlignment.Center }, new Frame { HasShadow = false, BackgroundColor = Config.ColorGrayBackground, Padding = new Thickness(5, 5, 5, 5), Content = editorText, } } }, new BoxView() { HeightRequest = 1, VerticalOptions = LayoutOptions.Fill, BackgroundColor = Color.Transparent }, new StackLayout() { Orientation = StackOrientation.Horizontal, //BackgroundColor = Config.ColorBackground, HorizontalOptions = LayoutOptions.Fill, HeightRequest = Config.OkCancelButtonsHeight, Padding = new Thickness(Config.OkCancelButtonsPadding), Spacing = 1, Children = { buttonCancel, buttonOk, } } } }; this.Content = stackLayout; this.Padding = new Thickness(0, 0, 0, 0); }
async void buttonOk_Clicked(object sender, EventArgs e) { // name string athleteName = this.entryName.Text; if (athleteName == null) { athleteName = ""; } athleteName = athleteName.Trim(); if (athleteName.Length > 0) { athleteName = athleteName.Substring(0, 1).ToUpper() + athleteName.Substring(1, athleteName.Length - 1); } if (athleteName.Length < 3) { App.Navigator.DisplayAlertRegular("Please enter a proper name."); return; } // about string about = this.entrySnookerAbout.Text; if (about == null) { about = ""; } about = about.Trim(); if (about.Length > 1000) { about = about.Substring(0, 1000); } // country Country country = null; if (this.pickerCountry.SelectedIndex >= 0) { country = countries[this.pickerCountry.SelectedIndex]; } if (country == null) { App.Navigator.DisplayAlertRegular("Please select your country."); return; } // metro int metroID; if (metros == null && this.athlete.MetroID > 0) { metroID = this.athlete.MetroID; // couldn't load metros, it's ok } else { MetroWebModel metro = null; if (this.pickerMetro.SelectedIndex >= 0) { metro = metros[this.pickerMetro.SelectedIndex]; } if (metro != null && metro.Country != country.ThreeLetterCode) { metro = null; } if (metro == null) { App.Navigator.DisplayAlertRegular("Please select your city. It doesn't have to be the city you live at, just a nearby city would do."); return; } metroID = metro.ID; } // update local DB var athlete = App.Repository.GetMyAthlete(); athlete.Name = athleteName; athlete.SnookerAbout = about; athlete.MetroID = metroID; if (country != null) { athlete.Country = country.ThreeLetterCode; } athlete.TimeModified = DateTimeHelper.GetUtcNow(); App.Repository.UpdateAthlete(athlete); // done if (this.UserClickedOkOrCancel != null) { this.UserClickedOkOrCancel(this, true); } // update in the cloud if (App.LoginAndRegistrationLogic.RegistrationStatus == RegistrationStatusEnum.Registered) { await App.WebService.SyncMyAthlete(athlete); } }
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); } }