Ejemplo n.º 1
0
        protected override void Initialize()
        {
            InitializeComponent();
            Title = "Leaderboard";

            list.ItemSelected += async(sender, e) =>
            {
                if (list.SelectedItem == null)
                {
                    return;
                }

                var vm = list.SelectedItem as MembershipViewModel;
                list.SelectedItem = null;
                var page = new MembershipDetailsPage(vm.Membership.Id);

                await Navigation.PushAsync(page);
            };

            if (ViewModel.League != null)
            {
                ViewModel.LocalRefresh();
            }

            SubscribeToChallenges();
        }
Ejemplo n.º 2
0
        async protected override void Initialize()
        {
            InitializeComponent();
            Title = ViewModel.League?.Name;

            rankStrip.Membership = ViewModel.CurrentMembership;             //Binding is not working in XAML for some reason
            scrollView.Scrolled += (sender, e) => Parallax();
            Parallax();

            btnRefresh.Clicked += async(sender, e) =>
            {
                using (new HUD("Refreshing..."))
                {
                    await ViewModel.RefreshLeague(true);

                    rankStrip.Membership = ViewModel.CurrentMembership;
                }
            };

            ongoingCard.OnClicked = () =>
            {
                PushChallengeDetailsPage(ViewModel.OngoingChallengeViewModel?.Challenge);
            };

            ongoingCard.OnPostResults = async() =>
            {
                var challenge = ViewModel.CurrentMembership.OngoingChallenge;
                if (challenge == null)
                {
                    return;
                }

                var page = new MatchResultsFormPage(challenge);
                page.AddDoneButton("Cancel");

                page.OnMatchResultsPosted = () =>
                {
                    _didPost = true;
                    PushChallengeDetailsPage(challenge, true);
                    ViewModel.RefreshLeague();
                    rankStrip.Membership = ViewModel.CurrentMembership;
                };

                await Navigation.PushModalAsync(page.GetNavigationPage());
            };

            ongoingCard.OnNudge = async() =>
            {
                using (new HUD("Nudging..."))
                {
                    await ViewModel.OngoingChallengeViewModel.NudgeAthlete();
                }

                "{0} has been nudged.".Fmt(ViewModel.OngoingChallengeViewModel.Opponent.Alias).ToToast();
            };

            ongoingCard.OnAccepted = async() =>
            {
                bool success;
                using (new HUD("Accepting challenge..."))
                {
                    success = await ViewModel.OngoingChallengeViewModel.AcceptChallenge();
                }

                if (success)
                {
                    await ViewModel.RefreshLeague();

                    "Accepted".ToToast();
                }
            };

            ongoingCard.OnDeclined = async() =>
            {
                var decline = await DisplayAlert("Really?", "Are you sure you want to cowardly decline this honorable duel?", "Yes", "No");

                if (!decline)
                {
                    return;
                }

                bool success;
                using (new HUD("Declining..."))
                {
                    success = await ViewModel.OngoingChallengeViewModel.DeclineChallenge();
                }

                if (success)
                {
                    await ViewModel.RefreshLeague();

                    "Challenge declined".ToToast();
                }
            };

            if (ViewModel.League != null && ViewModel.League.CreatedByAthleteId != null && ViewModel.League.CreatedByAthlete == null)
            {
                await ViewModel.LoadAthlete();
            }

            rankStrip.OnAthleteClicked = async(membership) =>
            {
                var page = new MembershipDetailsPage(membership.Id);
                await Navigation.PushAsync(page);
            };

            SubscribeToChallenges();
            ViewModel.NotifyPropertiesChanged();

            if (ViewModel.CurrentMembership != null && ViewModel.CurrentMembership.CurrentRank == 0)
            {
                HeapGloriousPraise();
            }
        }