예제 #1
0
        private static void EnqueueCoverRequest(AudioAlbum target)
        {
            lock (_syncRoot)
            {
                if (_requestQueue.ContainsKey(target.Id))
                {
                    if (_requestQueue[target.Id].All(t => t != target))
                        _requestQueue[target.Id].Add(target);
                }
                else
                {
                    _requestQueue.Add(target.Id, new List<AudioAlbum>() { target });
                }
            }

            if (!_isQueueWorking)
                Task.Run(() => StartQueueProcessing()); //вся обработка очереди производится в 1 потоке
        }
예제 #2
0
        private async Task LoadSelectedArtist()
        {
            if (SelectedArtist == null)
                return;

            OnTaskStarted("artists");

            try
            {
                if (Albums.IsNullOrEmpty())
                    await LoadAlbums();

                var albums = await ServiceLocator.LocalMusicService.GetArtistAlbums(SelectedArtist.Id);

                if (!albums.IsNullOrEmpty())
                {
                    foreach (var album in albums)
                    {
                        var tracks = await ServiceLocator.LocalMusicService.GetAlbumTracks(album.Id);
                        if (!tracks.IsNullOrEmpty())
                            album.Tracks = tracks.Cast<Audio>().ToList();
                    }
                }
                else
                {
                    albums = new List<AudioAlbum>();
                }

                if (SelectedArtist == null)
                    return;

                var unsortedTracks = await ServiceLocator.LocalMusicService.GetArtistUnsortedTracks(SelectedArtist.Id);
                if (!unsortedTracks.IsNullOrEmpty())
                {
                    var unsortedAlbum = new AudioAlbum() { Tracks = unsortedTracks.OfType<Audio>().ToList() };
                    albums.Insert(0, unsortedAlbum);
                }

                SelectedArtistAlbums = albums;
                SelectedArtistTracks = albums.SelectMany(a => a.Tracks).Cast<LocalAudio>().ToList();
            }
            catch (Exception ex)
            {
                OnTaskError("artists", ErrorResources.LoadArtistsErrorCommon);

                LoggingService.Log(ex);
            }

            OnTaskFinished("artists");
        }
예제 #3
0
 /// <summary>
 /// Ставит трек в очередь на получение обложки. Когда очередь подойдет, треку будет присвоена обложка.
 /// </summary>
 /// <param name="target"></param>
 public static void RequestCover(AudioAlbum target)
 {
     //ставим трек в очередь и сразу возвращаем null
     EnqueueCoverRequest(target);
 }
예제 #4
0
 /// <summary>
 /// Получить обложку
 /// </summary>
 /// <param name="target"></param>
 public static Task<ImageSource> GetCover(AudioAlbum target)
 {
     return GetImage(target.CoverPath);
 }
예제 #5
0
        private bool UpdateAlbum(AudioAlbum cachedAlbum, AudioAlbum updatedAlbum)
        {
            bool changed = false;

            if (cachedAlbum.Title != updatedAlbum.Title)
            {
                cachedAlbum.Title = updatedAlbum.Title;
                changed = true;
            }

            if (cachedAlbum.Artist != updatedAlbum.Artist)
            {
                cachedAlbum.Artist = updatedAlbum.Artist;
                changed = true;
            }

            if (cachedAlbum.ArtistId != updatedAlbum.ArtistId)
            {
                cachedAlbum.ArtistId = updatedAlbum.ArtistId;
                changed = true;
            }

            if (cachedAlbum.CoverPath != updatedAlbum.CoverPath)
            {
                cachedAlbum.CoverPath = updatedAlbum.CoverPath;
                changed = true;
            }

            if (cachedAlbum.Year != updatedAlbum.Year)
            {
                cachedAlbum.Year = updatedAlbum.Year;
                changed = true;
            }

            return changed;
        }