Esempio n. 1
0
 private void onLoadStarted()
 {
     loading.Show();
     request?.Cancel();
     cancellationToken?.Cancel();
     cancellationToken = new CancellationTokenSource();
 }
Esempio n. 2
0
        private void loadNewContent()
        {
            loading.Show();

            cancellationToken?.Cancel();
            lastRequest?.Cancel();

            if (Scope.Value == RankingsScope.Spotlights)
            {
                loadContent(new SpotlightsLayout
                {
                    Ruleset = { BindTarget = ruleset }
                });
                return;
            }

            var request = createScopedRequest();

            lastRequest = request;

            if (request == null)
            {
                loadContent(null);
                return;
            }

            request.Success += () => loadContent(createTableFromResponse(request));
            request.Failure += _ => loadContent(null);

            api.Queue(request);
        }
Esempio n. 3
0
        private void onSpotlightChanged(ValueChangedEvent <APISpotlight> spotlight)
        {
            loading.Show();

            cancellationToken?.Cancel();
            getRankingsRequest?.Cancel();

            getRankingsRequest          = new GetSpotlightRankingsRequest(Ruleset.Value, spotlight.NewValue.Id);
            getRankingsRequest.Success += onSuccess;
            api.Queue(getRankingsRequest);
        }
Esempio n. 4
0
        private void getScores()
        {
            getScoresRequest?.Cancel();
            getScoresRequest = null;

            noScoresPlaceholder.Hide();

            if (Beatmap.Value?.OnlineBeatmapID.HasValue != true || Beatmap.Value.Status <= BeatmapSetOnlineStatus.Pending)
            {
                Scores = null;
                content.Hide();
                return;
            }

            if (scope.Value != BeatmapLeaderboardScope.Global && !userIsSupporter)
            {
                Scores = null;
                notSupporterPlaceholder.Show();
                loading.Hide();
                return;
            }

            notSupporterPlaceholder.Hide();

            content.Show();
            loading.Show();

            getScoresRequest          = new GetScoresRequest(Beatmap.Value, Beatmap.Value.Ruleset, scope.Value, modSelector.SelectedMods);
            getScoresRequest.Success += scores =>
            {
                loading.Hide();
                Scores = scores;

                if (!scores.Scores.Any())
                {
                    noScoresPlaceholder.ShowWithScope(scope.Value);
                }
            };

            api.Queue(getScoresRequest);
        }
Esempio n. 5
0
        private void loadNewContent()
        {
            loading.Show();

            cancellationToken?.Cancel();
            lastRequest?.Cancel();

            var request = createScopedRequest();

            lastRequest = request;

            if (request == null)
            {
                loadTable(null);
                return;
            }

            request.Success += () => loadTable(createTableFromResponse(request));
            request.Failure += _ => loadTable(null);

            api.Queue(request);
        }
Esempio n. 6
0
        private void load(IAPIProvider api, NotificationOverlay notifications)
        {
            SpriteIcon icon;

            AddRange(new Drawable[]
            {
                icon = new SpriteIcon
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    Icon   = FontAwesome.Regular.Heart,
                    Size   = new Vector2(18),
                    Shadow = false,
                },
                loading = new DimmedLoadingLayer(0.8f, 0.5f),
            });

            Action = () =>
            {
                if (loading.State.Value == Visibility.Visible)
                {
                    return;
                }

                // guaranteed by disabled state above.
                Debug.Assert(BeatmapSet.Value.OnlineBeatmapSetID != null);

                loading.Show();

                request?.Cancel();

                request = new PostBeatmapFavouriteRequest(BeatmapSet.Value.OnlineBeatmapSetID.Value, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite);

                request.Success += () =>
                {
                    favourited.Toggle();
                    loading.Hide();
                };

                request.Failure += e =>
                {
                    notifications?.Post(new SimpleNotification
                    {
                        Text = e.Message,
                        Icon = FontAwesome.Solid.Times,
                    });

                    loading.Hide();
                };

                api.Queue(request);
            };

            favourited.ValueChanged += favourited => icon.Icon = favourited.NewValue ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart;

            localUser.BindTo(api.LocalUser);
            localUser.BindValueChanged(_ => updateEnabled());

            // must be run after setting the Action to ensure correct enabled state (setting an Action forces a button to be enabled).
            BeatmapSet.BindValueChanged(setInfo =>
            {
                updateEnabled();
                favourited.Value = setInfo.NewValue?.OnlineInfo?.HasFavourited ?? false;
            }, true);
        }