public VideoCacheIntroductionPageViewModel(HohoemaDialogService dialogService, HohoemaApp hohoemaApp)
        {
            _HohoemaDialogService = dialogService;
            _HohoemaApp           = hohoemaApp;

            var hasCacheFolder = Windows.Storage.AccessCache.StorageApplicationPermissions.
                                 FutureAccessList.Entries.Count > 0;

            IsCompleteCacheSettings = new ReactiveProperty <bool>(_HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache && hasCacheFolder)
                                      .AddTo(_Disposables);

            CanChangeCacheSettings = new ReactiveProperty <bool>(!IsCompleteCacheSettings.Value)
                                     .AddTo(_Disposables);
            RequireEnablingCacheCommand = CanChangeCacheSettings.ToAsyncReactiveCommand()
                                          .AddTo(_Disposables);

            RequireEnablingCacheCommand.Subscribe(async() =>
            {
                bool isAcceptedCache = _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache;
                if (!isAcceptedCache)
                {
                    isAcceptedCache = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync();
                    if (isAcceptedCache)
                    {
                        _HohoemaApp.UserSettings.CacheSettings.IsEnableCache       = true;
                        _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache = true;

                        (App.Current).Resources["IsCacheEnabled"] = true;
                    }
                }

                if (isAcceptedCache)
                {
                    if (await _HohoemaApp.ChangeUserDataFolder())
                    {
                        IsCompleteCacheSettings.Value = true;
                    }
                }
            })
            .AddTo(_Disposables);
        }
        protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            await RefreshCacheSaveFolderStatus();

            if (IsRequireUpdateCacheSaveFolder.Value)
            {
                (App.Current as App).PublishInAppNotification(
                    InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの保存先フォルダを選択してください。\n保存先が選択されると利用準備が完了します。",
                                                                        showDuration: TimeSpan.FromSeconds(30)
                                                                        ));

                if (await HohoemaApp.ChangeUserDataFolder())
                {
                    await RefreshCacheSaveFolderStatus();
                    await ResetList();

                    (App.Current as App).PublishInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの利用準備が出来ました")
                        );
                }
            }

            await base.NavigatedToAsync(cancelToken, e, viewModelState);
        }
