Exemple #1
0
        public MenuNavigatePageBaseViewModel(
            HohoemaApp hohoemaApp,
            PageManager pageManager
            )
        {
            PageManager = pageManager;
            HohoemaApp  = hohoemaApp;

            // TV Mode
            if (Util.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);

            MenuItems = new List <PageTypeSelectableItem>()
            {
                new PageTypeSelectableItem(HohoemaPageType.Search, OnMenuItemSelected, "検索", Symbol.Find),
                new PageTypeSelectableItem(HohoemaPageType.RankingCategoryList, OnMenuItemSelected, "ランキング", Symbol.Flag),
                new PageTypeSelectableItem(HohoemaPageType.UserMylist, OnMenuItemSelected, "マイリスト", Symbol.Bookmarks),
                new PageTypeSelectableItem(HohoemaPageType.FollowManage, OnMenuItemSelected, "フォロー", Symbol.OutlineStar),
                new PageTypeSelectableItem(HohoemaPageType.FeedGroupManage, OnMenuItemSelected, "フィード", Symbol.List),
            };

            SubMenuItems = new List <PageTypeSelectableItem>()
            {
                new PageTypeSelectableItem(HohoemaPageType.History, OnMenuItemSelected, "視聴履歴", Symbol.Clock),
                new PageTypeSelectableItem(HohoemaPageType.CacheManagement, OnMenuItemSelected, "キャッシュ管理", Symbol.Download),
                new PageTypeSelectableItem(HohoemaPageType.Settings, OnMenuItemSelected, "設定", Symbol.Setting),
                new PageTypeSelectableItem(HohoemaPageType.UserInfo, OnAccountMenuItemSelected, "アカウント", Symbol.Account),
            };

            AllMenuItems = MenuItems.Concat(SubMenuItems).ToList();

            MainSelectedItem = new ReactiveProperty <PageTypeSelectableItem>(MenuItems[0], ReactivePropertyMode.DistinctUntilChanged);
            SubSelectedItem  = new ReactiveProperty <PageTypeSelectableItem>(null, ReactivePropertyMode.DistinctUntilChanged);

            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.Source == pageType)
                    {
                        MainSelectedItem.Value = item;
                        SubSelectedItem.Value  = null;
                        isMenuItemOpened       = true;
                        break;
                    }
                }

                foreach (var item in SubMenuItems)
                {
                    if (item.Source == pageType)
                    {
                        SubSelectedItem.Value  = item;
                        MainSelectedItem.Value = null;
                        isMenuItemOpened       = true;
                        break;
                    }
                }

                if (!isMenuItemOpened)
                {
                    MainSelectedItem.Value = null;
                    SubSelectedItem.Value  = null;
                }
            });

            IsSubMenuItemPage = PageManager.ObserveProperty(x => x.CurrentPageType)
                                .Select(x => SubMenuItems.Any(y => y.Source == x))
                                .ToReactiveProperty();



            PageManager.ObserveProperty(x => x.PageTitle)
            .Subscribe(x =>
            {
                TitleText = x;
            });


            IsVisibleMenu = PageManager.ObserveProperty(x => x.CurrentPageType)
                            .Select(x =>
            {
                return(PageManager.DontNeedMenuPageTypes.All(dontNeedMenuPageType => x != dontNeedMenuPageType));
            })
                            .ToReactiveProperty();

            NowNavigating = PageManager.ObserveProperty(x => x.PageNavigating)
                            .ToReactiveProperty();


            PageManager.StartWork    += PageManager_StartWork;
            PageManager.ProgressWork += PageManager_ProgressWork;
            PageManager.CompleteWork += PageManager_CompleteWork;
            PageManager.CancelWork   += PageManager_CancelWork;



            var updater = HohoemaApp.BackgroundUpdater;

            var bgUpdateStartedObserver = Observable.FromEventPattern <BackgroundUpdateScheduleHandler>(
                handler => updater.BackgroundUpdateStartedEvent += handler,
                handler => updater.BackgroundUpdateStartedEvent -= handler
                );

            var bgUpdateCompletedObserver = Observable.FromEventPattern <BackgroundUpdateScheduleHandler>(
                handler => updater.BackgroundUpdateCompletedEvent += handler,
                handler => updater.BackgroundUpdateCompletedEvent -= handler
                );


            var bgUpdateCanceledObserver = Observable.FromEventPattern <BackgroundUpdateScheduleHandler>(
                handler => updater.BackgroundUpdateCanceledEvent += handler,
                handler => updater.BackgroundUpdateCanceledEvent -= handler
                );

            BGUpdateText    = new ReactiveProperty <string>();
            HasBGUpdateText = BGUpdateText.Select(x => !string.IsNullOrEmpty(x))
                              .ToReactiveProperty();
            bgUpdateStartedObserver.Subscribe(x =>
            {
                if (!string.IsNullOrEmpty(x.EventArgs.Label))
                {
                    BGUpdateText.Value = $"{x.EventArgs.Label} を処理中...";
                }
                else
                {
                    BGUpdateText.Value = $"{x.EventArgs.Id} を処理中...";
                }
            });


            Observable.Merge(
                bgUpdateCompletedObserver,
                bgUpdateCanceledObserver
                )
            .Throttle(TimeSpan.FromSeconds(2))
            .Subscribe(x =>
            {
                BGUpdateText.Value = null;
            });

            HohoemaApp.ObserveProperty(x => x.IsLoggedIn)
            .Subscribe(x => IsLoggedIn = x);

            HohoemaApp.ObserveProperty(x => x.LoginUserName)
            .Subscribe(x =>
            {
                UserName = x;
                UserMail = AccountManager.GetPrimaryAccountId();
            });

            HohoemaApp.ObserveProperty(x => x.UserIconUrl)
            .Subscribe(x => UserIconUrl = x);



            // 検索
            SearchKeyword = new ReactiveProperty <string>("");
            SearchTarget  = new ReactiveProperty <Models.SearchTarget>(Models.SearchTarget.Keyword);

            SearchCommand = SearchKeyword
                            .Select(x => !string.IsNullOrWhiteSpace(x))
                            .ToReactiveCommand();
            SearchCommand.Subscribe(_ =>
            {
                ISearchPagePayloadContent searchContent =
                    SearchPagePayloadContentHelper.CreateDefault(SearchTarget.Value, SearchKeyword.Value);
                PageManager.Search(searchContent);

                IsMobileNowSearching = false;
            });
        }