public MenuNavigatePageBaseViewModel( IUnityContainer container, IScheduler scheduler, AppearanceSettings appearanceSettings, PinSettings pinSettings, NiconicoSession niconicoSession, LocalMylistManager localMylistManager, UserMylistManager userMylistManager, VideoCacheManager videoCacheManager, PageManager pageManager, Services.NiconicoLoginService niconicoLoginService, Commands.LogoutFromNiconicoCommand logoutFromNiconicoCommand ) { PageManager = pageManager; NiconicoLoginService = niconicoLoginService; LogoutFromNiconicoCommand = logoutFromNiconicoCommand; Container = container; Scheduler = scheduler; AppearanceSettings = appearanceSettings; PinSettings = pinSettings; NiconicoSession = niconicoSession; LocalMylistManager = localMylistManager; UserMylistManager = userMylistManager; VideoCacheManager = videoCacheManager; NiconicoSession.LogIn += (sender, e) => ResetMenuItems(); NiconicoSession.LogOut += (sender, e) => ResetMenuItems(); CurrentMenuType = new ReactiveProperty <ViewModelBase>(); VideoMenu = App.Current.Container.Resolve <VideoMenuSubPageContent>(); LiveMenu = App.Current.Container.Resolve <LiveMenuSubPageContent>(); // Back Navigation CanGoBackNavigation = new ReactivePropertySlim <bool>(); GoBackNavigationCommand = CanGoBackNavigation .ToReactiveCommand(); GoBackNavigationCommand.Subscribe(_ => { PageManager.NavigationService.GoBack(); }); // TV Mode if (Services.Helpers.DeviceTypeHelper.IsXbox) { IsTVModeEnable = new ReactiveProperty <bool>(true); } else { IsTVModeEnable = AppearanceSettings.ObserveProperty(x => x.IsForceTVModeEnable) .ToReactiveProperty(); } ServiceLevel = NiconicoSession.ObserveProperty(x => x.ServiceStatus) .ToReadOnlyReactiveProperty(); IsNeedFullScreenToggleHelp = ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen; IsOpenPane = new ReactiveProperty <bool>(false); MainSelectedItem = new ReactiveProperty <HohoemaListingPageItemBase>(null, ReactivePropertyMode.DistinctUntilChanged); PinItems = new ObservableCollection <PinItemViewModel>( PinSettings.Pins.Select(x => Container.Resolve <PinItemViewModel>(new ParameterOverride("pin", x))) ); PinSettings.Pins.CollectionChangedAsObservable() .Subscribe(args => { if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { foreach (var item in args.NewItems) { PinItems.Add(Container.Resolve <PinItemViewModel>(new ParameterOverride("pin", item as HohoemaPin))); } } else if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { foreach (var item in args.OldItems) { var removedPin = item as HohoemaPin; var pinVM = PinItems.FirstOrDefault(x => x.Pin == removedPin); if (pinVM != null) { PinItems.Remove(pinVM); } } } }); ResetMenuItems(); // TODO; PinSettings側で自動保存するようにしたい PinItems.CollectionChangedAsObservable() .Subscribe(async _ => { await PinSettings.Save(); }); /* * Observable.Merge( * MainSelectedItem, * SubSelectedItem * ) * .Where(x => x != null) * .Subscribe(x => x.SelectedAction(x.Source)); */ PageManager.ObserveProperty(x => x.CurrentPageType) .Subscribe(pageType => { // IsOpenPane.Value = false; bool isMenuItemOpened = false; foreach (var item in MenuItems) { if ((item as MenuItemViewModel)?.PageType == pageType) { MainSelectedItem.Value = item; isMenuItemOpened = true; break; } } if (!isMenuItemOpened) { MainSelectedItem.Value = null; } if (Services.Helpers.DeviceTypeHelper.IsXbox || AppearanceSettings.IsForceTVModeEnable || Services.Helpers.DeviceTypeHelper.IsMobile ) { IsOpenPane.Value = false; } }); PageManager.ObserveProperty(x => x.PageTitle) .Subscribe(x => { TitleText = x; AddPinToCurrentPageCommand.RaiseCanExecuteChanged(); }); PageManager.ObserveProperty(x => x.CurrentPageType) .Subscribe(_ => UpdateCanGoBackNavigation()); IsVisibleMenu = PageManager.ObserveProperty(x => x.CurrentPageType) .Select(x => { return(!PageManager.IsHiddenMenuPage(x)); }) .ToReactiveProperty(false); NowNavigating = PageManager.ObserveProperty(x => x.PageNavigating) .ToReactiveProperty(); PageManager.StartWork += PageManager_StartWork; PageManager.ProgressWork += PageManager_ProgressWork; PageManager.CompleteWork += PageManager_CompleteWork; PageManager.CancelWork += PageManager_CancelWork; NiconicoSession.ObserveProperty(x => x.IsLoggedIn) .Subscribe(x => IsLoggedIn = x); NiconicoSession.ObserveProperty(x => x.UserName) .Subscribe(x => { UserName = x; }); NiconicoSession.ObserveProperty(x => x.UserIconUrl) .Subscribe(x => UserIconUrl = x); // 検索 SearchKeyword = new ReactiveProperty <string>(""); SearchCommand = new ReactiveCommand(); SearchCommand .Subscribe(async _ => { await Task.Delay(50); var keyword = SearchKeyword.Value; if (string.IsNullOrWhiteSpace(keyword)) { return; } SearchTarget?searchType = CurrentMenuType.Value is LiveMenuSubPageContent ? SearchTarget.Niconama : SearchTarget.Keyword; var searched = Database.SearchHistoryDb.LastSearchedTarget(keyword); if (searched != null) { searchType = searched; } PageManager.Search(SearchPagePayloadContentHelper.CreateDefault(searchType.Value, keyword)); ResetSearchHistoryItems(); }); SearchSuggestionWords = new ObservableCollection <string>(); // InAppNotification IsShowInAppNotification = new ReactiveProperty <bool>(true); // 検索履歴アイテムを初期化 ResetSearchHistoryItems(); }
public MenuNavigatePageBaseViewModel( HohoemaApp hohoemaApp, PageManager pageManager, Models.Niconico.Live.NicoLiveSubscriber nicoLiveSubscriber ) { PageManager = pageManager; HohoemaApp = hohoemaApp; NicoLiveSubscriber = nicoLiveSubscriber; HohoemaApp.OnSignin += HohoemaApp_OnSignin; HohoemaApp.OnSignout += HohoemaApp_OnSignout; CurrentMenuType = new ReactiveProperty <ViewModelBase>(); VideoMenu = new VideoMenuSubPageContent(HohoemaApp, HohoemaApp.UserMylistManager, HohoemaApp.Playlist); LiveMenu = new LiveMenuSubPageContent(NicoLiveSubscriber); // Back Navigation CanGoBackNavigation = new ReactivePropertySlim <bool>(); GoBackNavigationCommand = CanGoBackNavigation .ToReactiveCommand(); GoBackNavigationCommand.Subscribe(_ => { PageManager.NavigationService.GoBack(); }); // TV Mode if (Helpers.DeviceTypeHelper.IsXbox) { IsTVModeEnable = new ReactiveProperty <bool>(true); } else { IsTVModeEnable = HohoemaApp.UserSettings .AppearanceSettings.ObserveProperty(x => x.IsForceTVModeEnable) .ToReactiveProperty(); } ServiceLevel = HohoemaApp.ObserveProperty(x => x.ServiceStatus) .ToReadOnlyReactiveProperty(); IsNeedFullScreenToggleHelp = ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen; IsOpenPane = new ReactiveProperty <bool>(false); MainSelectedItem = new ReactiveProperty <HohoemaListingPageItemBase>(null, ReactivePropertyMode.DistinctUntilChanged); PinItems = HohoemaApp.UserSettings.PinSettings.Pins; ResetMenuItems(); PinItems.CollectionChangedAsObservable() .Subscribe(async _ => { await HohoemaApp.UserSettings.PinSettings.Save(); }); /* * Observable.Merge( * MainSelectedItem, * SubSelectedItem * ) * .Where(x => x != null) * .Subscribe(x => x.SelectedAction(x.Source)); */ PageManager.ObserveProperty(x => x.CurrentPageType) .Subscribe(pageType => { // IsOpenPane.Value = false; bool isMenuItemOpened = false; foreach (var item in MenuItems) { if ((item as MenuItemViewModel)?.PageType == pageType) { MainSelectedItem.Value = item; isMenuItemOpened = true; break; } } if (!isMenuItemOpened) { MainSelectedItem.Value = null; } if (Helpers.DeviceTypeHelper.IsXbox || HohoemaApp.UserSettings.AppearanceSettings.IsForceTVModeEnable) { IsOpenPane.Value = false; } }); PageManager.ObserveProperty(x => x.PageTitle) .Subscribe(x => { TitleText = x; AddPinToCurrentPageCommand.RaiseCanExecuteChanged(); }); PageManager.ObserveProperty(x => x.CurrentPageType) .Subscribe(_ => UpdateCanGoBackNavigation()); IsVisibleMenu = PageManager.ObserveProperty(x => x.CurrentPageType) .Select(x => { return(!PageManager.IsHiddenMenuPage(x)); }) .ToReactiveProperty(false); NowNavigating = PageManager.ObserveProperty(x => x.PageNavigating) .ToReactiveProperty(); PageManager.StartWork += PageManager_StartWork; PageManager.ProgressWork += PageManager_ProgressWork; PageManager.CompleteWork += PageManager_CompleteWork; PageManager.CancelWork += PageManager_CancelWork; HohoemaApp.ObserveProperty(x => x.IsLoggedIn) .Subscribe(x => IsLoggedIn = x); HohoemaApp.ObserveProperty(x => x.LoginUserName) .Subscribe(x => { UserName = x; }); HohoemaApp.ObserveProperty(x => x.UserIconUrl) .Subscribe(x => UserIconUrl = x); // 検索 SearchKeyword = new ReactiveProperty <string>(""); SearchCommand = new ReactiveCommand(); SearchCommand .Subscribe(async _ => { await Task.Delay(50); var keyword = SearchKeyword.Value; if (string.IsNullOrWhiteSpace(keyword)) { return; } SearchTarget?searchType = CurrentMenuType.Value is LiveMenuSubPageContent ? SearchTarget.Niconama : SearchTarget.Keyword; var searched = Database.SearchHistoryDb.LastSearchedTarget(keyword); if (searched != null) { searchType = searched; } PageManager.Search(SearchPagePayloadContentHelper.CreateDefault(searchType.Value, keyword)); ResetSearchHistoryItems(); }); SearchSuggestionWords = new ObservableCollection <string>(); // InAppNotification IsShowInAppNotification = new ReactiveProperty <bool>(true); IsShowPlayerInFill = HohoemaApp.Playlist .ObserveProperty(x => x.IsPlayerFloatingModeEnable) .Select(x => !x) .ToReadOnlyReactiveProperty(); IsShowPlayerInFill_DelayedRead = IsShowPlayerInFill .Delay(TimeSpan.FromMilliseconds(300)) .ToReadOnlyReactiveProperty(); IsShowPlayer = HohoemaApp.Playlist.ObserveProperty(x => x.IsDisplayMainViewPlayer) .ToReactiveProperty(mode: ReactivePropertyMode.DistinctUntilChanged); IsContentDisplayFloating = Observable.CombineLatest( IsShowPlayerInFill.Select(x => !x), IsShowPlayer ) .Select(x => x.All(y => y)) .ToReactiveProperty(); HohoemaApp.Playlist.OpenPlaylistItem += HohoemaPlaylist_OpenPlaylistItem; IsShowPlayer .Where(x => !x) .Subscribe(x => { ClosePlayer(); }); if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4)) { Observable.Merge( IsShowPlayer.Where(x => !x), IsContentDisplayFloating.Where(x => x) ) .Subscribe(async x => { var view = ApplicationView.GetForCurrentView(); if (view.IsViewModeSupported(ApplicationViewMode.CompactOverlay)) { var result = await view.TryEnterViewModeAsync(ApplicationViewMode.Default); } }); } // 検索履歴アイテムを初期化 ResetSearchHistoryItems(); }