Exemple #1
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 SettingsPageViewModel(
            PageManager pageManager,
            NotificationService toastService,
            Services.DialogService dialogService,
            NGSettings ngSettings,
            RankingSettings rankingSettings,
            ActivityFeedSettings activityFeedSettings,
            AppearanceSettings appearanceSettings,
            CacheSettings cacheSettings
            )
            : base(pageManager)
        {
            ToastNotificationService = toastService;
            NgSettings            = ngSettings;
            RankingSettings       = rankingSettings;
            _HohoemaDialogService = dialogService;
            NgSettings            = ngSettings;
            RankingSettings       = rankingSettings;
            ActivityFeedSettings  = activityFeedSettings;
            AppearanceSettings    = appearanceSettings;
            CacheSettings         = cacheSettings;


            IsLiveAlertEnabled = ActivityFeedSettings.ToReactivePropertyAsSynchronized(x => x.IsLiveAlertEnabled)
                                 .AddTo(_CompositeDisposable);

            // NG Video Owner User Id
            NGVideoOwnerUserIdEnable = NgSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoOwnerUserIdEnable);
            NGVideoOwnerUserIds      = NgSettings.NGVideoOwnerUserIds
                                       .ToReadOnlyReactiveCollection();

            OpenUserPageCommand = new DelegateCommand <UserIdInfo>(userIdInfo =>
            {
                pageManager.OpenPage(HohoemaPageType.UserInfo, userIdInfo.UserId);
            });

            // NG Keyword on Video Title
            NGVideoTitleKeywordEnable = NgSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleKeywordEnable);
            NGVideoTitleKeywords      = new ReactiveProperty <string>();
            NGVideoTitleKeywordError  = NGVideoTitleKeywords
                                        .Select(x =>
            {
                if (x == null)
                {
                    return(null);
                }

                var keywords     = x.Split('\r');
                var invalidRegex = keywords.FirstOrDefault(keyword =>
                {
                    Regex regex = null;
                    try
                    {
                        regex = new Regex(keyword);
                    }
                    catch { }
                    return(regex == null);
                });

                if (invalidRegex == null)
                {
                    return(null);
                }
                else
                {
                    return($"Error in \"{invalidRegex}\"");
                }
            })
                                        .ToReadOnlyReactiveProperty();

            // アピアランス

            var currentTheme = App.GetTheme();

            SelectedApplicationTheme = new ReactiveProperty <string>(currentTheme.ToString(), mode: ReactivePropertyMode.DistinctUntilChanged);

            SelectedApplicationTheme.Subscribe(x =>
            {
                var type = (ApplicationTheme)Enum.Parse(typeof(ApplicationTheme), x);
                App.SetTheme(type);

                // 一度だけトースト通知
                if (!ThemeChanged)
                {
                    toastService.ShowToast("Hohoemaを再起動するとテーマが適用されます。", "");
                }

                ThemeChanged = true;
                RaisePropertyChanged(nameof(ThemeChanged));
            });

            IsTVModeEnable = AppearanceSettings
                             .ToReactivePropertyAsSynchronized(x => x.IsForceTVModeEnable);
            IsXbox = Services.Helpers.DeviceTypeHelper.IsXbox;

            IsForceMobileModeEnable = AppearanceSettings
                                      .ToReactivePropertyAsSynchronized(x => x.IsForceMobileModeEnable);



            IsDefaultFullScreen = new ReactiveProperty <bool>(ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen);
            IsDefaultFullScreen.Subscribe(x =>
            {
                if (x)
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
                }
                else
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
                }
            });

            StartupPageType = AppearanceSettings
                              .ToReactivePropertyAsSynchronized(x => x.StartupPageType);


            // キャッシュ
            DefaultCacheQuality                 = CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQuality);
            IsAllowDownloadOnMeteredNetwork     = CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAllowDownloadOnMeteredNetwork);
            DefaultCacheQualityOnMeteredNetwork = CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQualityOnMeteredNetwork);

            // シェア
            IsLoginTwitter           = new ReactiveProperty <bool>(/*TwitterHelper.IsLoggedIn*/ false);
            TwitterAccountScreenName = new ReactiveProperty <string>(/*TwitterHelper.TwitterUser?.ScreenName ?? ""*/);


            // アバウト
            var version = Windows.ApplicationModel.Package.Current.Id.Version;

#if DEBUG
            VersionText = $"{version.Major}.{version.Minor}.{version.Build} DEBUG";
#else
            VersionText = $"{version.Major}.{version.Minor}.{version.Build}";
