Пример #1
0
 public CommentVideoInfoContentViewModel(HohoemaUserSettings settings, ObservableCollection <Comment> comments)
 {
     UserSettings = settings;
     Comments     = comments;
     IsCommentListScrollWithVideo = new ReactiveProperty <bool>(false)
                                    .AddTo(_CompositeDisposable);
 }
        public LiveCommentSidePaneContentViewModel(HohoemaUserSettings settings, Microsoft.Toolkit.Uwp.UI.AdvancedCollectionView comments)
        {
            UserSettings = settings;
            Comments     = comments;
            IsCommentListScrollWithVideo = new ReactiveProperty <bool>(CurrentWindowContextScheduler, false)
                                           .AddTo(_CompositeDisposable);

            NGUsers = new ReadOnlyObservableCollection <NGUserIdInfo>(UserSettings.NGSettings.NGLiveCommentUserIds);
            IsNGCommentUserIdEnabled = UserSettings.NGSettings.ToReactivePropertyAsSynchronized(x => x.IsNGLiveCommentUserEnable, CurrentWindowContextScheduler)
                                       .AddTo(_CompositeDisposable);
        }
Пример #3
0
        public SettingsSidePaneContentViewModel(HohoemaUserSettings settings)
        {
            _NGSettings       = settings.NGSettings;
            _PlayerSettings   = settings.PlayerSettings;
            _PlaylistSettings = settings.PlaylistSettings;

            VideoPlayingQuality = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.DefaultQuality,
                                                                                   convert: x => VideoPlayingQualityList.First(y => y.Value == x),
                                                                                   convertBack: x => x.Value,
                                                                                   raiseEventScheduler: CurrentWindowContextScheduler,
                                                                                   mode: ReactivePropertyMode.DistinctUntilChanged
                                                                                   )
                                  .AddTo(_CompositeDisposable);
            VideoPlayingQuality.Subscribe(x =>
            {
                VideoQualityChanged?.Invoke(this, x.Value);
            })
            .AddTo(_CompositeDisposable);


            VideoPlaybackRate      = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.PlaybackRate);
            SetPlaybackRateCommand = VideoPlaybackRate.Select(
                rate => rate != 1.0
                )
                                     .ToReactiveCommand <double?>(CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);

            SetPlaybackRateCommand.Subscribe(
                (rate) => VideoPlaybackRate.Value = rate.HasValue ? rate.Value : 1.0
                )
            .AddTo(_CompositeDisposable);



            LiveVideoPlayingQuality = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.DefaultLiveQuality,
                                                                                       convert: x => LivePlayingQualityList.FirstOrDefault(y => y.Value == x),
                                                                                       convertBack: x => x.Value,
                                                                                       raiseEventScheduler: CurrentWindowContextScheduler,
                                                                                       mode: ReactivePropertyMode.DistinctUntilChanged
                                                                                       )
                                      .AddTo(_CompositeDisposable);

            IsLowLatency = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.LiveWatchWithLowLatency, CurrentWindowContextScheduler, mode: ReactivePropertyMode.DistinctUntilChanged)
                           .AddTo(_CompositeDisposable);

            IsKeepDisplayInPlayback = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.IsKeepDisplayInPlayback, CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);
            ScrollVolumeFrequency = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.SoundVolumeChangeFrequency, CurrentWindowContextScheduler)
                                    .AddTo(_CompositeDisposable);
            IsForceLandscapeDefault = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.IsForceLandscape, CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);

            AutoHideDelayTime = _PlayerSettings.ToReactivePropertyAsSynchronized(x =>
                                                                                 x.AutoHidePlayerControlUIPreventTime
                                                                                 , x => x.TotalSeconds
                                                                                 , x => TimeSpan.FromSeconds(x)
                                                                                 , CurrentWindowContextScheduler
                                                                                 )
                                .AddTo(_CompositeDisposable);

            PlaylistEndAction = _PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.PlaylistEndAction, CurrentWindowContextScheduler)
                                .AddTo(_CompositeDisposable);

            AutoMoveNextVideoOnPlaylistEmpty = _PlaylistSettings.ToReactivePropertyAsSynchronized(x => x.AutoMoveNextVideoOnPlaylistEmpty, CurrentWindowContextScheduler)
                                               .AddTo(_CompositeDisposable);


            // NG Comment User Id



            // Comment Display
            CommentColor = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.CommentColor, CurrentWindowContextScheduler)
                           .AddTo(_CompositeDisposable);
            IsPauseWithCommentWriting = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.PauseWithCommentWriting, CurrentWindowContextScheduler)
                                        .AddTo(_CompositeDisposable);
            CommentRenderingFPS = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.CommentRenderingFPS, CurrentWindowContextScheduler)
                                  .AddTo(_CompositeDisposable);
            CommentDisplayDuration = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.CommentDisplayDuration, x => x.TotalSeconds, x => TimeSpan.FromSeconds(x), CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);
            CommentFontScale = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCommentFontScale, CurrentWindowContextScheduler)
                               .AddTo(_CompositeDisposable);
            IsDefaultCommentWithAnonymous = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.IsDefaultCommentWithAnonymous, CurrentWindowContextScheduler)
                                            .AddTo(_CompositeDisposable);
            CommentOpacity = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.CommentOpacity, CurrentWindowContextScheduler)
                             .AddTo(_CompositeDisposable);

            IsEnableOwnerCommentCommand = new ReactiveProperty <bool>(CurrentWindowContextScheduler, _PlayerSettings.CommentCommandPermission.HasFlag(CommentCommandPermissionType.Owner))
                                          .AddTo(_CompositeDisposable);
            IsEnableUserCommentCommand = new ReactiveProperty <bool>(CurrentWindowContextScheduler, _PlayerSettings.CommentCommandPermission.HasFlag(CommentCommandPermissionType.User))
                                         .AddTo(_CompositeDisposable);
            IsEnableAnonymousCommentCommand = new ReactiveProperty <bool>(CurrentWindowContextScheduler, _PlayerSettings.CommentCommandPermission.HasFlag(CommentCommandPermissionType.Anonymous))
                                              .AddTo(_CompositeDisposable);

            IsEnableOwnerCommentCommand.Subscribe(x => SetCommentCommandPermission(x, CommentCommandPermissionType.Owner))
            .AddTo(_CompositeDisposable);
            IsEnableUserCommentCommand.Subscribe(x => SetCommentCommandPermission(x, CommentCommandPermissionType.User))
            .AddTo(_CompositeDisposable);
            IsEnableAnonymousCommentCommand.Subscribe(x => SetCommentCommandPermission(x, CommentCommandPermissionType.Anonymous))
            .AddTo(_CompositeDisposable);

            NicoScript_Default_Enabled = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.NicoScript_Default_Enabled, raiseEventScheduler: CurrentWindowContextScheduler)
                                         .AddTo(_CompositeDisposable);
            NicoScript_DisallowSeek_Enabled = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.NicoScript_DisallowSeek_Enabled, raiseEventScheduler: CurrentWindowContextScheduler)
                                              .AddTo(_CompositeDisposable);
            NicoScript_DisallowComment_Enabled = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.NicoScript_DisallowComment_Enabled, raiseEventScheduler: CurrentWindowContextScheduler)
                                                 .AddTo(_CompositeDisposable);
            NicoScript_Jump_Enabled = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.NicoScript_Jump_Enabled, raiseEventScheduler: CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);
            NicoScript_Replace_Enabled = _PlayerSettings.ToReactivePropertyAsSynchronized(x => x.NicoScript_Replace_Enabled, raiseEventScheduler: CurrentWindowContextScheduler)
                                         .AddTo(_CompositeDisposable);


            // NG Comment

            NGCommentUserIdEnable = _NGSettings.ToReactivePropertyAsSynchronized(x => x.NGCommentUserIdEnable, CurrentWindowContextScheduler)
                                    .AddTo(_CompositeDisposable);
            NGCommentUserIds = _NGSettings.NGCommentUserIds
                               .ToReadOnlyReactiveCollection(x =>
                                                             RemovableSettingsListItemHelper.UserIdInfoToRemovableListItemVM(x, OnRemoveNGCommentUserIdFromList),
                                                             CurrentWindowContextScheduler
                                                             )
                               .AddTo(_CompositeDisposable);

            NGCommentKeywordEnable = _NGSettings.ToReactivePropertyAsSynchronized(x => x.NGCommentKeywordEnable, CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);
            NGCommentKeywords = new ReactiveProperty <string>(CurrentWindowContextScheduler, string.Empty)
                                .AddTo(_CompositeDisposable);

            NGCommentKeywordError = NGCommentKeywords
                                    .Select(x =>
            {
                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(string.Empty);
                }
                else
                {
                    return($"Error in \"{invalidRegex}\"");
                }
            })
                                    .ToReadOnlyReactiveProperty(eventScheduler: CurrentWindowContextScheduler)
                                    .AddTo(_CompositeDisposable);

            NGCommentScoreTypes = ((IEnumerable <NGCommentScore>)Enum.GetValues(typeof(NGCommentScore))).ToList();

            SelectedNGCommentScore = _NGSettings.ToReactivePropertyAsSynchronized(x => x.NGCommentScoreType, CurrentWindowContextScheduler)
                                     .AddTo(_CompositeDisposable);



            CommentGlassMowerEnable = _PlayerSettings
                                      .ToReactivePropertyAsSynchronized(x => x.CommentGlassMowerEnable, CurrentWindowContextScheduler)
                                      .AddTo(_CompositeDisposable);
        }