Esempio n. 3
0
        public CacheSettingsPageContentViewModel(
            HohoemaApp hohoemaApp
            , EditAutoCacheConditionDialogService editDialogService
            , AcceptCacheUsaseDialogService cacheConfirmDialogService
            )
            : base("キャッシュ", HohoemaSettingsKind.Cache)
        {
            _HohoemaApp                    = hohoemaApp;
            _CacheSettings                 = _HohoemaApp.UserSettings.CacheSettings;
            _EditDialogService             = editDialogService;
            _AcceptCacheUsaseDialogService = cacheConfirmDialogService;

            IsAutoCacheOnPlayEnable          = _CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAutoCacheOnPlayEnable);
            IsUserAcceptRegalNotice          = _CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsUserAcceptedCache);
            IsCacheFolderSelectedButNotExist = new ReactiveProperty <bool>(false);

            ReadCacheAcceptTextCommand = new DelegateCommand(async() =>
            {
                await cacheConfirmDialogService.ShowAcceptCacheTextDialog();
            });


            AddAutoCacheConditionCommand = new DelegateCommand(() =>
            {
                _CacheSettings.CacheOnPlayTagConditions.Add(new TagCondition()
                {
                    Label = "NewCondition"
                });
            });

            AutoCacheConditions = _CacheSettings.CacheOnPlayTagConditions.ToReadOnlyReactiveCollection(
                x => new AutoCacheConditionViewModel(_CacheSettings, x)
                );

            EditAutoCacheConditionCommnad = new DelegateCommand <AutoCacheConditionViewModel>(async(conditionVM) =>
            {
                await EditAutoCacheCondition(conditionVM);
            });


            Observable.Merge(
                IsUserAcceptRegalNotice.ToUnit(),
                IsAutoCacheOnPlayEnable.ToUnit()
                )
            .Subscribe(async _ =>
            {
                await _CacheSettings.Save().ConfigureAwait(false);
            });

            CacheFolderStateDescription = new ReactiveProperty <string>("");
            CacheSaveFolderPath         = new ReactiveProperty <string>("");

            OpenCurrentCacheFolderCommand = new DelegateCommand(async() =>
            {
                await RefreshCacheSaveFolderStatus();

                var folder = await _HohoemaApp.GetVideoCacheFolder();
                if (folder != null)
                {
                    await Launcher.LaunchFolderAsync(folder);
                }
            });

            IsEnableCache = _HohoemaApp.UserSettings
                            .CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsEnableCache);

            IsEnableCache
            .Where(x => x)
            .Where(_ => false == _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache)
            .Subscribe(async x =>
            {
                // ユーザーがキャッシュ機能利用に対する承諾を行っていない場合に
                // 確認のダイアログを表示する
                var result = await _AcceptCacheUsaseDialogService.ShowConfirmAcceptCacheDialog();

                if (result)
                {
                    _HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache = true;

                    await RefreshCacheSaveFolderStatus();
                }
                else
                {
                    IsEnableCache.Value = false;
                }
            });

            IsEnableCache.Subscribe(async _ =>
            {
                await RefreshCacheSaveFolderStatus();
            });

            ChangeCacheFolderCommand = new DelegateCommand(async() =>
            {
                if (await _HohoemaApp.ChangeUserDataFolder())
                {
                    await RefreshCacheSaveFolderStatus();
                }
            });
        }
        public CacheManagementPageViewModel(
            HohoemaApp app,
            PageManager pageManager,
            HohoemaDialogService dialogService
            )
            : base(app, pageManager)
        {
            _MediaManager         = app.CacheManager;
            _HohoemaDialogService = dialogService;

            IsRequireUpdateCacheSaveFolder = new ReactiveProperty <bool>(false);

            IsCacheUserAccepted = HohoemaApp.UserSettings.CacheSettings.ObserveProperty(x => x.IsUserAcceptedCache)
                                  .ToReadOnlyReactiveProperty();

            RequireEnablingCacheCommand = new DelegateCommand(async() =>
            {
                var result = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync();
                if (result)
                {
                    HohoemaApp.UserSettings.CacheSettings.IsEnableCache       = true;
                    HohoemaApp.UserSettings.CacheSettings.IsUserAcceptedCache = true;
                    (App.Current).Resources["IsCacheEnabled"] = true;

                    await RefreshCacheSaveFolderStatus();

                    (App.Current as App).PublishInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの保存先フォルダを選択してください。\n保存先が選択されると利用準備が完了します。",
                                                                            showDuration: TimeSpan.FromSeconds(30)
                                                                            ));

                    if (await HohoemaApp.ChangeUserDataFolder())
                    {
                        await RefreshCacheSaveFolderStatus();
                        await ResetList();

                        (App.Current as App).PublishInAppNotification(
                            InAppNotificationPayload.CreateReadOnlyNotification("キャッシュの利用準備が出来ました")
                            );
                    }
                }
            });

            ReadCacheAcceptTextCommand = new DelegateCommand(async() =>
            {
                var result = await _HohoemaDialogService.ShowAcceptCacheUsaseDialogAsync(showWithoutConfirmButton: true);
            });



            CacheFolderStateDescription = new ReactiveProperty <string>("");
            CacheSaveFolderPath         = new ReactiveProperty <string>("");

            OpenCurrentCacheFolderCommand = new DelegateCommand(async() =>
            {
                await RefreshCacheSaveFolderStatus();

                var folder = await HohoemaApp.GetVideoCacheFolder();
                if (folder != null)
                {
                    await Launcher.LaunchFolderAsync(folder);
                }
            });


            ChangeCacheFolderCommand = new DelegateCommand(async() =>
            {
                var prevPath = CacheSaveFolderPath.Value;

                if (await HohoemaApp.ChangeUserDataFolder())
                {
                    (App.Current as App).PublishInAppNotification(
                        InAppNotificationPayload.CreateReadOnlyNotification($"キャッシュの保存先を {CacheSaveFolderPath.Value} に変更しました")
                        );

                    await RefreshCacheSaveFolderStatus();
                    await ResetList();
                }
            });
        }