예제 #1
0
        // コンストラクタ

        public ConfigureApiKeyViewModel(DialogService dialogService, AddAccountService addAccountModel)
        {
            // DI
            _dialogService     = dialogService;
            _addAccountService = addAccountModel;

            // バリデーションを有効化する
            ConsumerKey.SetValidateAttribute(() => ConsumerKey);
            ConsumerSecret.SetValidateAttribute(() => ConsumerSecret);

            // ConsumerKeyとConsumerKeyが正しく入力されているときのみ「次へ」を押せるようにする
            NextCommand = new[]
            {
                ConsumerKey.ObserveHasErrors,
                ConsumerSecret.ObserveHasErrors
            }
            .CombineLatestValuesAreAllFalse()
            .ToReactiveCommand()
            .AddTo(Disposables);

            // 「次へ」が押されたらPinコード設定画面を開く
            NextCommand
            .Subscribe(() =>
            {
                _addAccountService.OpenAuthorizeUrl(ConsumerKey.Value, ConsumerSecret.Value);
                _dialogService.OpenConfigurePincodeView();
            })
            .AddTo(Disposables);
        }
        // コンストラクタ

        public ConfigurePincodeViewModel(DialogService dialogService, AddAccountService addAccountModel)
        {
            // DI
            _dialogService     = dialogService;
            _addAccountService = addAccountModel;

            // バリデーションを有効化する
            Pincode.SetValidateAttribute(() => Pincode);

            // Pincodeが入力されているときのみ「次へ」を押せるようにする
            NextCommand = Pincode
                          .ObserveHasErrors
                          .Select(x => !x)
                          .ToReactiveCommand()
                          .AddTo(Disposables);

            // 「次へ」が押されたらPinコードの認証を開始する
            NextCommand.Subscribe(() =>
            {
                _addAccountService.ConfigureAccessTokens(Pincode.Value);
                _dialogService.CloseConfigurePincodeView();
                _dialogService.CloseConfigureApiKeyView();
            })
            .AddTo(Disposables);
        }