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(); } }); }
protected override void OnLeave() { _CacheSettings.Save().ConfigureAwait(false); }