private void OnPlaylistsCollectionChanged(object sender, PlaylistCollectionChangedEventArgs e)
        {
            Unsubscribe(e.GetRemoved());
            Subscribe(e.GetAdded());

            PlaylistCollectionChanged?.Invoke(this, new SubscriptionsEventArgs <IPlaylistCollection, PlaylistCollectionChangedEventArgs>(sender, e));
        }
Ejemplo n.º 2
0
        public void Change(IEnumerable <IPlaylist> removes, IEnumerable <IPlaylist> adds)
        {
            IPlaylist[] removeArray = removes?.ToArray() ?? new IPlaylist[0];
            IPlaylist[] addArray    = adds?.ToArray() ?? new IPlaylist[0];

            List <ChangeCollectionItem <IPlaylist> > removeChanges = new List <ChangeCollectionItem <IPlaylist> >();
            List <ChangeCollectionItem <IPlaylist> > addChanges    = new List <ChangeCollectionItem <IPlaylist> >();

            foreach (IPlaylist playlist in removeArray)
            {
                int index = IndexOf(playlist);

                if (index == -1)
                {
                    continue;
                }

                removeChanges.Add(new ChangeCollectionItem <IPlaylist>(index, playlist));
                list.RemoveAt(index);
            }

            foreach (IPlaylist playlist in addArray.OrderBy(p => p.AbsolutePath))
            {
                if (this.Contains(playlist))
                {
                    continue;
                }

                int index = WouldIndexOf(this.Select(p => p.AbsolutePath), playlist.AbsolutePath);

                addChanges.Add(new ChangeCollectionItem <IPlaylist>(index, playlist));
                list.Insert(index, playlist);

                playlist.Parent = this;
            }

            if (removeChanges.Count == 0 && addChanges.Count == 0)
            {
                return;
            }

            PlaylistCollectionChangedEventArgs args = new PlaylistCollectionChangedEventArgs(addChanges.ToArray(), removeChanges.ToArray());

            Changed?.Invoke(this, args);
            OnPropertyChanged(nameof(Count));

            UpdateCurrentPlaylist();
        }