public AccountSelectorViewModel(InputViewModel parent)
 {
     _parent = parent;
     this._accountSelectionFlip = new AccountSelectionFlipViewModel();
     this.AccountSelectionFlip.Closed += () =>
     {
         // After selection accounts, return focus to text box
         // if input area is opened.
         if (_parent.IsOpening)
         {
             _parent.FocusToTextBox();
         }
     };
     this.AccountSelectionFlip.SelectedAccountsChanged += () =>
     {
         InputModel.AccountSelector.Accounts.Clear();
         Setting.Accounts.Collection
                .Where(a => AccountSelectionFlip.SelectedAccounts.Contains(a))
                .ForEach(InputModel.AccountSelector.Accounts.Add);
     };
     CompositeDisposable.Add(this.AccountSelectionFlip);
     CompositeDisposable.Add(
         ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
             InputModel.AccountSelector.Accounts,
             a => new TwitterAccountViewModel(a),
             DispatcherHelper.UIDispatcher));
     CompositeDisposable.Add(
         InputModel.AccountSelector.Accounts.ListenCollectionChanged()
                   .Subscribe(_ =>
                   {
                       RaisePropertyChanged(() => AuthInfoGridRowColumn);
                       this.RaisePropertyChanged(() => AuthInfoScreenNames);
                   }));
     CompositeDisposable.Add(this._accounts =
         ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
             InputModel.AccountSelector.Accounts,
             account => new TwitterAccountViewModel(account),
             DispatcherHelper.UIDispatcher));
     CompositeDisposable.Add(this._accounts
         .ListenCollectionChanged()
         .Subscribe(_ =>
         {
             this.RaisePropertyChanged(() => AuthInfoGridRowColumn);
             RaisePropertyChanged(() => IsBindingAuthInfoExisted);
         }));
     CompositeDisposable.Add(
         InputModel.AccountSelector.ListenPropertyChanged(
             () => InputModel.AccountSelector.IsSynchronizedWithTab)
                   .Subscribe(_ => RaisePropertyChanged(() => IsSynchronizedWithTab)));
 }
