public MixViewModel(Mix mixModel, IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IObservable <bool> userLoggedInObservable) { mixModel.CurrentTrackIndexObservable.Subscribe(x => { // if we're playing a track that has already been added CurrentTrackIndex = x; UpdateCurrentTrackIndicator(); }); mixModel.LikedByCurrentUserObservable.Subscribe(x => LikedByCurrentUser = x); this.Model = mixModel; Play = ReactiveCommand.Create(_ => true); Play.Subscribe(_ => playbackController.Play(Model)); ToggleLike = Model != Mix.NoMixAvailable ? new ReactiveAsyncCommand(userLoggedInObservable, 1) : new ReactiveAsyncCommand(Observable.Return(false), 1); ToggleLike.RegisterAsyncAction(_ => mediaLibraryBrowser.ToggleLike(Model)); this.isUserRequested = ConfigurationManager.AppSettings["AudioPlayer"] == null || !ConfigurationManager.AppSettings["AudioPlayer"].Equals("DirectX WMI 3.14169"); ReplaySubject <bool> skippingSongAllowed = new ReplaySubject <bool>(1); //skipping not allowed if there are no tracks in the mix Model.CurrentTrackIndexObservable.Select(trackIndex => trackIndex < Model.Tracks.Count && trackIndex >= 0 ? Model.Tracks[trackIndex].IsSkipAllowed : false).Subscribe(skippingSongAllowed.OnNext); NextSong = new ReactiveAsyncCommand(skippingSongAllowed, 1); NextSong.RegisterAsyncAction(_ => { try { playbackController.NextSong(isUserRequested); } catch (Exception e) { log.Error("Unable to go to the next song", e); } }); Tracks = new DispatchedReactiveCollection <TrackViewModel>(); // merge current items and future ones Observable.Merge(Model.Tracks.ToObservable(), Model.Tracks.ItemsAdded) .Select(CreateTrackViewModel) .Subscribe(trackViewModel => { Tracks.Add(trackViewModel); UpdateCurrentTrackIndicator(); }); Download = ReactiveCommand.Create(_ => Model != Mix.NoMixAvailable); Download.Subscribe(_ => { string destinationFolder = FileSystemBrowser.GetSaveToDirectory(); if (String.IsNullOrEmpty(destinationFolder)) { return; } destinationFolder += Path.DirectorySeparatorChar + Model.Name; FileSystemBrowser.TryCreateDirectory(destinationFolder); Tracks // .Where( // trackViewModel => // trackViewModel.TrackLocation.Equals(FileLocation.Online.ToString())) .ToObservable() .Subscribe(trackViewModel => SaveTrack(trackViewModel, destinationFolder)); }); FileSystemBrowser = new FileSystemBrowser(); WebAccessProxy = new WebAccessProxy(); // _TotalNumberOfTracks = Tracks.CollectionCountChanged // .ToProperty(this, x => x.TotalNumberOfTracks); CurrentTrackIndexAsString = "0"; skippingSongAllowed.OnNext(false); }
private void TheApplicationIssuesACommandToToggleLikingAMix() { mediaLibraryBrowser.ToggleLike(mix); }