/// <summary>
        /// Handles user input and programmatic changes for viewed songs and selected song
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Input0: CurrentPlaylist.AllSongs, Input1: CurrentPlaylist.CurrentSong, Input2: CurrentPlaylist.WannaSong, Input3: lbxSongs.SelectedIndex</param>
        /// <returns>The list of Songs to view on UI.</returns>
        private object MicCurrentSongIndex_ConvertRef(object sender, MultiplesInputsConvert4EventArgs args)
        {
            if (args.Input0 == null)
            {
                args.Input3 = -1;
                return(null);
            }
            if (args.ChangedValueIndex == 2)
            {
                return(args.Input0);
            }

            IEnumerable <Song> allSongs = (IEnumerable <Song>)args.Input0;
            Song?currentSong            = (Song?)args.Input1;
            int  index = (int)args.Input3;

            if (args.ChangedValueIndex == 3 && index != -1)
            {
                args.Input2 = RequestSong.Start(allSongs.ElementAt(index));
            }
            else if (!currentSong.HasValue)
            {
                args.Input3 = -1;
            }
            else
            {
                args.Input3 = allSongs.IndexOf(currentSong.Value);
            }

            return(allSongs);
        }
Example #2
0
 private object MicException_Convert(object sender, MultiplesInputsConvert4EventArgs args)
 {
     return(args.Input3 ?? args.Input2 ?? args.Input1 ?? args.Input0);
 }
        private object MicPlaylists_Convert(object sender, MultiplesInputsConvert4EventArgs args)
        {
            MultipleInputs4Converter converter = (MultipleInputs4Converter)sender;

            if (args.ChangedValueIndex == 0)
            {
                if (args.OldValue is INotifyCollectionChanged oldList)
                {
                    oldList.CollectionChanged -= OnCollectionChanged;
                }
                if (args.Input0 is INotifyCollectionChanged newList)
                {
                    newList.CollectionChanged += OnCollectionChanged;
                }
            }
            else if (args.ChangedValueIndex == 1)
            {
                if (args.OldValue is INotifyCollectionChanged oldList)
                {
                    oldList.CollectionChanged -= OnCollectionChanged;
                }
                if (args.Input1 is INotifyCollectionChanged newList)
                {
                    newList.CollectionChanged += OnCollectionChanged;
                }
            }

            UpdateAllPlaylists();

            if (args.ChangedValueIndex == 3 && args.Input3 != null)
            {
                args.Input2 = args.Input3;
            }
            else
            {
                args.Input3 = args.Input2;
            }

            return(allPlaylists);

            void OnCollectionChanged(object s, NotifyCollectionChangedEventArgs e)
            {
                UpdateAllPlaylists();
            }

            void UpdateAllPlaylists()
            {
                IPlaylist[] newAllPlaylists = ((IEnumerable <ISourcePlaylist>)converter.Input0).ToNotNull()
                                              .Concat(((IEnumerable <IPlaylist>)converter.Input1).ToNotNull()).ToArray();

                for (int i = allPlaylists.Count - 1; i >= 0; i--)
                {
                    if (!newAllPlaylists.Contains(allPlaylists[i]))
                    {
                        allPlaylists.RemoveAt(i);
                    }
                }

                foreach ((int newIndex, IPlaylist playlist) in newAllPlaylists.WithIndex())
                {
                    int oldIndex = allPlaylists.IndexOf(playlist);
                    if (oldIndex == -1)
                    {
                        allPlaylists.Insert(newIndex, playlist);
                    }
                    else if (oldIndex != newIndex)
                    {
                        allPlaylists.Move(oldIndex, newIndex);
                    }
                }
            }
        }