Ejemplo n.º 1
0
        public RecordControl()
        {
            this.metadata = new MetadataHelper().CreateDefault();

            this.Padding         = new Thickness(0);
            this.BackgroundColor = Config.ColorGrayBackground;

            // new match panel
            this.metadataControl         = new SnookerMatchMetadataControl(this.metadata, true);
            this.metadataControl.Padding = new Thickness(0, 0, 0, 0);
            this.buttonNewMatch          = new BybButton()
            {
                Text              = "Record a match",
                Style             = (Style)App.Current.Resources["BlackButtonStyle"],
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            this.buttonNewBreak = new BybButton()
            {
                Text              = "Record a break",
                Style             = (Style)App.Current.Resources["BlackButtonStyle"],
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            this.buttonNewMatch.Clicked += buttonNewMatch_Clicked;
            this.buttonNewBreak.Clicked += buttonNewBreak_Clicked;
            this.panelNewMatch           = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Spacing     = 0,
                Padding     = new Thickness(0),
                Children    =
                {
                    this.metadataControl,
                    new StackLayout()
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Padding           = new Thickness(0,        12, 0, 0),
                        Spacing           = Config.SpaceBetweenButtons,
                        Children          =
                        {
                            this.buttonNewBreak,
                            this.buttonNewMatch,
                        }
                    }
                }
            };

            // paused matches panel
            this.panelPausedMatches = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Spacing     = 0,
                Padding     = new Thickness(0, 0, 0, 0)
            };

            // the top level stack
            this.stackTopLevel = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Padding     = new Thickness(12, 12, 12, 12),
                Spacing     = 0,
                Children    =
                {
                    this.panelPausedMatches,
                    this.panelNewMatch,
                }
            };
            this.Content = this.stackTopLevel;

            this.stackTopLevel.GestureRecognizers.Add(new TapGestureRecognizer()
            {
                Command = new Command(() =>
                {
                    App.Navigator.ShowInternalOptions();
                }),
                NumberOfTapsRequired = 2,
            });
        }
Ejemplo n.º 2
0
        void fillPausedMatches()
        {
            // incompleted matches in the db
            var scoreObjs = (from i in App.Repository.GetScores(false)
                             where i.IsUnfinished == true
                             orderby i.TimeModified descending
                             select i).ToList();

            this.panelNewMatch.IsVisible = scoreObjs.Count() == 0;
            this.panelPausedMatches.Children.Clear();

            foreach (var scoreObj in scoreObjs)
            {
                var match         = SnookerMatchScore.FromScore(scoreObj.AthleteAID, scoreObj);
                var matchMetadata = new MetadataHelper().FromScoreForYou(match);

                var metadataControl = new SnookerMatchMetadataControl(matchMetadata, true)
                {
                    Padding = new Thickness(0, 0, 0, 0)
                };
                this.panelPausedMatches.Children.Add(metadataControl);

                var buttonDelete = new BybButton()
                {
                    Text              = "Cancel the match",
                    Style             = (Style)App.Current.Resources["BlackButtonStyle"],
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };
                buttonDelete.Clicked += async(s1, e1) =>
                {
                    if (await App.Navigator.NavPage.DisplayAlert("Byb", "Delete this match?", "Yes, delete", "Cancel") == true)
                    {
                        App.Repository.SetIsDeletedOnScore(scoreObj.ScoreID, true);
                        this.DoOnOpen();
                    }
                };

                var buttonContinue = new BybButton()
                {
                    Text              = "Continue the match",
                    Style             = (Style)App.Current.Resources["LargeButtonStyle"],
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };
                buttonContinue.Clicked += async(s1, e1) =>
                {
                    new MetadataHelper().ToScore(matchMetadata, match);

                    var page = new RecordMatchPage(match, false);
                    await App.Navigator.NavPage.Navigation.PushModalAsync(page);
                };

                this.panelPausedMatches.Children.Add(new StackLayout()
                {
                    Orientation       = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Padding           = new Thickness(0, 12, 0, 0),
                    Spacing           = 1,
                    Children          =
                    {
                        buttonDelete,
                        buttonContinue
                    }
                });
                this.panelPausedMatches.Children.Add(new BoxView()
                {
                    HeightRequest = 25
                });

                // load opponent names from web if it's not loaded yet
                if (matchMetadata.OpponentAthleteID > 0 && string.IsNullOrEmpty(matchMetadata.OpponentAthleteName) == true)
                {
                    Task.Run(async() =>
                    {
                        await App.Cache.LoadFromWebserviceIfNecessary_People(new List <int> ()
                        {
                            matchMetadata.OpponentAthleteID
                        });
                        var person = App.Cache.People.Get(matchMetadata.OpponentAthleteID);
                        if (person != null)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                match.OpponentName                = person.Name;
                                match.OpponentPicture             = person.Picture;
                                matchMetadata.OpponentAthleteName = person.Name;
                                matchMetadata.OpponentPicture     = person.Picture;
                                metadataControl.Refill();
                            });
                        }
                    });
                }
                ;
            }
        }