コード例 #1
0
        public SimplePlaylistViewModel(
            IAudioPlaybackEngine audioPlaybackEngine,
            IWriteLibraryService writeLibraryService,
            IDialogService dialogService,
            TracksSubsetViewModel parentTracksSubsetViewModel,
            IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChangesFlow,
            SimplePlaylist playlist)
            : base(audioPlaybackEngine, writeLibraryService, dialogService, parentTracksSubsetViewModel, sourceTrackViewModelsChangesFlow, playlist)
        {
            this.RemoveTrackFromSubset = ReactiveCommand.CreateFromTask(
                async(TrackViewModel trackViewModel) =>
            {
                var selectedItem = this.SelectedTrackViewModel;

                if (this.SelectedTrackViewModel == trackViewModel)
                {
                    // TODO: use dynamicdata watch overload to expose selected item as filter by id
                    this.SelectedTrackViewModel = null;
                }

                try
                {
                    // TODO: handle null? should not happen
                    await this.Playlist?.Remove(trackViewModel.Id);
                }
                catch
                {
                    this.SelectedTrackViewModel = selectedItem;
                }
            })
                                         .DisposeWith(this._disposables);
            this.RemoveTrackFromSubset.ThrownExceptions
            .Subscribe(ex => Debug.WriteLine(ex))
            .DisposeWith(this._disposables);
        }
コード例 #2
0
 public AllTracksViewModel(
     IAudioPlaybackEngine audioPlaybackEngine,
     IWriteLibraryService writeLibraryService,
     IDialogService dialogService,
     TracksSubsetViewModel parentTracksSubsetViewModel,
     IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChanges)
     : base(audioPlaybackEngine, writeLibraryService, dialogService, parentTracksSubsetViewModel, sourceTrackViewModelsChanges)
 {
 }
コード例 #3
0
 public PlaylistBaseViewModel(
     IAudioPlaybackEngine audioPlaybackEngine,
     IWriteLibraryService writeLibraryService,
     IDialogService dialogService,
     TracksSubsetViewModel parentTracksSubsetViewModel,
     IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChangesFlow,
     PlaylistBase playlist)
     : base(audioPlaybackEngine, writeLibraryService, dialogService, parentTracksSubsetViewModel, sourceTrackViewModelsChangesFlow)
 {
     this._playlist = playlist ?? throw new ArgumentNullException(nameof(playlist));
 }
コード例 #4
0
        public FolderPlaylistViewModel(
            IAudioPlaybackEngine audioPlaybackEngine,
            IWriteLibraryService writeLibraryService,
            IDialogService dialogService,
            TracksSubsetViewModel parentTracksSubsetViewModel,
            IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChangesFlow,
            FolderPlaylist playlistFolder,
            Func <PlaylistBase, FolderPlaylistViewModel, PlaylistBaseViewModel> playlistViewModelFactoryMethod)
            : base(audioPlaybackEngine, writeLibraryService, dialogService, parentTracksSubsetViewModel, sourceTrackViewModelsChangesFlow, playlistFolder)
        {
            this._playlistViewModelFactoryMethod = playlistViewModelFactoryMethod ?? throw new ArgumentNullException(nameof(playlistViewModelFactoryMethod));

            this._childrenSubscription = new SerialDisposable().DisposeWith(this._disposables);
        }
コード例 #5
0
        public TracksSubsetViewModel(
            IAudioPlaybackEngine audioPlaybackEngine,
            IWriteLibraryService writeLibraryService,
            IDialogService dialogService,
            TracksSubsetViewModel parentTracksSubsetViewModel,
            IObservable <IChangeSet <TrackViewModel, uint> > sourceTrackViewModelsChanges)
        {
            this._audioPlaybackEngine          = audioPlaybackEngine ?? throw new ArgumentNullException(nameof(audioPlaybackEngine));
            this._writeLibraryService          = writeLibraryService ?? throw new ArgumentNullException(nameof(writeLibraryService));
            this._dialogService                = dialogService ?? throw new ArgumentNullException(nameof(dialogService));
            this._sourceTrackViewModelsChanges = sourceTrackViewModelsChanges ?? throw new ArgumentNullException(nameof(sourceTrackViewModelsChanges));

            this.ParentTracksSubsetViewModel = parentTracksSubsetViewModel;

            this._serialViewModelsChangesSubscription = new SerialDisposable().DisposeWith(this._disposables);

            this._areTracksLoaded = this
                                    .WhenAnyValue(x => x.SortedFilteredTrackViewModelsROOC)
                                    .Select(x => x != null)
                                    .StartWith(this.SortedFilteredTrackViewModelsROOC != null)
                                    .ToProperty(this, nameof(this.AreTracksLoaded), deferSubscription: true)
                                    .DisposeWith(this._disposables);

            //this._tracksCount_OAPH = this
            //    .WhenAnyObservable(
            //        x => x.WhenPropertyChanged(e => e.SortedFilteredTrackViewModelsROOC, true, null)
            //    )
            //    .Select(p => p?.Value?.Count)
            //    .ToProperty(this, nameof(this.TracksCount))
            //    .DisposeWith(this._disposables);

            this.PlayTrack = ReactiveCommand.CreateFromTask(
                async(TrackViewModel trackVM) =>
            {
                // TODO: add ConfigureAwait
                await this._audioPlaybackEngine.StopAsync() /*.ConfigureAwait(false)*/;
                await this._audioPlaybackEngine.LoadAndPlayAsync(trackVM.Track) /*.ConfigureAwait(false)*/;
            },
                Observable.CombineLatest(
                    this.WhenAnyValue(t => t.SelectedTrackViewModel),
                    this._audioPlaybackEngine.WhenCanLoadChanged,
                    this._audioPlaybackEngine.WhenCanPlayChanged,
                    this._audioPlaybackEngine.WhenCanStopChanged,
                    (selectedTrackViewModel, canLoad, canPlay, canStop) => selectedTrackViewModel != null && (canLoad || canPlay || canStop)))
                             .DisposeWith(this._disposables);
            this.PlayTrack.ThrownExceptions
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(ex => Debug.WriteLine(ex))
            .DisposeWith(this._disposables);

            this.RemoveTrackFromLibrary = ReactiveCommand.CreateFromTask(
                async(TrackViewModel trackViewModel) =>
            {
                if (this.SelectedTrackViewModel == trackViewModel)
                {
                    this.SelectedTrackViewModel = null;
                }

                await this._writeLibraryService.RemoveTrackAsync(new RemoveTrackCommand(trackViewModel.Id));
            })
                                          .DisposeWith(this._disposables);
            this.RemoveTrackFromLibrary.ThrownExceptions
            .Subscribe(ex => Debug.WriteLine(ex))
            .DisposeWith(this._disposables);
        }