Ejemplo n.º 1
0
        private void LoadConfigSettings()
        {
            NowPlayingConfig = new NowPlayingConfigWorker();

            if (NowPlayingConfig.Config.IsNightModeEnabled)
            {
                NightModeSwitch.Toggle();
                ToggleSwitchNightMode_MouseLeftButtonDown(null, null);
            }

            if (NowPlayingConfig.Config.IsAutoSendEnabled)
            {
                CheckBoxAutoSend.DefaultCheckBox.IsChecked = true;
            }

            if (NowPlayingConfig.Config.IsDebugModeEnabled)
            {
                DebugCheckBox.Visibility = Visibility.Visible;
            }

            TextBoxKeyBind.DefaultTextBox.Text = NowPlayingConfig.Config.LastUsedKey;
        }
Ejemplo n.º 2
0
        public MainPage()
        {
            InitializeComponent();

            this.WhenActivated(disposables =>
            {
                NightModeBrightnessPicker.Items = Enumerable.Range(0, 255).ToArray();

                this.WhenAnyValue(x => x.ViewModel.Color)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Select(x => Color.FromRgba(x.R / 255f, x.G / 255f, x.B / 255f, x.A / 32f))
                .BindTo(this, x => x.Grid.BackgroundColor)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Color)
                .Select(x => x.GetBrightness())
                .Merge(this
                       .WhenAnyValue(x => x.ViewModel.Color.A)
                       .Select(x => x / 255f)
                       .Skip(1))
                .Select(x => 1 - x)
                .Select(x => Color.FromRgb(x, x, x))
                .SubscribeSafe(SetTextColors)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.ConnectionState.Message)
                .ObserveOn(RxApp.MainThreadScheduler)
                .BindTo(this, x => x.ConnectionStateLabel.Text)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.ConnectionState.Type)
                .Select(x => x == StateType.Connecting)
                .ObserveOn(RxApp.MainThreadScheduler)
                .BindTo(this, x => x.ProgressIndicator.IsVisible)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.ConnectionState.Type)
                .Select(x => x == StateType.Connected)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(SetSliderIsEnabled)
                .Select(x => x ? 1f : 0.5f)
                .Do(SetSliderOpacity)
                .SubscribeSafe()
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Red)
                .BindTo(this, x => x.RedLabel.Text)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Green)
                .BindTo(this, x => x.GreenLabel.Text)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Blue)
                .BindTo(this, x => x.BlueLabel.Text)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Alpha)
                .BindTo(this, x => x.BrightnessLabel.Text)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Red)
                .Take(1)
                .BindTo(this, x => x.RedSlider.Value)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Green)
                .Take(1)
                .BindTo(this, x => x.GreenSlider.Value)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Blue)
                .Take(1)
                .BindTo(this, x => x.BlueSlider.Value)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.Alpha)
                .Take(1)
                .BindTo(this, x => x.BrightnessSlider.Value)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.IsNightModeEnabled)
                .CombineLatest(GetInitialNightModePickerRowHeight(), Tuple.Create)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(AnimateNightModePickerLayout)
                .Select(x => x.Item1)
                .BindTo(this, x => x.NightModeSwitch.IsToggled)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.NightModeBrightness)
                .ObserveOn(RxApp.MainThreadScheduler)
                .BindTo(this, x => x.NightModeBrightnessPicker.SelectedIndex)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.NightModeFromTime)
                .ObserveOn(RxApp.MainThreadScheduler)
                .SubscribeSafe(x => NightModeFromTimePicker.GetUnderlyingPicker().Time = x)
                .DisposeWith(disposables);

                this.WhenAnyValue(x => x.ViewModel.NightModeToTime)
                .ObserveOn(RxApp.MainThreadScheduler)
                .SubscribeSafe(x => NightModeToTimePicker.GetUnderlyingPicker().Time = x)
                .DisposeWith(disposables);

                RedSlider
                .ValueChange()
                .Select(x => (int)x)
                .BindTo(ViewModel, x => x.Red)
                .DisposeWith(disposables);

                GreenSlider
                .ValueChange()
                .Select(x => (int)x)
                .BindTo(ViewModel, x => x.Green)
                .DisposeWith(disposables);

                BlueSlider
                .ValueChange()
                .Select(x => (int)x)
                .BindTo(ViewModel, x => x.Blue)
                .DisposeWith(disposables);

                BrightnessSlider
                .ValueChange()
                .Select(x => (int)x)
                .BindTo(ViewModel, x => x.Alpha)
                .DisposeWith(disposables);

                NightModeSwitch
                .ToggleChange()
                .BindTo(ViewModel, x => x.IsNightModeEnabled)
                .DisposeWith(disposables);

                NightModeBrightnessPicker
                .SelectionChange()
                .BindTo(ViewModel, x => x.NightModeBrightness)
                .DisposeWith(disposables);

                NightModeFromTimePicker
                .TimeChange()
                .BindTo(ViewModel, x => x.NightModeFromTime)
                .DisposeWith(disposables);

                NightModeToTimePicker
                .TimeChange()
                .BindTo(ViewModel, x => x.NightModeToTime)
                .DisposeWith(disposables);
            });
        }