Example #2
0
 public MainWindowViewModel()
 {
     CompositeDisposable.Add(_backstageViewModel = new BackstageViewModel());
     CompositeDisposable.Add(_inputAreaViewModel = new InputAreaViewModel());
     CompositeDisposable.Add(_mainAreaViewModel = new MainAreaViewModel());
     CompositeDisposable.Add(_globalAccountSelectionFlipViewModel = new AccountSelectionFlipViewModel());
     CompositeDisposable.Add(_tabConfigurationFlipViewModel = new TabConfigurationFlipViewModel());
     CompositeDisposable.Add(_searchFlipViewModel = new SearchFlipViewModel());
     CompositeDisposable.Add(Observable.FromEvent<FocusRequest>(
         h => MainWindowModel.FocusRequested += h,
         h => MainWindowModel.FocusRequested -= h)
         .Subscribe(SetFocus));
     CompositeDisposable.Add(Observable.FromEvent<Tuple<string, FilterExpressionBase>>(
         h => MainWindowModel.ConfirmMuteRequested += h,
         h => MainWindowModel.ConfirmMuteRequested -= h)
         .Subscribe(OnMuteRequested));
     CompositeDisposable.Add(Observable.FromEvent<bool>(
         h => MainWindowModel.BackstageTransitionRequested += h,
         h => MainWindowModel.BackstageTransitionRequested -= h)
         .Subscribe(this.TransitionBackstage));
     this._backstageViewModel.Initialize();
 }
 public MainWindowViewModel()
 {
     CompositeDisposable.Add(_backstageViewModel = new BackstageViewModel());
     CompositeDisposable.Add(this._inputViewModel = new InputViewModel());
     CompositeDisposable.Add(_mainAreaViewModel = new MainAreaViewModel());
     CompositeDisposable.Add(_globalAccountSelectionFlipViewModel = new AccountSelectionFlipViewModel());
     CompositeDisposable.Add(_settingFlipViewModel = new SettingFlipViewModel(this));
     CompositeDisposable.Add(_tabConfigurationFlipViewModel = new TabConfigurationFlipViewModel());
     CompositeDisposable.Add(_searchFlipViewModel = new SearchFlipViewModel());
     CompositeDisposable.Add(Observable
         .FromEvent<FocusRequest>(
             h => MainWindowModel.FocusRequested += h,
             h => MainWindowModel.FocusRequested -= h)
         .Subscribe(SetFocus));
     CompositeDisposable.Add(Observable
         .FromEvent<bool>(
             h => MainWindowModel.BackstageTransitionRequested += h,
             h => MainWindowModel.BackstageTransitionRequested -= h)
         .Subscribe(this.TransitionBackstage));
     CompositeDisposable.Add(Setting.BackgroundImagePath.ListenValueChanged(
         _ =>
         {
             RaisePropertyChanged(() => BackgroundImageUri);
             RaisePropertyChanged(() => BackgroundImage);
         }));
     CompositeDisposable.Add(Setting.BackgroundImageTransparency.ListenValueChanged(
         _ => RaisePropertyChanged(() => BackgroundImageOpacity)));
     this._backstageViewModel.Initialize();
 }
 public SelectableAccountViewModel(AccountSelectionFlipViewModel parent, TwitterAccount account, Action onSelectionChanged)
 {
     this._parent = parent;
     this._account = account;
     this._onSelectionChanged = onSelectionChanged;
 }
 public SelectableAccountViewModel(AccountSelectionFlipViewModel parent, TwitterAccount account, Action onSelectionChanged)
 {
     this._parent             = parent;
     this._account            = account;
     this._onSelectionChanged = onSelectionChanged;
 }
        /// <summary>
        ///     Constructor
        /// </summary>
        public InputAreaViewModel()
        {
            _provider = new InputAreaSuggestItemProvider();

            #region Account control
            _accountSelectionFlip = new AccountSelectionFlipViewModel();
            _accountSelectionFlip.Closed += () =>
            {
                // After selection accounts, return focus to text box
                // if input area is opened.
                if (IsOpening)
                {
                    FocusToTextBox();
                }
            };
            var accountSelectReflecting = false;
            _accountSelectionFlip.SelectedAccountsChanged += () =>
            {
                if (!_isSuppressAccountChangeRelay)
                {
                    // write-back
                    accountSelectReflecting = true;
                    InputAreaModel.BindingAccounts.Clear();
                    _accountSelectionFlip.SelectedAccounts
                                    .ForEach(InputAreaModel.BindingAccounts.Add);
                    accountSelectReflecting = false;
                    _baseSelectedAccounts = InputAreaModel.BindingAccounts.Select(_ => _.Id).ToArray();
                }
                InputInfo.Accounts = AccountSelectionFlip.SelectedAccounts;
                RaisePropertyChanged(() => AuthInfoGridRowColumn);
                UpdateTextCount();
                RaisePropertyChanged(() => IsPostLimitPredictionEnabled);
            };
            CompositeDisposable.Add(_accountSelectionFlip);
            CompositeDisposable.Add(
                new CollectionChangedEventListener(
                    InputAreaModel.BindingAccounts,
                    (_, __) =>
                    {
                        RaisePropertyChanged(() => IsPostLimitPredictionEnabled);
                        if (accountSelectReflecting) return;
                        _baseSelectedAccounts = InputAreaModel.BindingAccounts
                                                              .Select(a => a.Id)
                                                              .ToArray();
                        ApplyBaseSelectedAccounts();
                        UpdateTextCount();
                    }));
            #endregion

            CompositeDisposable.Add(_bindingHashtags =
                                    ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                        InputAreaModel.BindingHashtags,
                                        _ => new BindHashtagViewModel(_, () => UnbindHashtag(_)),
                                        DispatcherHelper.UIDispatcher));
            CompositeDisposable.Add(_bindingHashtags
                                        .ListenCollectionChanged()
                                        .Subscribe(_ => RaisePropertyChanged(() => IsBindingHashtagExisted)));

            _bindableHashtagCandidates =
                new DispatcherCollection<BindHashtagViewModel>(DispatcherHelper.UIDispatcher);
            CompositeDisposable.Add(_bindableHashtagCandidates
                                        .ListenCollectionChanged()
                                        .Subscribe(_ => RaisePropertyChanged(() => IsBindableHashtagExisted)));

            CompositeDisposable.Add(_draftedInputs =
                                    ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                        InputAreaModel.Drafts,
                                        _ =>
                                        new TweetInputInfoViewModel(this, _, vm => InputAreaModel.Drafts.Remove(vm)),
                                        DispatcherHelper.UIDispatcher));

            CompositeDisposable.Add(_draftedInputs
                                        .ListenCollectionChanged()
                                        .Subscribe(_ =>
                                        {
                                            RaisePropertyChanged(() => DraftCount);
                                            RaisePropertyChanged(() => IsDraftsExisted);
                                        }));

            CompositeDisposable.Add(_bindingAuthInfos =
                                    ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                        InputAreaModel.BindingAccounts,
                                        account => new TwitterAccountViewModel(account),
                                        DispatcherHelper.UIDispatcher));

            CompositeDisposable.Add(_bindingAuthInfos
                                        .ListenCollectionChanged()
                                        .Subscribe(_ => RaisePropertyChanged(() => IsBindingAuthInfoExisted)));

            CompositeDisposable.Add(
                new EventListener<Action<IEnumerable<TwitterAccount>, string, CursorPosition, TwitterStatus>>(
                    h => InputAreaModel.SetTextRequested += h,
                    h => InputAreaModel.SetTextRequested -= h, (infos, body, cursor, inReplyTo) =>
                    {
                        OpenInput(false);
                        if (!CheckClearInput(body)) return;
                        if (infos != null)
                        {
                            OverrideSelectedAccounts(infos);
                        }
                        if (inReplyTo != null)
                        {
                            Task.Run(async () => InReplyTo = new StatusViewModel(await StatusModel.Get(inReplyTo)));
                        }
                        switch (cursor)
                        {
                            case CursorPosition.Begin:
                                Messenger.Raise(new TextBoxSetCaretMessage(0));
                                break;
                            case CursorPosition.End:
                                Messenger.Raise(new TextBoxSetCaretMessage(InputText.Length));
                                break;
                        }
                    }));

            CompositeDisposable.Add(
                new EventListener<Action<IEnumerable<TwitterAccount>, TwitterUser>>(
                    _ => InputAreaModel.SendDirectMessageRequested += _,
                    _ => InputAreaModel.SendDirectMessageRequested -= _,
                    (infos, user) =>
                    {
                        OpenInput(false);
                        CheckClearInput();
                        OverrideSelectedAccounts(infos);
                        DirectMessageTo = new UserViewModel(user);
                    }));

            CompositeDisposable.Add(InitPostLimitPrediction());

            _geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
            _geoWatcher.StatusChanged += (_, e) =>
            {
                if (e.Status != GeoPositionStatus.Ready)
                {
                    IsLocationEnabled = true;
                }
                else
                {
                    IsLocationEnabled = false;
                    AttachedLocation = null;
                }
            };
            CompositeDisposable.Add(_geoWatcher);
            _geoWatcher.Start();
        }
 public SelectableAccountViewModel(AccountSelectionFlipViewModel parent, AuthenticateInfo info, Action onSelectionChanged)
 {
     this._parent = parent;
     this._info = info;
     this._onSelectionChanged = onSelectionChanged;
 }