Example #1
0
        public static PagesLoader From([NotNull] SpotifySession session, [NotNull] String context)
        {
            var loader = new PagesLoader(session)
            {
                _resolveUrl = context
            };

            return(loader);
        }
Example #2
0
        public static PagesLoader From([NotNull] SpotifySession session, [NotNull] Context context)
        {
            var pages = context.Pages.ToList();

            if (!pages.Any())
            {
                return(From(session, context.Uri));
            }

            var loader = new PagesLoader(session);

            loader._pages.AddRange(pages);
            return(loader);
        }
Example #3
0
        public void ToggleShuffle(bool value)
        {
            if (!_state.Context.IsFinite())
            {
                throw new Exception("Cannot shuffle infinite context!");
            }
            if (Tracks.Count() <= 1)
            {
                return;
            }
            if (_isPlayingQueue)
            {
                return;
            }

            if (value)
            {
                if (!_cannotLoadMore)
                {
                    if (LoadAllTracks())
                    {
                        Debug.WriteLine("Loaded all tracks before shuffling.");
                    }
                    else
                    {
                        Debug.WriteLine("Cannot shuffle context!");
                        return;
                    }
                }

                var currentlyPlaying = _state.GetCurrentPlayableOrThrow();
                _shuffle.Shuffle(Tracks, true);
                _shuffleKeepIndex = Tracks.FindIndex(x => x.Uri == currentlyPlaying.Uri);
                Tracks.Swap(0, _shuffleKeepIndex);
                SetCurrentTrackIndex(0);

                Debug.WriteLine("Shuffled context! keepIndex: {0}", _shuffleKeepIndex);
            }
            else
            {
                if (_shuffle.CanUnshuffle(Tracks.Count))
                {
                    var currentlyPlaying = _state.GetCurrentPlayableOrThrow();
                    if (_shuffleKeepIndex != -1)
                    {
                        Tracks.Swap(0, _shuffleKeepIndex);
                    }

                    _shuffle.Unshuffle(Tracks);
                    SetCurrentTrackIndex(Tracks.FindIndex(x => x.Uri == currentlyPlaying.Uri));

                    Debug.WriteLine("Unshuffled using Fisher-Yates.");
                }
                else
                {
                    var id = _state.GetCurrentPlayableOrThrow();

                    Tracks.Clear();
                    _state.Pages = PagesLoader.From(_state.Session, _state.Context.Uri());
                    LoadAllTracks();

                    SetCurrentTrackIndex(Tracks.FindIndex(x => x.Uri == id.Uri));
                    Debug.WriteLine("Unshuffled by reloading context.");
                }
            }
        }