Example #1
0
        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());
            }
        }
Example #2
0
        public async Task Initialize(CommunitySelection selection)
        {
            this.Selection = selection;

            this.fillTop();
            this.fillCountries(false);
            await this.fillMetros();
        }
Example #3
0
 public bool Compare(CommunitySelection selection)
 {
     if (this.Country == selection.Country && this.MetroID == selection.MetroID && this.IsFriendsOnly == selection.IsFriendsOnly)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
        private void buttonSettings_Clicked(object sender, EventArgs e)
        {
            FVOConfigPage page = new FVOConfigPage();

            this.Navigation.PushModalAsync(page);

            page.Disappearing += (s1, e1) =>
            {
                if (page.ChangesMade)
                {
                    var me = App.Repository.GetMyAthlete();
                    this.findPeopleControl.ReloadAsync(CommunitySelection.CreateDefault(me), false);
                }
            };
        }
Example #5
0
        public void ReloadAsync(CommunitySelection communitySelection, bool onlyIfItsBeenAwhile)
        {
            bool isCommunitySelectionChanged = this.CurrentCommunity.Compare(communitySelection) == false;

            if (isCommunitySelectionChanged)
            {
                this.communitySelectorControl.Selection = communitySelection;
            }

            if (isCommunitySelectionChanged)
            {
                onlyIfItsBeenAwhile = false;
            }

            this.reloadAsync(onlyIfItsBeenAwhile);
        }
Example #6
0
        public void OpenTab(CommunityControlTabEnum newTab)
        {
            CommunitySelection currentCommunity = this.CurrentCommunity;

            if (rootForNewsfeed != null)
            {
                this.rootForNewsfeed.IsVisible = newTab == CommunityControlTabEnum.Feed;
            }
            if (this.rootForPeople != null)
            {
                this.rootForPeople.IsVisible = newTab == CommunityControlTabEnum.People;
            }
            if (this.findVenuesControl != null)
            {
                this.findVenuesControl.IsVisible = newTab == CommunityControlTabEnum.Venues;
            }

            if (newTab == CommunityControlTabEnum.Feed)
            {
                this.createFeedTabIfNotCreatedYet();
                this.newsfeedControl.ReloadAsync(currentCommunity, true);
            }
            else if (newTab == CommunityControlTabEnum.Venues)
            {
                this.createVenuesTabIfNotCreatedYet();
                this.findVenuesControl.ReloadAsync(currentCommunity);
            }
            else
            {
                this.createPeopleTabIfNotCreatedYet();
                this.findPeopleControl.ReloadAsync(currentCommunity, true);
            }

            if (this.scrollViewForNewsfeed != null)
            {
                this.scrollViewForNewsfeed.IsVisible = this.rootForNewsfeed.IsVisible;
            }
            if (this.findPeopleControl != null)
            {
                this.findPeopleControl.IsVisible = this.rootForPeople.IsVisible;
            }

            this.buttonFeed.IsSelected   = newTab == CommunityControlTabEnum.Feed;
            this.buttonVenues.IsSelected = newTab == CommunityControlTabEnum.Venues;
            this.buttonPeople.IsSelected = newTab == CommunityControlTabEnum.People;
        }
Example #7
0
        public void ReloadAsync(CommunitySelection communitySelection)
        {
            if (this.thread == null)
            {
                this.thread = new Thread(threadProc);
                this.thread.Start();
            }

            if (this.CurrentCommunity.Compare(communitySelection) == false && communitySelection.IsFriendsOnly == false)
            {
                this.IsShowingMap = true;
                this.communitySelectorControl.Selection = communitySelection;
                this.setCurrentLocationFromCurrentCommunityAsync();
            }

            this.checkMyLocationIfNecessary();
        }
Example #8
0
        public void ReloadAsync(CommunitySelection communitySelection, bool onlyIfItsBeenAwhile)
        {
            bool isCommunitySelectionChanged = true;

            if (this.communityLoaded != null && communityLoaded.Compare(communitySelection) == true)
            {
                isCommunitySelectionChanged = false;
            }

            if (isCommunitySelectionChanged)
            {
                this.communitySelectorControl.Selection = communitySelection;
            }

            if (isCommunitySelectionChanged || onlyIfItsBeenAwhile == false)
            {
                this.reloadAsync();
            }
        }
Example #9
0
        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,
            });
        }
