예제 #1
0
        public LiveMenuSubPageContent(Models.Niconico.Live.NicoLiveSubscriber nicoLiveSubscriber)
        {
            _LiveSubscriber = nicoLiveSubscriber;

            UpdateOnAirStreamsCommand = new AsyncReactiveCommand();

            UpdateOnAirStreamsCommand.Subscribe(async _ =>
            {
                await _LiveSubscriber.UpdateOnAirStreams();
            });

            OnAirStreams = _LiveSubscriber.OnAirStreams.ToReadOnlyReactiveCollection(x =>
                                                                                     new OnAirStream()
            {
                BroadcasterId = x.Video.UserId,
                Id            = x.Video.Id,
                Label         = x.Video.Title,
                Thumbnail     = x.Community?.ThumbnailSmall,
                CommunityName = x.Community.Name,
                StartAt       = x.Video.StartTime.Value
            }
                                                                                     );

            ReservedStreams = _LiveSubscriber.ReservedStreams.ToReadOnlyReactiveCollection(x =>
                                                                                           new OnAirStream()
            {
                BroadcasterId = x.Video.UserId,
                Id            = x.Video.Id,
                Label         = x.Video.Title,
                Thumbnail     = x.Community?.ThumbnailSmall,
                CommunityName = x.Community.Name,
                StartAt       = x.Video.StartTime.Value
            }
                                                                                           );

            MenuItems = new List <HohoemaListingPageItemBase>();
            MenuItems.Add(new MenuItemViewModel("ニコレポ", HohoemaPageType.NicoRepo));
            MenuItems.Add(new MenuItemViewModel("フォロー", HohoemaPageType.FollowManage));
            //            MenuItems.Add(new MenuItemViewModel("タイムシフト", HohoemaPageType.Recommend));
            //            MenuItems.Add(new MenuItemViewModel("予約", HohoemaPageType.NicoRepo));
        }
예제 #2
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();
        }