コード例 #1
0
        public async Task TestUpdateViewSuccess()
        {
            var status = new Status
            {
                track = new Track
                {
                    track_resource = new Resource
                    {
                        name     = "TestName",
                        uri      = "SpotifyUri",
                        location = new Location
                        {
                            og = "https://open.spotify.com/track/trackurl"
                        }
                    },
                    artist_resource = new Resource
                    {
                        name = "TestArtistName"
                    }
                },
                playing = true,
                volume  = 0.5
            };

            _spotifyController.IsSpotifyOpen().Returns(true);
            _spotifyController.GetStatus().Returns(status);
            _settings.SpotifyToken = new MiniPie.Core.SpotifyWeb.Token();
            _coverService.FetchCover(status).Returns("TestCover");
            _spotifyController.IsTracksSaved(null).ReturnsForAnyArgs(new[] { true });
            _spotifyController.GetPlaylists().Returns(new List <Playlist>
            {
                new Playlist
                {
                    Id = "TestId"
                }
            });

            await _shellViewModel.UpdateView();

            Assert.Equal("TestName", _shellViewModel.CurrentTrack);
            Assert.Equal("SpotifyUri", _shellViewModel.SpotifyUri);
            Assert.Equal("https://open.spotify.com/track/trackurl", _shellViewModel.TrackUrl);
            Assert.Equal("TestArtistName – TestName", _shellViewModel.TrackFriendlyName);
            Assert.Equal("trackurl", _shellViewModel.TrackId);
            Assert.Equal("TestCover", _shellViewModel.CoverImage);
            Assert.Equal(0.5, _shellViewModel.Volume);

            Assert.Collection(_shellViewModel.Playlists, playlist => Assert.Equal("TestId", playlist.Id));
        }
コード例 #2
0
ファイル: ShellViewModel.cs プロジェクト: cbradley857/Winfy
        private void UpdateView()
        {
            try {
                var status = _SpotifyController.GetStatus();
                var track  = _SpotifyController.GetSongName();
                var artist = _SpotifyController.GetArtistName();
                var fade   = (status != null && status.Playing);

                if (fade)
                {
                    OnCoverDisplayFadeOut();
                }

                HasTrackInformation = (!string.IsNullOrEmpty(track) || !string.IsNullOrEmpty(artist));
                CurrentTrack        = string.IsNullOrEmpty(track) ? "-" : track;
                CurrentArtist       = string.IsNullOrEmpty(artist) ? "-" : artist;

                CanPlayPause    = _SpotifyController.IsSpotifyOpen();
                CanPlayPrevious = _SpotifyController.IsSpotifyOpen();
                CanPlayNext     = _SpotifyController.IsSpotifyOpen();

                if (_SpotifyController.IsSpotifyOpen() && !string.IsNullOrEmpty(track) && !string.IsNullOrEmpty(artist))
                {
                    if (_Settings.DisableAnimations)
                    {
                        CoverImage = NoCoverUri;                         //Reset cover image, no cover is better than an old one
                    }
                    var updateCoverAction = new Action(() => {
                        var coverUri = _CoverService.FetchCover(artist, track);
                        if (string.IsNullOrEmpty(coverUri))
                        {
                            coverUri = UnknownCoverUri;
                        }
                        CoverImage = coverUri;
                        if (fade)
                        {
                            OnCoverDisplayFadeIn();
                        }
                    });
                    updateCoverAction.BeginInvoke(UpdateCoverActionCallback, null);
                }
                else
                {
                    CoverImage = NoCoverUri;
                    if (fade)
                    {
                        OnCoverDisplayFadeIn();
                    }
                }
            }
            catch (Exception exc) {
                _Logger.FatalException("UpdateView() failed hard", exc);
            }
        }
コード例 #3
0
ファイル: ShellViewModel.cs プロジェクト: DSilence/MiniPie
        internal async Task UpdateView()
        {
            try
            {
                var tokenPresent = _Settings.SpotifyToken != null;
                if (!tokenPresent)
                {
                    NotifyNotLoggedIn?.Invoke(this, Resources.App_NotLoggedIn);
                }
                var status = _SpotifyController.GetStatus();
                if (status == null)
                {
                    return;
                }

                var track  = status.track?.track_resource?.name;
                var artist = status.track?.artist_resource?.name;
                if (status.track != null)
                {
                    MaxProgress = status.track.length;
                    Progress    = status.playing_position;
                    IsPlaying   = status.playing;
                    Volume      = status.volume;

                    if (IsPlaying)
                    {
                        OnCoverDisplayFadeOut();
                    }

                    HasTrackInformation = !string.IsNullOrEmpty(track) || !string.IsNullOrEmpty(artist);
                    var currentTrack      = string.IsNullOrEmpty(track) ? "-" : track;
                    var currentArtist     = string.IsNullOrEmpty(artist) ? "-" : artist;
                    var trackFriendlyName = string.Format(_songFriendlyNameFormat, currentArtist, currentTrack);

                    TrackUrl          = status.track.track_resource?.location.og;
                    SpotifyUri        = status.track.track_resource?.uri;
                    CurrentTrack      = currentTrack;
                    CurrentArtist     = currentArtist;
                    TrackFriendlyName = trackFriendlyName;
                }
                TrackId = GetTrackId(TrackUrl);

                CanPlayPause    = _SpotifyController.IsSpotifyOpen();
                CanPlayPrevious = _SpotifyController.IsSpotifyOpen();
                CanPlayNext     = _SpotifyController.IsSpotifyOpen();
                CanVolumeDown   = _SpotifyController.IsSpotifyOpen();
                CanVolumeUp     = _SpotifyController.IsSpotifyOpen();

                if (_SpotifyController.IsSpotifyOpen() &&
                    !string.IsNullOrEmpty(track) &&
                    !string.IsNullOrEmpty(artist))
                {
                    if (_Settings.DisableAnimations)
                    {
                        CoverImage = NoCoverUri; //Reset cover image, no cover is better than an old one
                    }
                    try
                    {
                        var coverUri = await _CoverService.FetchCover(status);

                        if (string.IsNullOrEmpty(coverUri))
                        {
                            coverUri = UnknownCoverUri;
                        }
                        CoverImage = coverUri;
                        if (IsPlaying)
                        {
                            OnCoverDisplayFadeIn();
                        }
                    }
                    catch (Exception e)
                    {
                        _Logger.WarnException("Failed to retrieve cover information with: " + e.Message, e);
                    }
                }
                else
                {
                    CoverImage = NoCoverUri;
                    if (IsPlaying)
                    {
                        OnCoverDisplayFadeIn();
                    }
                }


                if (tokenPresent)
                {
                    if (TrackId != null)
                    {
                        IsTrackSaved = (await _SpotifyController.IsTracksSaved(new[] { TrackId })).First();
                    }
                    await UpdatePlaylists().ConfigureAwait(false);
                }
            }
            catch (Exception exc)
            {
                _Logger.FatalException("UpdateView() failed hard with: " + exc.Message, exc);
                _Logger.Fatal(exc.StackTrace);
            }
        }