private void OnSongsCollectionChanged(object sender, SongCollectionChangedEventArgs e) { MobileDebug.Service.WriteEvent("PlaylistSubscribtionHandler.OnSongsCollectionChanged", (sender as ISongCollection)?.Parent?.Name); Unsubscribe(e.GetRemoved()); Subscribe(e.GetAdded()); SongCollectionChanged?.Invoke(this, new SubscriptionsEventArgs <ISongCollection, SongCollectionChangedEventArgs>(sender, e)); }
private void Parent_CollectionChanged(object sender, SongCollectionChangedEventArgs e) { List <ChangeCollectionItem <Song> > adds = new List <ChangeCollectionItem <Song> >(); foreach (Song addSong in e.GetAdded()) { int index = ran.Next(Count - e.RemovedSongs.Length + adds.Count); adds.Add(new ChangeCollectionItem <Song>(index, addSong)); } Change(e.GetRemoved(), adds); }
private void Parent_CollectionChanged(object sender, SongCollectionChangedEventArgs e) { Song[] ordered = GetOrdered(Parent).ToArray(); Change(e.GetRemoved(), e.GetAdded().Select(s => new ChangeCollectionItem <Song>(Array.IndexOf(ordered, s), s))); }
private void Parent_CollectionChanged(object sender, SongCollectionChangedEventArgs e) { Song currentSong = Parent.Parent.CurrentSong; int shuffleIndex = GetCurrentSongIndex(Parent.Count); int shuffleCount = GetCount(Parent.Count); int currentSongIndex = IndexOf(currentSong); List <Song> removes = new List <Song>(); List <ChangeCollectionItem <Song> > adds = new List <ChangeCollectionItem <Song> >(); foreach (Song remove in e.GetRemoved()) { int index = IndexOf(remove); if (index == -1) { continue; } Song add = GetRandomSong(Parent, null, adds.Select(c => c.Item)); ChangeCollectionItem <Song> addChange = new ChangeCollectionItem <Song>(index, add); removes.Add(remove); adds.Add(addChange); } for (int i = currentSongIndex - 1; i >= shuffleIndex; i++) { Song remove = this.ElementAt(i); if (!removes.Contains(remove)) { removes.Add(remove); } else { adds.Remove(adds.FirstOrDefault(c => c.Index == i)); } } for (int i = currentSongIndex; i < shuffleIndex; i++) { Song add = GetRandomSong(Parent, removes, adds.Select(c => c.Item)); ChangeCollectionItem <Song> addChange = new ChangeCollectionItem <Song>(i, add); adds.Add(addChange); } while (Parent.Count - removes.Count + adds.Count > shuffleCount) { if (!adds.Remove(adds.FirstOrDefault(c => c.Index > shuffleIndex))) { removes.Add(this.Except(removes).LastOrDefault()); } } while (Parent.Count - removes.Count + adds.Count < shuffleCount) { int index = Parent.Count - removes.Count + adds.Count; Song add = GetRandomSong(Parent, removes, adds.Select(c => c.Item)); ChangeCollectionItem <Song> addChange = new ChangeCollectionItem <Song>(index, add); adds.Add(addChange); } }