#endif


            var dispatcher = Window.Current.CoreWindow.Dispatcher;
            LisenceSummary.Load()
            .ContinueWith(async prevResult =>
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var lisenceSummary = prevResult.Result;

                    LisenceItems = lisenceSummary.Items
                                   .OrderBy(x => x.Name)
                                   .Select(x => new LisenceItemViewModel(x))
                                   .ToList();
                    RaisePropertyChanged(nameof(LisenceItems));
                });
            });


            IsDebugModeEnabled = new ReactiveProperty <bool>((App.Current as App).IsDebugModeEnabled, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsDebugModeEnabled.Subscribe(isEnabled =>
            {
                (App.Current as App).IsDebugModeEnabled = isEnabled;
            })
            .AddTo(_CompositeDisposable);
        }
        public SettingsPageViewModel(
            PageManager pageManager,
            NotificationService toastService,
            Services.DialogService dialogService,
            PlayerSettings playerSettings,
            NGSettings ngSettings,
            RankingSettings rankingSettings,
            ActivityFeedSettings activityFeedSettings,
            AppearanceSettings appearanceSettings,
            CacheSettings cacheSettings,
            ApplicationLayoutManager applicationLayoutManager
            )
        {
            ToastNotificationService = toastService;
            NgSettings               = ngSettings;
            RankingSettings          = rankingSettings;
            _HohoemaDialogService    = dialogService;
            PlayerSettings           = playerSettings;
            NgSettings               = ngSettings;
            RankingSettings          = rankingSettings;
            ActivityFeedSettings     = activityFeedSettings;
            AppearanceSettings       = appearanceSettings;
            CacheSettings            = cacheSettings;
            ApplicationLayoutManager = applicationLayoutManager;

            // NG Video Owner User Id
            NGVideoOwnerUserIdEnable = NgSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoOwnerUserIdEnable);
            NGVideoOwnerUserIds      = NgSettings.NGVideoOwnerUserIds
                                       .ToReadOnlyReactiveCollection();

            OpenUserPageCommand = new DelegateCommand <UserIdInfo>(userIdInfo =>
            {
                pageManager.OpenPageWithId(HohoemaPageType.UserInfo, userIdInfo.UserId);
            });

            // NG Keyword on Video Title
            NGVideoTitleKeywordEnable = NgSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleKeywordEnable);
            NGVideoTitleKeywords      = new ReactiveProperty <string>();
            NGVideoTitleKeywordError  = NGVideoTitleKeywords
                                        .Select(x =>
            {
                if (x == null)
                {
                    return(null);
                }

                var keywords     = x.Split('\r');
                var invalidRegex = keywords.FirstOrDefault(keyword =>
                {
                    Regex regex = null;
                    try
                    {
                        regex = new Regex(keyword);
                    }
                    catch { }
                    return(regex == null);
                });

                if (invalidRegex == null)
                {
                    return(null);
                }
                else
                {
                    return($"Error in \"{invalidRegex}\"");
                }
            })
                                        .ToReadOnlyReactiveProperty();

            // アピアランス

            var currentTheme = App.GetTheme();

            SelectedTheme = new ReactiveProperty <ElementTheme>(AppearanceSettings.Theme, mode: ReactivePropertyMode.DistinctUntilChanged);

            SelectedTheme.Subscribe(theme =>
            {
                AppearanceSettings.Theme = theme;

                ApplicationTheme appTheme;
                if (theme == ElementTheme.Default)
                {
                    appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme();
                }
                else if (theme == ElementTheme.Dark)
                {
                    appTheme = ApplicationTheme.Dark;
                }
                else
                {
                    appTheme = ApplicationTheme.Light;
                }

                App.SetTheme(appTheme);

                var appView = ApplicationView.GetForCurrentView();
                if (appTheme == ApplicationTheme.Light)
                {
                    appView.TitleBar.ButtonForegroundColor         = Colors.Black;
                    appView.TitleBar.ButtonHoverBackgroundColor    = Colors.DarkGray;
                    appView.TitleBar.ButtonHoverForegroundColor    = Colors.Black;
                    appView.TitleBar.ButtonInactiveForegroundColor = Colors.Gray;
                }
                else
                {
                    appView.TitleBar.ButtonForegroundColor         = Colors.White;
                    appView.TitleBar.ButtonHoverBackgroundColor    = Colors.DimGray;
                    appView.TitleBar.ButtonHoverForegroundColor    = Colors.White;
                    appView.TitleBar.ButtonInactiveForegroundColor = Colors.DarkGray;
                }
            });



            IsDefaultFullScreen = new ReactiveProperty <bool>(ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen);
            IsDefaultFullScreen.Subscribe(x =>
            {
                if (x)
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
                }
                else
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
                }
            });

            StartupPageType = AppearanceSettings
                              .ToReactivePropertyAsSynchronized(x => x.StartupPageType);

            AppearanceSettings.ObserveProperty(x => x.Locale, isPushCurrentValueAtFirst: false).Subscribe(locale =>
            {
                I18NPortable.I18N.Current.Locale = locale;
            });

            // キャッシュ
            DefaultCacheQuality                 = CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQuality);
            IsAllowDownloadOnMeteredNetwork     = CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAllowDownloadOnMeteredNetwork);
            DefaultCacheQualityOnMeteredNetwork = CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQualityOnMeteredNetwork);

            // シェア
            IsLoginTwitter           = new ReactiveProperty <bool>(/*TwitterHelper.IsLoggedIn*/ false);
            TwitterAccountScreenName = new ReactiveProperty <string>(/*TwitterHelper.TwitterUser?.ScreenName ?? ""*/);


            // アバウト
            var version = Windows.ApplicationModel.Package.Current.Id.Version;

#if DEBUG
            VersionText = $"{version.Major}.{version.Minor}.{version.Build} DEBUG";
#else
            VersionText = $"{version.Major}.{version.Minor}.{version.Build}";
#endif


            var dispatcher = Window.Current.CoreWindow.Dispatcher;
            LisenceSummary.Load()
            .ContinueWith(async prevResult =>
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var lisenceSummary = prevResult.Result;

                    LisenceItems = lisenceSummary.Items
                                   .OrderBy(x => x.Name)
                                   .Select(x => new LisenceItemViewModel(x))
                                   .ToList();
                    RaisePropertyChanged(nameof(LisenceItems));
                });
            });


            IsDebugModeEnabled = new ReactiveProperty <bool>((App.Current as App).IsDebugModeEnabled, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsDebugModeEnabled.Subscribe(isEnabled =>
            {
                (App.Current as App).IsDebugModeEnabled = isEnabled;
            })
            .AddTo(_CompositeDisposable);
        }