Пример #4
0
        public async Task MigrateAsync()
        {
            if (_appFlagsRepository.IsSettingMigrated_V_0_23_0)
            {
                return;
            }

            try
            {
                var hohoemaUserSettings = await HohoemaUserSettings.LoadSettings(ApplicationData.Current.LocalFolder);


                Debug.WriteLine("[Migrate] AppearanceSetting");
                {
                    var appearanceSettings = hohoemaUserSettings.AppearanceSettings;
                    _appearanceSettings.Locale = appearanceSettings.Locale;
                    _appearanceSettings.FirstAppearPageType     = appearanceSettings.FirstAppearPageType;
                    _appearanceSettings.OverrideInteractionMode = appearanceSettings.OverrideIntractionMode;
                    _appearanceSettings.ApplicationTheme        = appearanceSettings.Theme;
                }
                Debug.WriteLine("[Migrate] AppearanceSetting done");

                Debug.WriteLine("[Migrate] RankingSetting");
                {
                    var rankingSettings = hohoemaUserSettings.RankingSettings;
                    foreach (var favRankingTag in rankingSettings.FavoriteTags)
                    {
                        _videoRankingSettings.AddFavoriteTag(favRankingTag.Genre, favRankingTag.Tag, favRankingTag.Label);
                    }

                    Debug.WriteLine("[Migrate] RankingSetting FavoriteTag migrated. ");

                    foreach (var hiddenRankingTag in rankingSettings.HiddenTags)
                    {
                        _videoRankingSettings.AddHiddenTag(hiddenRankingTag.Genre, hiddenRankingTag.Tag, hiddenRankingTag.Label);
                    }

                    Debug.WriteLine("[Migrate] RankingSetting HiddenTags migrated. ");

                    foreach (var hiddenGenre in rankingSettings.HiddenGenres)
                    {
                        _videoRankingSettings.AddHiddenGenre(hiddenGenre);
                    }

                    Debug.WriteLine("[Migrate] RankingSetting HiddenGenres migrated. ");
                }
                Debug.WriteLine("[Migrate] RankingSetting done");

                Debug.WriteLine("[Migrate] PinSetting");
                {
                    var pinSettings = hohoemaUserSettings.PinSettings;

                    int index = 0;
                    foreach (var pin in pinSettings.Pins)
                    {
                        _pinSettings.CreateItem(new Domain.Pins.HohoemaPin()
                        {
                            Label         = pin.Label,
                            Parameter     = pin.Parameter,
                            OverrideLabel = pin.OverrideLabel,
                            PageType      = pin.PageType,
                            SortIndex     = index
                        });

                        index++;
                    }
                }

                Debug.WriteLine("[Migrate] PinSetting done");

                Debug.WriteLine("[Migrate] NGSetting(VideoFilteringSettings)");
                {
                    var ngSettings = hohoemaUserSettings.NGSettings;
                    _videoFilteringRepository.NGVideoIdEnable           = ngSettings.NGVideoIdEnable;
                    _videoFilteringRepository.NGVideoOwnerUserIdEnable  = ngSettings.NGVideoOwnerUserIdEnable;
                    _videoFilteringRepository.NGVideoTitleKeywordEnable = ngSettings.NGVideoTitleKeywordEnable;

                    foreach (var videoId in  ngSettings.NGVideoIds)
                    {
                        _videoFilteringRepository.AddHiddenVideoId(videoId.VideoId, videoId.Description);
                    }

                    Debug.WriteLine("[Migrate] NGSetting ng video ids migrated");

                    foreach (var userId in ngSettings.NGVideoOwnerUserIds)
                    {
                        _videoFilteringRepository.AddHiddenVideoOwnerId(userId.UserId, userId.Description);
                    }

                    Debug.WriteLine("[Migrate] NGSetting ng video owner ids migrated");

                    foreach (var ngTitle in ngSettings.NGVideoTitleKeywords)
                    {
                        var titleEntry = _videoFilteringRepository.CreateVideoTitleFiltering();
                        titleEntry.Keyword = ngTitle.Keyword;
                        _videoFilteringRepository.UpdateVideoTitleFiltering(titleEntry);
                    }

                    Debug.WriteLine("[Migrate] NGSetting ng video title migrated");
                }
                Debug.WriteLine("[Migrate] NGSetting(VideoFilteringSettings) done");


                {
                    var ps = hohoemaUserSettings.PlayerSettings;
                    _playerSettings.DefaultVideoQuality     = ps.DefaultVideoQuality;
                    _playerSettings.DefaultLiveQuality      = ps.DefaultLiveQuality;
                    _playerSettings.LiveWatchWithLowLatency = ps.LiveWatchWithLowLatency;
                    _playerSettings.IsMute      = ps.IsMute;
                    _playerSettings.SoundVolume = ps.SoundVolume;
                    _playerSettings.SoundVolumeChangeFrequency  = ps.SoundVolumeChangeFrequency;
                    _playerSettings.IsLoudnessCorrectionEnabled = ps.IsLoudnessCorrectionEnabled;
                    _playerSettings.IsCommentDisplay_Video      = ps.IsCommentDisplay_Video;
                    _playerSettings.IsCommentDisplay_Live       = ps.IsCommentDisplay_Live;
                    _playerSettings.PauseWithCommentWriting     = ps.PauseWithCommentWriting;
                    _playerSettings.CommentDisplayDuration      = ps.CommentDisplayDuration;
                    _playerSettings.DefaultCommentFontScale     = ps.DefaultCommentFontScale;
                    _playerSettings.CommentOpacity = ps.CommentOpacity;
                    _playerSettings.IsDefaultCommentWithAnonymous = ps.IsDefaultCommentWithAnonymous;
                    _playerSettings.CommentColor = ps.CommentColor;
                    _playerSettings.IsAutoHidePlayerControlUI          = ps.IsAutoHidePlayerControlUI;
                    _playerSettings.AutoHidePlayerControlUIPreventTime = ps.AutoHidePlayerControlUIPreventTime;
                    _playerSettings.IsForceLandscape                   = ps.IsForceLandscape;
                    _playerSettings.PlaybackRate                       = ps.PlaybackRate;
                    _playerSettings.NicoScript_Default_Enabled         = ps.NicoScript_Default_Enabled;
                    _playerSettings.NicoScript_DisallowSeek_Enabled    = ps.NicoScript_DisallowSeek_Enabled;
                    _playerSettings.NicoScript_Jump_Enabled            = ps.NicoScript_Jump_Enabled;
                    _playerSettings.NicoScript_DisallowComment_Enabled = ps._NicoScript_DisallowComment_Enabled;
                    _playerSettings.NicoScript_Replace_Enabled         = ps.NicoScript_Replace_Enabled;
                    _playerSettings.IsCurrentVideoLoopingEnabled       = ps.IsCurrentVideoLoopingEnabled;
                    _playerSettings.IsPlaylistLoopingEnabled           = ps.IsPlaylistLoopingEnabled;
                    _playerSettings.IsShuffleEnable                    = ps.IsShuffleEnable;
                    _playerSettings.IsReverseModeEnable                = ps.IsReverseModeEnable;
                    _playerSettings.PlaylistEndAction                  = ps.PlaylistEndAction switch
                    {
                        Domain.Legacy.PlaylistEndAction.NothingDo => Domain.Player.PlaylistEndAction.NothingDo,
                        Domain.Legacy.PlaylistEndAction.ChangeIntoSplit => Domain.Player.PlaylistEndAction.ChangeIntoSplit,
                        Domain.Legacy.PlaylistEndAction.CloseIfPlayWithCurrentWindow => Domain.Player.PlaylistEndAction.CloseIfPlayWithCurrentWindow,
                        _ => throw new NotSupportedException()
                    };
                    _playerSettings.AutoMoveNextVideoOnPlaylistEmpty = ps.AutoMoveNextVideoOnPlaylistEmpty;
                }


                {
                    var allSettings = new SettingsBase[]
                    {
                        hohoemaUserSettings.RankingSettings,
                        hohoemaUserSettings.PlayerSettings,
                        hohoemaUserSettings.PinSettings,
                        hohoemaUserSettings.NGSettings,
                        hohoemaUserSettings.CacheSettings,
                        hohoemaUserSettings.AppearanceSettings,
                        hohoemaUserSettings.ActivityFeedSettings
                    };

                    hohoemaUserSettings.Dispose();

                    foreach (var setting in allSettings)
                    {
                        Debug.WriteLine("[Migrate] Delete legacy settings :" + setting.FileName);
                        var file = await setting.GetFile();

                        await file.DeleteAsync();
                    }
                }
            }
            catch
            {
            }
            finally
            {
                _appFlagsRepository.IsSettingMigrated_V_0_23_0 = true;
            }
        }