예제 #1
0
        public SettingsPageViewModel(
            PageManager pageManager,
            NotificationService toastService,
            Services.DialogService dialogService,
            PlayerSettings playerSettings,
            VideoRankingSettings rankingSettings,
            NicoRepoSettings nicoRepoSettings,
            AppearanceSettings appearanceSettings,
            VideoCacheSettings cacheSettings,
            VideoCacheFolderManager videoCacheFolderManager,
            ApplicationLayoutManager applicationLayoutManager,
            VideoFilteringSettings videoFilteringRepository,
            BackupManager backupManager,
            ILoggerFactory loggerFactory
            )
        {
            _notificationService      = toastService;
            RankingSettings           = rankingSettings;
            _HohoemaDialogService     = dialogService;
            PlayerSettings            = playerSettings;
            ActivityFeedSettings      = nicoRepoSettings;
            AppearanceSettings        = appearanceSettings;
            VideoCacheSettings        = cacheSettings;
            _videoCacheFolderManager  = videoCacheFolderManager;
            ApplicationLayoutManager  = applicationLayoutManager;
            _videoFilteringRepository = videoFilteringRepository;
            _backupManager            = backupManager;
            _logger = loggerFactory.CreateLogger <SettingsPageViewModel>();

            // NG Video Owner User Id
            NGVideoOwnerUserIdEnable = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoOwnerUserIdEnable)
                                       .AddTo(_CompositeDisposable);
            NGVideoOwnerUserIds = _videoFilteringRepository.GetVideoOwnerIdFilteringEntries();

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

            // NG Keyword on Video Title
            VideoTitleFilteringItems = new ObservableCollection <VideoFilteringTitleViewModel>();

            NGVideoTitleKeywordEnable = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleKeywordEnable)
                                        .AddTo(_CompositeDisposable);

            TestText = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleTestText)
                       .AddTo(_CompositeDisposable);

            /*
             * 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()
             *  .AddTo(_CompositeDisposable);
             */
            // アピアランス

            StartupPageType = AppearanceSettings.ToReactivePropertyAsSynchronized(x => x.FirstAppearPageType)
                              .AddTo(_CompositeDisposable);

            var currentTheme = App.GetTheme();

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

            SelectedTheme.Subscribe(theme =>
            {
                AppearanceSettings.ApplicationTheme = 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;
                }
            })
            .AddTo(_CompositeDisposable);



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

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

            // キャッシュ
            DefaultCacheQuality = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQuality)
                                  .AddTo(_CompositeDisposable);
            IsAllowDownloadOnMeteredNetwork = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAllowDownloadOnMeteredNetwork)
                                              .AddTo(_CompositeDisposable);
            MaxVideoCacheStorageSize = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.MaxVideoCacheStorageSize)
                                       .AddTo(_CompositeDisposable);
            OpenCurrentCacheFolderCommand = new RelayCommand(async() =>
            {
                var folder = _videoCacheFolderManager.VideoCacheFolder;
                if (folder != null)
                {
                    await Windows.System.Launcher.LaunchFolderAsync(folder);
                }
            });

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


            StringBuilder sb = new StringBuilder();

            sb.Append(SystemInformation.Instance.ApplicationName)
            .Append(" v").Append(SystemInformation.Instance.ApplicationVersion.ToFormattedString())
            .AppendLine();
            sb.Append(SystemInformation.Instance.OperatingSystem).Append(" ").Append(SystemInformation.Instance.OperatingSystemArchitecture)
            .Append("(").Append(SystemInformation.Instance.OperatingSystemVersion).Append(")")
            .Append(" ").Append(DeviceInfo.Idiom)
            ;
            VersionText = sb.ToString();

            IsDebugModeEnabled = new ReactiveProperty <bool>((App.Current as App).IsDebugModeEnabled, mode: ReactivePropertyMode.DistinctUntilChanged)
                                 .AddTo(_CompositeDisposable);
            IsDebugModeEnabled.Subscribe(isEnabled =>
            {
                (App.Current as App).IsDebugModeEnabled = isEnabled;
            })
            .AddTo(_CompositeDisposable);
        }
예제 #2
0
        public CacheManagementPageViewModel(
            IScheduler scheduler,
            NiconicoSession niconicoSession,
            ApplicationLayoutManager applicationLayoutManager,
            VideoCacheSettings cacheSettings,
            VideoCacheManager videoCacheManager,
            VideoCacheFolderManager videoCacheFolderManager,
            VideoCacheDownloadOperationManager videoCacheDownloadOperationManager,
            NicoVideoProvider nicoVideoProvider,
            PageManager pageManager,
            DialogService dialogService,
            NotificationService notificationService,
            SelectionModeToggleCommand selectionModeToggleCommand,
            VideoPlayWithQueueCommand videoPlayWithQueueCommand
            )
        {
            _scheduler                          = scheduler;
            _niconicoSession                    = niconicoSession;
            ApplicationLayoutManager            = applicationLayoutManager;
            VideoCacheSettings                  = cacheSettings;
            VideoCacheManager                   = videoCacheManager;
            _videoCacheFolderManager            = videoCacheFolderManager;
            _videoCacheDownloadOperationManager = videoCacheDownloadOperationManager;
            NicoVideoProvider                   = nicoVideoProvider;
            HohoemaDialogService                = dialogService;
            NotificationService                 = notificationService;
            SelectionModeToggleCommand          = selectionModeToggleCommand;
            VideoPlayWithQueueCommand           = videoPlayWithQueueCommand;
            Groups = new (new[]
            {
                VideoCacheStatus.Failed,
                VideoCacheStatus.Downloading,
                VideoCacheStatus.DownloadPaused,
                VideoCacheStatus.Pending,
                VideoCacheStatus.Completed,
            }
                          .Select(x => new CacheItemsGroup(x, new ObservableCollection <CacheVideoViewModel>()))
                          );

            IsLoggedInWithPremiumMember = _niconicoSession.ObserveProperty(x => x.IsPremiumAccount).ToReadOnlyReactivePropertySlim(_niconicoSession.IsPremiumAccount)
                                          .AddTo(_CompositeDisposable);

            CurrentlyCachedStorageSize = VideoCacheSettings.ObserveProperty(x => x.CachedStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.CachedStorageSize)
                                         .AddTo(_CompositeDisposable);

            MaxCacheStorageSize = VideoCacheSettings.ObserveProperty(x => x.MaxVideoCacheStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.MaxVideoCacheStorageSize)
                                  .AddTo(_CompositeDisposable);

            IsAllowDownload = new ReactivePropertySlim <bool>(_videoCacheDownloadOperationManager.IsAllowDownload, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsAllowDownload.Subscribe(isAllowDownload =>
            {
                if (isAllowDownload)
                {
                    _videoCacheDownloadOperationManager.ResumeDownload();
                }
                else
                {
                    _videoCacheDownloadOperationManager.SuspendDownload();
                }
            })
            .AddTo(_CompositeDisposable);

            AvairableStorageSizeNormalized = new[]
            {
                CurrentlyCachedStorageSize,
                MaxCacheStorageSize.Select(x => x ?? 0),
            }
            .CombineLatest()
            .Select(xy => xy[1] == 0 ? 0.0 : ((double)xy[0] / xy[1]))
            .ToReadOnlyReactivePropertySlim()
            .AddTo(_CompositeDisposable);
        }