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 MediaBrowserViewModel(LoginFormViewModel loginFormViewModel, IMixViewModelFactory mixViewModelFactory) : this(new MediaLibraryBrowser(), new Settings(), loginFormViewModel, mixViewModelFactory) { }