示例#1
0
        public async void LoadTopTracks(string songName, string similarTrackArtistName, int id)
        {
            await DispatcherHelper.RunAsync(async() =>
            {
                int count = 10;
                if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.Mobile")
                {
                    count = 20;
                }

                ClearNowPlayingViewModelData();

                Message              = Core.StringMessage.LoadingPleaseWait;
                IsLoading            = true;
                SimilarTrackVisible  = true;
                SimilarArtistVisible = false;
                // viewModelCleared = false;

                SimilarTracks = new ObservableCollection <Base>();

                try
                {
                    var webResults = await _service.GetSimilarTracksAsync(songName, similarTrackArtistName, count);

                    if (webResults == null || webResults.Songs.Count < 1)
                    {
                        SimilarTrackVisible  = false;
                        SimilarArtistVisible = true;
                        var o          = await _service.GetSimilarArtistsAsync(similarTrackArtistName, 10);
                        SimilarArtists = o?.Artists;
                        if (o != null)
                        {
                            o = null;
                        }
                    }
                    else
                    {
                        int indexToAdd = -1;
                        foreach (var simpleTrack in webResults.Songs)
                        {
                            indexToAdd++;
                            SimilarTracks.Add(simpleTrack);
                            if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 ||
                                indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99)
                            {
                                SimilarTracks.Insert(indexToAdd, new ListAdvert());
                            }
                        }
                    }

                    if (webResults != null)
                    {
                        webResults = null;
                    }
                }
                catch (Exception)
                {
                    Message = Core.StringMessage.SomethinWentWrong;
                }

                if ((SimilarArtists != null && SimilarArtists.Count() > 0) ||
                    (SimilarTracks != null && SimilarTracks.Count > 0))
                {
                    Message = Core.StringMessage.NoMessge;
                }
                else
                {
                    Message = Core.StringMessage.EmptyMessage;
                }

                IsLoading = false;
            });
        }