예제 #1
0
 public NicoAccountIntroductionPageViewModel(
     NiconicoSession niconicoSession,
     Commands.GoNextIntroductionPageCommand goNextIntroduction
     )
 {
     NiconicoSession    = niconicoSession;
     GoNextIntroduction = goNextIntroduction;
     IsLoggedIn         = NiconicoSession.ObserveProperty(x => x.IsLoggedIn)
                          .ToReadOnlyReactiveProperty();
 }
        public override void OnNavigatedTo(INavigationParameters parameters)
        {
            new[]
            {
                _niconicoSession.ObserveProperty(x => x.IsLoggedIn).ToUnit(),
                _userMylistManager.Mylists.CollectionChangedAsObservable().ToUnit(),
            }
            .Merge()
            .Subscribe(async _ =>
            {
                await RefreshPlaylistItems();
            })
            .AddTo(_navigationDisposables);

            /*
             * new[]
             * {
             *  SelectedDisplayMylistKind.ToUnit()
             * }
             * .Merge()
             * .Subscribe(_ => ItemsView.RefreshFilter())
             * .AddTo(_NavigatingCompositeDisposable);
             */
        }
예제 #3
0
        public CacheManagementPageViewModel(
            IScheduler scheduler,
            NiconicoSession niconicoSession,
            ApplicationLayoutManager applicationLayoutManager,
            VideoCacheSettings cacheSettings,
            VideoCacheManager videoCacheManager,
            VideoCacheFolderManager videoCacheFolderManager,
            VideoCacheDownloadOperationManager videoCacheDownloadOperationManager,
            NicoVideoProvider nicoVideoProvider,
            PageManager pageManager,
            DialogService dialogService,
            NotificationService notificationService,
            SelectionModeToggleCommand selectionModeToggleCommand,
            VideoPlayWithQueueCommand videoPlayWithQueueCommand
            )
        {
            _scheduler                          = scheduler;
            _niconicoSession                    = niconicoSession;
            ApplicationLayoutManager            = applicationLayoutManager;
            VideoCacheSettings                  = cacheSettings;
            VideoCacheManager                   = videoCacheManager;
            _videoCacheFolderManager            = videoCacheFolderManager;
            _videoCacheDownloadOperationManager = videoCacheDownloadOperationManager;
            NicoVideoProvider                   = nicoVideoProvider;
            HohoemaDialogService                = dialogService;
            NotificationService                 = notificationService;
            SelectionModeToggleCommand          = selectionModeToggleCommand;
            VideoPlayWithQueueCommand           = videoPlayWithQueueCommand;
            Groups = new (new[]
            {
                VideoCacheStatus.Failed,
                VideoCacheStatus.Downloading,
                VideoCacheStatus.DownloadPaused,
                VideoCacheStatus.Pending,
                VideoCacheStatus.Completed,
            }
                          .Select(x => new CacheItemsGroup(x, new ObservableCollection <CacheVideoViewModel>()))
                          );

            IsLoggedInWithPremiumMember = _niconicoSession.ObserveProperty(x => x.IsPremiumAccount).ToReadOnlyReactivePropertySlim(_niconicoSession.IsPremiumAccount)
                                          .AddTo(_CompositeDisposable);

            CurrentlyCachedStorageSize = VideoCacheSettings.ObserveProperty(x => x.CachedStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.CachedStorageSize)
                                         .AddTo(_CompositeDisposable);

            MaxCacheStorageSize = VideoCacheSettings.ObserveProperty(x => x.MaxVideoCacheStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.MaxVideoCacheStorageSize)
                                  .AddTo(_CompositeDisposable);

            IsAllowDownload = new ReactivePropertySlim <bool>(_videoCacheDownloadOperationManager.IsAllowDownload, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsAllowDownload.Subscribe(isAllowDownload =>
            {
                if (isAllowDownload)
                {
                    _videoCacheDownloadOperationManager.ResumeDownload();
                }
                else
                {
                    _videoCacheDownloadOperationManager.SuspendDownload();
                }
            })
            .AddTo(_CompositeDisposable);

            AvairableStorageSizeNormalized = new[]
            {
                CurrentlyCachedStorageSize,
                MaxCacheStorageSize.Select(x => x ?? 0),
            }
            .CombineLatest()
            .Select(xy => xy[1] == 0 ? 0.0 : ((double)xy[0] / xy[1]))
            .ToReadOnlyReactivePropertySlim()
            .AddTo(_CompositeDisposable);
        }
        public MenuNavigatePageBaseViewModel(
            IUnityContainer container,
            IScheduler scheduler,
            INavigationService navigationService,
            AppearanceSettings appearanceSettings,
            PinSettings pinSettings,
            NiconicoSession niconicoSession,
            LocalMylistManager localMylistManager,
            UserMylistManager userMylistManager,
            VideoCacheManager videoCacheManager,
            PageManager pageManager,
            PlayerViewManager playerViewManager,
            Services.NiconicoLoginService niconicoLoginService,
            Commands.LogoutFromNiconicoCommand logoutFromNiconicoCommand
            )
        {
            PageManager               = pageManager;
            PlayerViewManager         = playerViewManager;
            NiconicoLoginService      = niconicoLoginService;
            LogoutFromNiconicoCommand = logoutFromNiconicoCommand;
            Container          = container;
            Scheduler          = scheduler;
            NavigationService  = navigationService;
            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 <MenuItemBase>();
            VideoMenu       = App.Current.Container.Resolve <VideoMenuSubPageContent>();
            LiveMenu        = App.Current.Container.Resolve <LiveMenuSubPageContent>();

            // 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(eventScheduler: Scheduler);

            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)))
                );


            bool isPinItemsChanging = false;

            PinSettings.Pins.CollectionChangedAsObservable()
            .Subscribe(args =>
            {
                if (isPinItemsChanging)
                {
                    return;
                }

                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)));
                    }
                    RaisePropertyChanged(nameof(PinItems));
                }
                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);
                        }
                    }
                    RaisePropertyChanged(nameof(PinItems));
                }
            });

            ResetMenuItems();

            // TODO; PinSettings側で自動保存するようにしたい
            PinItems.CollectionChangedAsObservable()
            .Subscribe(async _ =>
            {
                await Task.Delay(50);

                try
                {
                    isPinItemsChanging = true;
                    PinSettings.Pins.Clear();
                    foreach (var pin in PinItems)
                    {
                        PinSettings.Pins.Add(pin.Pin);
                    }
                }
                finally
                {
                    isPinItemsChanging = false;
                }
            });

            /*
             * 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;
            });

            CanGoBackNavigation = new ReactiveProperty <bool>();

            (NavigationService as IPlatformNavigationService).CanGoBackChanged += (_, e) =>
            {
                CanGoBackNavigation.Value = NavigationService.CanGoBack();
            };

            /*
             * 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;

            UserName = NiconicoSession.ObserveProperty(x => x.UserName)
                       .ToReadOnlyReactiveProperty(eventScheduler: Scheduler);

            UserIconUrl = NiconicoSession.ObserveProperty(x => x.UserIconUrl)
                          .ToReadOnlyReactiveProperty(eventScheduler: Scheduler);


            // 検索
            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(searchType.Value, keyword);

                ResetSearchHistoryItems();
            });

            SearchSuggestionWords = new ObservableCollection <string>();



            // InAppNotification
            IsShowInAppNotification = new ReactiveProperty <bool>(true);


            // 検索履歴アイテムを初期化
            ResetSearchHistoryItems();
        }