Example #10
0
        void reloadAsync(bool forceWorldwide = false)
        {
            TraceHelper.TraceInfoForResponsiveness("FindPeopleControl.reloadAsync");

            /// search parameters to use
            ///

            var community = this.communitySelectorControl.Selection;

            this.communityLoaded = community;
            Country country = community.Country;
            int?    metroID = null;

            if (community.MetroID > 0)
            {
                metroID = community.MetroID;
            }
            string nameQuery = this.entrySearch.Text;

            if (nameQuery == null)
            {
                nameQuery = "";
            }
            nameQuery = nameQuery.Trim();
            bool friendsOnly = community.IsFriendsOnly == true;

            if (forceWorldwide)
            {
                country     = null;
                metroID     = null;
                friendsOnly = false;
            }
            this.theSearchParams = new searchParams()
            {
                NameQuery   = nameQuery,
                Country     = country,
                MetroID     = metroID,
                FriendsOnly = friendsOnly,
                IsMyMetro   = community.IsMyMetro,
            };

            /// if already searching, search again
            ///
            if (isSearchingNow == true)
            {
                shouldDoAnotherSearch = true;
                return;
            }
            shouldDoAnotherSearch = false;

            /// update the UI
            ///
            if (this.LoadStarted != null)
            {
                this.LoadStarted();
            }
            this.panelStatus.IsVisible           = true;
            this.labelStatus.Text                = "Querying snookerbyb.com ...";
            this.listOfPeopleControl.IsVisible   = false;
            this.buttonSearchWorldwide.IsVisible = false;

            /// load data async
            ///
            Task.Run(async() => { await this.threadProc(); });
        }
Example #11
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);
        }
    }
        public CommunitySelectorControl()
        {
            this.Selection = CommunitySelection.CreateDefault(App.Repository.GetMyAthlete());

            this.Orientation       = StackOrientation.Horizontal;
            this.BackgroundColor   = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorBackground : Config.ColorBackgroundWhite;
            this.HeightRequest     = Config.LargeButtonsHeight;// 40;
            this.Padding           = new Thickness(15, 0, 10, 0);
            this.Spacing           = 5;
            this.HorizontalOptions = LayoutOptions.FillAndExpand;
            this.VerticalOptions   = LayoutOptions.Start;

            this.labelLabel = new BybLabel()
            {
                TextColor       = Config.App == MobileAppEnum.SnookerForVenues ? Config.ColorTextOnBackgroundGrayed : Config.ColorGrayTextOnWhite,
                VerticalOptions = LayoutOptions.Center,
            };
            this.NameAsCommunity = true;
            this.Children.Add(this.labelLabel);
            this.labelCommunityName = new BybLabel()
            {
                Text              = Selection.ToString(),
                FontFamily        = Config.FontFamily,
                FontAttributes    = FontAttributes.Bold,
                TextColor         = Config.App == MobileAppEnum.SnookerForVenues ? Color.White : Color.Black,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            this.Children.Add(this.labelCommunityName);
            this.labelAskToTap = new BybLabel()
            {
                IsVisible       = false,
                Text            = "(tap here)",
                FontFamily      = Config.FontFamily,
                TextColor       = Color.Red,
                VerticalOptions = LayoutOptions.Center,
            };
            this.Children.Add(this.labelAskToTap);

            Image image = new Image()
            {
                VerticalOptions = LayoutOptions.Center,
                WidthRequest    = Config.RedArrowImageSize,
                HeightRequest   = Config.RedArrowImageSize,
                Source          = new FileImageSource()
                {
                    File = "arrowRight.png"
                }
            };

            this.Children.Add(image);

            this.GestureRecognizers.Add(new TapGestureRecognizer()
            {
                Command = new Command(async() =>
                {
                    if (App.Navigator.GetOpenedModalPage(typeof(PickCommunityPage)) != null)
                    {
                        return;
                    }

                    PickCommunityPage page     = new PickCommunityPage();
                    page.AllowFriendsSelection = AllowFriendsSelection;
                    page.DoNotCheckSelection   = this.IsAskToTapVisible;
                    await App.Navigator.NavPage.Navigation.PushModalAsync(page);
                    page.SelectionChanged += (s1, e1) =>
                    {
                        this.Selection = page.Selection;
                        if (this.SelectionChanged != null)
                        {
                            this.SelectionChanged(this, EventArgs.Empty);
                        }
                    };
                    await page.Initialize(this.Selection);
                })
            });
        }