Esempio n. 1
0
        protected async Task GetTracksCommonAsync(IList <TrackInfo> tracks, TrackOrder trackOrder)
        {
            try
            {
                // Do we need to show the TrackNumber?
                bool showTracknumber = this.TrackOrder == TrackOrder.ByAlbum;

                // Create new ObservableCollection
                ObservableCollection <TrackInfoViewModel> trackInfoViewModels = new ObservableCollection <TrackInfoViewModel>();

                // Order the incoming Tracks
                List <TrackInfo> orderedTracks = await Core.Database.Utils.OrderTracksAsync(tracks, trackOrder);

                await Task.Run(() =>
                {
                    foreach (TrackInfo ti in orderedTracks)
                    {
                        TrackInfoViewModel tivm = this.container.Resolve <TrackInfoViewModel>();
                        tivm.TrackInfo          = ti;
                        tivm.ShowTrackNumber    = showTracknumber;
                        trackInfoViewModels.Add(tivm);
                    }
                });

                // Unbind to improve UI performance
                if (this.TracksCvs != null)
                {
                    this.TracksCvs.Filter -= new FilterEventHandler(TracksCvs_Filter);
                }
                this.Tracks    = null;
                this.TracksCvs = null;

                // Populate ObservableCollection
                this.Tracks = trackInfoViewModels;
            }
            catch (Exception ex)
            {
                LogClient.Instance.Logger.Error("An error occurred while getting Tracks. Exception: {0}", ex.Message);

                // Failed getting Tracks. Create empty ObservableCollection.
                this.Tracks = new ObservableCollection <TrackInfoViewModel>();
            }

            // Populate CollectionViewSource
            this.TracksCvs = new CollectionViewSource {
                Source = this.Tracks
            };
            this.TracksCvs.Filter += new FilterEventHandler(TracksCvs_Filter);

            // Update count
            this.TracksCount = this.TracksCvs.View.Cast <TrackInfoViewModel>().Count();

            // Group by Album if needed
            if (this.TrackOrder == TrackOrder.ByAlbum)
            {
                this.TracksCvs.GroupDescriptions.Add(new PropertyGroupDescription("GroupHeader"));
            }

            // Update duration and size
            this.SetSizeInformationAsync();

            // Show playing Track
            this.ShowPlayingTrackAsync();

            // Set Track artwork
            this.collectionService.SetTrackArtworkAsync(this.Tracks, Constants.ArtworkLoadDelay);
        }
Esempio n. 2
0
        protected void TracksCvs_Filter(object sender, FilterEventArgs e)
        {
            TrackInfoViewModel tivm = e.Item as TrackInfoViewModel;

            e.Accepted = Dopamine.Core.Database.Utils.FilterTracks(tivm.TrackInfo, this.searchService.SearchText);
        }