public MixViewModelFactory(IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IObservable <bool> userLoggedInObservable) { this.playbackController = playbackController; this.mediaLibraryBrowser = mediaLibraryBrowser; this.userLoggedInObservable = userLoggedInObservable; }
public void SetUp() { // testScheduler = new TestScheduler(); // origSched = RxApp.DeferredScheduler; // RxApp.DeferredScheduler = testScheduler; lockObject = new ManualResetEvent(false); requestExecutor = new RequestExecutorStub(); audioPlayerStub = new AudioPlayerStub(); playbackController = new PlaybackController(audioPlayerStub, requestExecutor); authenticator = new Authenticator(requestExecutor, new SettingsStub()); mediaLibraryBrowser = new MediaLibraryBrowser(requestExecutor); requestExecutor.Responses.Add(new LoginResponse() { LoggedIn = false, CurrentUserElement = new CurrentUserElement() { Login = "******", Slug = "userSlug" } }); loginFormViewModel = new LoginFormViewModel(authenticator); mediaBrowserViewModel = new MediaBrowserViewModel(mediaLibraryBrowser, new SettingsStub(), loginFormViewModel, new MixViewModelFactory(playbackController, mediaLibraryBrowser, loginFormViewModel.UserLoggedInObservable)); }
public void SetUp() { origSched = RxApp.DeferredScheduler; RxApp.DeferredScheduler = new TestScheduler(); requestExecutor = new RequestExecutorStub(); mediaLibraryBrowser = new MediaLibraryBrowser(requestExecutor); mix = new Mix(new MixElement(), 0); mixFilter = new MixFilter(); }
public MainWindowViewModel(IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IAuthenticator authenticator, Settings settings) { LoginFormViewModel = new LoginFormViewModel(authenticator); LoginFormViewModel.UserDataObservable.Subscribe( userData => mediaLibraryBrowser.UserToken = userData.UserToken); IMixViewModelFactory mixViewModelFactory = new MixViewModelFactory(playbackController, mediaLibraryBrowser, LoginFormViewModel.UserLoggedInObservable); this.MediaBrowserViewModel = new MediaBrowserViewModel(mediaLibraryBrowser, settings, LoginFormViewModel, mixViewModelFactory); this.PlaybackViewModel = new PlaybackViewModel(playbackController, settings, mixViewModelFactory); new TrackReporter(playbackController.CurrentMixObservable, playbackController.CurrentPositionObservable); }
public MediaBrowserViewModel(IMediaLibraryBrowser mediaLibraryBrowser, Settings settings, LoginFormViewModel loginFormViewModel, IMixViewModelFactory mixViewModelFactory) { this.settings = settings; this.mixViewModelFactory = mixViewModelFactory; this.mediaLibraryBrowser = mediaLibraryBrowser; GetRecentlyMadeMixes = new ReactiveAsyncCommand(null, 1); GetRecentlyMadeMixes.RegisterAsyncFunction( _ => mediaLibraryBrowser.GetRecentlyMadeMixes(CreateMixFilter(Filter))) .Subscribe(SetBrowsedMixes); GetHotMixes = new ReactiveAsyncCommand(null, 1); GetHotMixes.RegisterAsyncFunction(_ => mediaLibraryBrowser.GetHotMixes(CreateMixFilter(Filter))).Subscribe( SetBrowsedMixes); GetPopularMixes = new ReactiveAsyncCommand(null, 1); GetPopularMixes.RegisterAsyncFunction(_ => mediaLibraryBrowser.GetPopularMixes(CreateMixFilter(Filter))) .Subscribe(SetBrowsedMixes); // command is enabled only if the user is logged in GetLikedMixes = new ReactiveAsyncCommand(loginFormViewModel.UserLoggedInObservable, 1); GetLikedMixes.RegisterAsyncFunction(_ => { var mixFilter = CreateMixFilter(Filter); string userSlug = loginFormViewModel.UserData.UserSlug; return(mediaLibraryBrowser.GetLikedMixes(mixFilter, userSlug)); }).Subscribe(SetBrowsedMixes); // command is enabled only if the user is logged in GetFeedMixes = new ReactiveAsyncCommand(loginFormViewModel.UserLoggedInObservable, 1); GetFeedMixes.RegisterAsyncFunction(_ => { var mixFilter = CreateMixFilter(Filter); string userSlug = loginFormViewModel.UserData.UserSlug; return(mediaLibraryBrowser.GetFeedMixes(mixFilter, userSlug)); }).Subscribe(SetBrowsedMixes); GetRecommendedMixes = new ReactiveAsyncCommand(loginFormViewModel.UserLoggedInObservable, 1); GetRecommendedMixes.RegisterAsyncFunction(_ => { var mixFilter = CreateMixFilter(Filter); string userSlug = loginFormViewModel.UserData.UserSlug; return(mediaLibraryBrowser.GetRecommendedMixes(mixFilter, userSlug)); }).Subscribe(SetBrowsedMixes); GetHistoryMixes = new ReactiveAsyncCommand(loginFormViewModel.UserLoggedInObservable, 1); GetHistoryMixes.RegisterAsyncFunction(_ => { var mixFilter = CreateMixFilter(Filter); string userSlug = loginFormViewModel.UserData.UserSlug; return(mediaLibraryBrowser.GetHistoryMixes(mixFilter, userSlug)); }).Subscribe(SetBrowsedMixes); BrowsedMixes = new DispatchedReactiveCollection <MixViewModel>(); ReplaySubject <bool> browsedMixesExistObservable = new ReplaySubject <bool>(1); BrowsedMixes.CollectionCountChanged.Select(count => count > 0).Subscribe(browsedMixesExistObservable.OnNext); browsedMixesExistObservable.OnNext(false); GetMoreMixes = new ReactiveAsyncCommand(browsedMixesExistObservable, 1); GetMoreMixes.RegisterAsyncFunction(_ => mediaLibraryBrowser.GetMoreMixes()) .Subscribe(AddBrowsedMixes); // set can execute only if there is something in the list SetMixDisplayMode = new ReactiveCommand(browsedMixesExistObservable); SetMixDisplayMode.Subscribe(mode => MixDisplayMode = (MixDisplayMode)mode); ApplyFilter = new ReactiveCommand(); ApplyFilter.Where(_ => Filter.Length > 0) .Subscribe(_ => { // if we only started up the application, by search for Hot mixes if (mediaLibraryBrowser.SessionData.IsEmpty) { GetHotMixes.Execute(null); return; } // otherwise, take the same type of mixes as they were before switch (mediaLibraryBrowser.SessionData.LastMixesRequest.ViewType) { case MixesViewType.Hot: GetHotMixes.Execute(null); break; case MixesViewType.Popular: GetPopularMixes.Execute(null); break; case MixesViewType.Recent: GetRecentlyMadeMixes.Execute(null); break; case MixesViewType.Liked: GetLikedMixes.Execute(null); break; case MixesViewType.Feed: GetFeedMixes.Execute(null); break; case MixesViewType.Listened: GetHistoryMixes.Execute(null); break; case MixesViewType.Recommended: GetRecommendedMixes.Execute(null); break; default: // throw new ArgumentOutOfRangeException(); break; } }); MixDisplayMode mixDisplayMode; string storedMixDisplayModeString = (string)settings[mixdisplayModeKey]; Enum.TryParse <MixDisplayMode>(storedMixDisplayModeString, out mixDisplayMode); MixDisplayMode = mixDisplayMode; MixesViewTypeAsString = String.Empty; Filter = String.Empty; MixBrowsingMessage = String.Empty; }
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); }