Esempio n. 1
0
        public ReactivePropertyViewModel(IShelfBoxRepository shelfBoxRepository)
        {
            _shelfBoxRepository = shelfBoxRepository;
            BoxDatas            = new ObservableCollection <BoxDataEntity>(_shelfBoxRepository.GetBoxAll());
            BoxDatas2.Value     = new ObservableCollection <BoxDataEntity>(_shelfBoxRepository.GetBoxAll());
            Name.Value          = "akiraFirst";

            //Index2.Subscribe(x => Console.WriteLine($"Subscribe: {x}")).AddTo(this.Disposable); // 1個 Subscribe: 初期値
            Index2.Subscribe(x => {
                Console.WriteLine($"Subscribe: {x}");
                Index = x;
            }).AddTo(this.Disposable);                                     // いろいろ行う Subscribe: 初期値

            //NameTest = new ReactiveProperty<string>()
            //.SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "空文字はダメ" : null);

            NameTest = new ReactiveProperty <string>(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreInitialValidationError)
                       .SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "空文字はダメ" : null).AddTo(this.Disposable);;

            // デフォルト値が true の設定
            IsChecked = new ReactivePropertySlim <bool>(true).AddTo(this.Disposable);
            // ReactiveProperty は IObservable なので ReactiveCommand にできる
            SampleCommand = IsChecked.ToReactiveCommand().AddTo(this.Disposable);
            // ReactiveCommand は IObservable なので Select で加工して ReactiveProperty に出来る
            Message = SampleCommand.Select(_ => DateTime.Now.ToString())
                      .ToReadOnlyReactivePropertySlim().AddTo(this.Disposable);

            ButtonCommand.Subscribe(_ => ButtonAction());

            this.Input  = new ReactiveProperty <string>(""); // デフォルト値を指定してReactivePropertyを作成
            this.Output = this.Input
                          .Delay(TimeSpan.FromSeconds(1))    // 1秒間待機して
                          .Select(x => x.ToUpper())          // 大文字に変換して
                          .ToReactiveProperty();             // ReactiveProperty化する
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        internal PlaylistContentViewViewModel(
            IYouTubeService youTubeService,
            IWebClientService webClientService,
            IPlaylistListViewViewModel playlistListViewViewModel)
        {
            m_YouTubeService            = youTubeService;
            m_WebClientService          = webClientService;
            m_PlaylistListViewViewModel = playlistListViewViewModel;
            playlistListViewViewModel.SelectionChanged += PlaylistListViewViewModel_SelectionChanged;

            Title            = new ReactivePropertySlim <string>().AddTo(m_Disposables);
            Description      = new ReactivePropertySlim <string>().AddTo(m_Disposables);
            PlaylistItemList = new ReactiveCollection <PlaylistItemViewModel>().AddTo(m_Disposables);

            // コマンドの生成
            Playlist = new ReactivePropertySlim <Playlist?>().AddTo(m_Disposables);
            CanAddVideosToPlaylistItemAsync   = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanRemovePlaylistItemAsync        = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanMovePlaylistItemAsync          = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanClonePlaylistItemsFromPlaylist = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanAddOrClonePlaylistItems        = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            Playlist.Subscribe(v => {
                CanAddVideosToPlaylistItemAsync.Value   = (v != null);
                CanRemovePlaylistItemAsync.Value        = (v != null);
                CanMovePlaylistItemAsync.Value          = (v != null);
                CanClonePlaylistItemsFromPlaylist.Value = (v != null);
                CanAddOrClonePlaylistItems.Value        = (v != null);
            });
            AddVideosToPlaylistItemAsyncCommand = CanAddVideosToPlaylistItemAsync
                                                  .ToReactiveCommand()
                                                  .WithSubscribe(async() => await AddVideosToPlaylistItemAsync())
                                                  .AddTo(m_Disposables);
            RemovePlaylistItemAsyncCommand = CanRemovePlaylistItemAsync
                                             .ToReactiveCommand()
                                             .WithSubscribe(async() => await RemovePlaylistItemAsync())
                                             .AddTo(m_Disposables);
            MovePlaylistItemAsyncCommand = CanMovePlaylistItemAsync
                                           .ToReactiveCommand <IPlaylistListViewItemViewModel>()
                                           .WithSubscribe(async param => await MovePlaylistItemAsync(param))
                                           .AddTo(m_Disposables);
            ClonePlaylistItemsFromPlaylistCommand = CanClonePlaylistItemsFromPlaylist
                                                    .ToReactiveCommand()
                                                    .WithSubscribe(async() => await ClonePlaylistItemsFromPlaylist())
                                                    .AddTo(m_Disposables);
            AddOrClonePlaylistItemsCommand = CanAddOrClonePlaylistItems
                                             .ToReactiveCommand()
                                             .WithSubscribe(async() => await AddOrClonePlaylistItems())
                                             .AddTo(m_Disposables);

            // ダイアログを表示するインタラクションを保持
            ShowAddPlaylistItemDialog         = new Interaction <Unit, AddPlaylistItemDialogViewModel>();
            ShowClonePlaylistItemsDialog      = new Interaction <Unit, ClonePlaylistItemsDialogViewModel>();
            ShowAddOrClonePlaylistItemsDialog = new Interaction <Unit, AddOrClonePlaylistItemsDialogViewModel>();
        }
 public EventToReactiveViewModel()
 {
     MousePosition = new ReactivePropertySlim <string>()
                     .AddTo(Disposables);
     CanExecute = new ReactivePropertySlim <bool>(true)
                  .AddTo(Disposables);
     OpenFileCommand = CanExecute.ToReactiveCommand <string>()
                       .AddTo(Disposables);
     OpenedFile = OpenFileCommand.Select(x => $"You selected {x}")
                  .ToReadOnlyReactivePropertySlim()
                  .AddTo(Disposables);
 }
        public ReactiveCommandViewModel()
        {
            InvokedDateTime           = new ReactivePropertySlim <string>();
            CreateAndSubscribeCommand = new ReactiveCommand()
                                        .WithSubscribe(() => InvokedDateTime.Value = $"The command was invoked at {DateTime.Now}.")
                                        .AddTo(Disposables);

            InvokedDateTimeFromCommand = CreateAndSubscribeCommand
                                         .Select(_ => $"The command was invoked at {DateTime.Now}.")
                                         .ToReadOnlyReactivePropertySlim()
                                         .AddTo(Disposables);

            IsChecked = new ReactivePropertySlim <bool>()
                        .AddTo(Disposables);
            CreateFromIObservableBoolCommand = IsChecked.ToReactiveCommand()
                                               .AddTo(Disposables);
            InvokedDateTimeForCreateFromIObservableBoolCommand = CreateFromIObservableBoolCommand
                                                                 .Select(_ => $"The command was invoked at {DateTime.Now}.")
                                                                 .ToReadOnlyReactivePropertySlim()
                                                                 .AddTo(Disposables);

            ReactiveCommandWithParameter = new ReactiveCommand <string>()
                                           .AddTo(Disposables);
            ReactiveCommandWithParameterOutput = ReactiveCommandWithParameter
                                                 .Select(x => $"The command was invoked with {x}.")
                                                 .ToReadOnlyReactivePropertySlim()
                                                 .AddTo(Disposables);

            LongRunningCommandOutput = new ReactivePropertySlim <string>();
            LongRunningCommand       = new AsyncReactiveCommand()
                                       .WithSubscribe(async() =>
            {
                LongRunningCommandOutput.Value = "Long running command was started.";
                await Task.Delay(5000);
                LongRunningCommandOutput.Value = "Long running command was finished.";
            })
                                       .AddTo(Disposables);

            IsCheckedForAsyncReactiveCommand = new ReactivePropertySlim <bool>()
                                               .AddTo(Disposables);
            CreateFromIObservableBoolAsyncReactiveCommandOutput = new ReactivePropertySlim <string>()
                                                                  .AddTo(Disposables);
            CreateFromIObservableBoolAsyncReactiveCommand = IsCheckedForAsyncReactiveCommand
                                                            .ToAsyncReactiveCommand()
                                                            .WithSubscribe(async() =>
            {
                CreateFromIObservableBoolAsyncReactiveCommandOutput.Value = "Long running command was started.";
                await Task.Delay(5000);
                CreateFromIObservableBoolAsyncReactiveCommandOutput.Value = "Long running command was finished.";
            })
                                                            .AddTo(Disposables);

            var sharedStatus = new ReactivePropertySlim <bool>(true)
                               .AddTo(Disposables);

            IsCheckedForSharedStatus = new ReactivePropertySlim <bool>()
                                       .AddTo(Disposables);
            SharedStatusOutput = new ReactivePropertySlim <string>()
                                 .AddTo(Disposables);
            ACommand = IsCheckedForSharedStatus
                       .ToAsyncReactiveCommand(sharedStatus)
                       .WithSubscribe(async() =>
            {
                SharedStatusOutput.Value = "A command was started.";
                await Task.Delay(5000);
                SharedStatusOutput.Value = "A command was finished.";
            })
                       .AddTo(Disposables);
            BCommand = IsCheckedForSharedStatus
                       .ToAsyncReactiveCommand(sharedStatus)
                       .WithSubscribe(async() =>
            {
                SharedStatusOutput.Value = "B command was started.";
                await Task.Delay(5000);
                SharedStatusOutput.Value = "B command was finished.";
            })
                       .AddTo(Disposables);
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        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();
        }