ViewModel for the Views.ReleaseResultView.
Inheritance: Caliburn.Micro.PropertyChangedBase
コード例 #1
0
        /// <summary>
        /// Fetches the release list of the clicked artist via Last.fm.
        /// </summary>
        /// <param name="artist"></param>
        /// <returns>Task.</returns>
        private async Task ArtistClickedLastFm(Artist artist)
        {
            var response = await _lastfmArtistAPI.GetTopAlbumsAsync(artist.Name, false, 1, MaxResults);

            if (response.Success)
            {
                FetchedReleases.Clear();
                foreach (var s in response.Content)
                {
                    FetchedReleaseViewModel vm = new FetchedReleaseViewModel(new Release(s.Name, s.ArtistName, s.Mbid, s.Images.Large));
                    vm.ReleaseClicked += ReleaseClicked;
                    FetchedReleases.Add(vm);
                }

                if (FetchedReleases.Count != 0)
                {
                    FetchedReleaseThroughArtist = true;
                    CurrentView = _releaseResultView;
                    OnStatusUpdated("Successfully fetched releases from '" + artist.Name + "'");
                }
                else
                {
                    OnStatusUpdated("'" + artist.Name + "'" + " has no releases");
                }
            }
            else
            {
                OnStatusUpdated("Error while fetching releases from '" + artist.Name + "'");
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a new <see cref="FetchedReleaseViewModel"/> to the <see cref="FetchedReleases"/>.
        /// </summary>
        /// <param name="name">Name of the release.</param>
        /// <param name="artistName">Name of the artist.</param>
        /// <param name="mbid">Mbid of the release.</param>
        /// <param name="image">Image of the release.</param>
        private void AddReleaseViewModel(string name, string artistName, string mbid, Uri image)
        {
            FetchedReleaseViewModel vm = new FetchedReleaseViewModel(new Release(name, artistName, mbid, image));

            vm.ReleaseClicked += ReleaseClicked;
            FetchedReleases.Add(vm);
        }
コード例 #3
0
    /// <summary>
    /// Fetches the release list of the clicked artist and displays it.
    /// </summary>
    /// <param name="sender">Clicked artist as <see cref="LastArtist"/>.</param>
    /// <param name="e">Ignored.</param>
    public async void ArtistClicked(object sender, EventArgs e)
    {
      if (EnableControls)
      {
        EnableControls = false;

        var artist = sender as LastArtist;

        OnStatusUpdated("Trying to fetch releases from '" + artist.Name + "'");

        var response = await MainViewModel.Client.Artist.GetTopAlbumsAsync(artist.Name);
        if (response.Success)
        {
          FetchedReleases.Clear();
          foreach (var s in response.Content)
          {
            FetchedReleaseViewModel vm = new FetchedReleaseViewModel(s);
            vm.ReleaseClicked += ReleaseClicked;
            FetchedReleases.Add(vm);
          }

          if (FetchedReleases.Count != 0)
          {
            FetchedReleaseThroughArtist = true;
            CurrentView = _releaseResultView;
            OnStatusUpdated("Successfully fetched releases from '" + artist.Name + "'");
          }
          else
            OnStatusUpdated("'" + artist.Name + "'" + " has no releases");
        }
        else
          OnStatusUpdated("Error while fetching releases from '" + artist.Name + "'");

        EnableControls = true;
      }
    }
コード例 #4
0
    /// <summary>
    /// Sarches the entered <see cref="SearchText"/>.
    /// And displays the info.
    /// </summary>
    /// <returns>Task.</returns>
    public async Task Search()
    {
      EnableControls = false;

      if (SearchType == SearchType.Artist)
      {
        OnStatusUpdated("Trying to search for artist '" + SearchText + "'...");

        var response = await MainViewModel.Client.Artist.SearchAsync(SearchText);
        if (response.Success)
        {
          FetchedArtists.Clear();
          foreach (var s in response.Content)
          {
            FetchedArtistViewModel vm = new FetchedArtistViewModel(s);
            vm.ArtistClicked += ArtistClicked;
            FetchedArtists.Add(vm);
          }

          if (FetchedArtists.Count != 0)
          {
            CurrentView = _artistResultView;
            OnStatusUpdated("Found " + FetchedArtists.Count + " artists");
          }
          else
            OnStatusUpdated("Found no artists");
        }
        else
          OnStatusUpdated("Error while searching for artist '" + SearchText + "'");
      }
      else if (SearchType == SearchType.Release)
      {
        OnStatusUpdated("Trying to search for release '" + SearchText + "'");

        var response = await MainViewModel.Client.Album.SearchAsync(SearchText);
        if (response.Success)
        {
          FetchedReleases.Clear();
          foreach (var s in response.Content)
          {
            FetchedReleaseViewModel vm = new FetchedReleaseViewModel(s);
            vm.ReleaseClicked += ReleaseClicked;
            FetchedReleases.Add(vm);
          }

          if (FetchedReleases.Count != 0)
          {
            FetchedReleaseThroughArtist = false;
            CurrentView = _releaseResultView;
            OnStatusUpdated("Found " + FetchedArtists.Count + " releases");
          }
          else
            OnStatusUpdated("Found no releases");
        }
        else
          OnStatusUpdated("Error while searching for release '" + SearchText + "'");
      }

      EnableControls = true;
    }