Example #1
0
        /// <summary>
        /// Rebind the playlist to the view after it's been randified
        /// </summary>
        /// <returns></returns>
        public async Task BindPlaylistAfterSort(List <PlaylistTrack> playlistTracks)
        {
            PlaylistTracks.Clear();
            PlaylistTracks.AddRange(playlistTracks);

            NumberOfLoadedTracks = PlaylistTracks.Count();

            IsPlaylistLoading = false;

            Stopwatch.Stop();

            StateHasChanged();
        }
Example #2
0
        /// <summary>
        /// Drop down list changed event to bind the playlist to the view
        /// </summary>
        /// <returns></returns>
        public async Task BindPlaylist(ChangeEventArgs e)
        {
            if (IsRandifying || IsPlaylistLoading)
            {
                return;
            }

            var playlistId = e.Value.ToString();

            try
            {
                IsPlaylistLoading    = true;
                Seconds              = 0;
                NumberOfLoadedTracks = 0;

                Stopwatch = new Stopwatch();
                Stopwatch.Start();
                PlaylistTracks.Clear();

                try
                {
                    var tracks = new List <PlaylistTrack>();

                    CurrentPlaylist = Playlists.FirstOrDefault(o => o.Id == playlistId);
                    var page = await SpotifyService.GetPlaylistTracks(AuthenticationService.User, AuthenticationService.AuthenticationToken, CurrentPlaylist);

                    do
                    {
                        foreach (var playlistTrack in page.Items)
                        {
                            tracks.Add(playlistTrack);
                        }

                        Seconds = Stopwatch.Elapsed.Seconds;
                        NumberOfLoadedTracks = tracks.Count();

                        StateHasChanged();

                        if (page.HasNextPage)
                        {
                            page = await SpotifyService.GetNextPage(page, AuthenticationService.AuthenticationToken);
                        }
                        else
                        {
                            page = null;
                        }
                    }while (page != null);

                    PlaylistTracks = tracks;
                }
                catch (Exception ex)
                {
                    PageException = ex;
                }

                NumberOfLoadedTracks = PlaylistTracks.Count();
                IsPlaylistLoading    = false;
                Stopwatch.Stop();

                StateHasChanged();
            }
            catch (Exception ex)
            {
                PageException = ex;
            }
        }