Ejemplo n.º 1
0
 public MainWindowViewModel()
 {
     CompositeDisposable.Add(_backpanelViewModel = new BackpanelViewModel());
     CompositeDisposable.Add(_inputAreaViewModel = new InputAreaViewModel());
     CompositeDisposable.Add(_mainAreaViewModel = new MainAreaViewModel());
     CompositeDisposable.Add(_globalAccountSelectorViewModel = new AccountSelectorViewModel());
     _backpanelViewModel.Initialize();
 }
Ejemplo n.º 2
0
 public SelectableAccountViewModel(AccountSelectorViewModel parent, AuthenticateInfo info, Action onSelectionChanged)
 {
     this._parent = parent;
     this._info = info;
     this._onSelectionChanged = onSelectionChanged;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Constructor
        /// </summary>
        public InputAreaViewModel()
        {
            _accountSelector = new AccountSelectorViewModel();
            _accountSelector.OnClosed += () =>
            {
                // After selection accounts, return focus to text box
                // if input area is opened.
                if (IsOpening)
                {
                    FocusToTextBox();
                }
            };

            CompositeDisposable.Add(_bindingHashtags =
                                    ViewModelHelper.CreateReadOnlyDispatcherCollection(
                                        InputAreaModel.BindingHashtags,
                                        _ => new BindHashtagViewModel(_, () => UnbindHashtag(_)),
                                        DispatcherHelper.UIDispatcher));
            CompositeDisposable.Add(new CollectionChangedEventListener(
                                        _bindingHashtags, (_, __) => RaisePropertyChanged(() => IsBindingHashtagExisted)));

            _bindableHashtagCandidates =
                new DispatcherCollection<BindHashtagViewModel>(DispatcherHelper.UIDispatcher);
            CompositeDisposable.Add(new CollectionChangedEventListener(
                                        _bindableHashtagCandidates,
                                        (_, __) => RaisePropertyChanged(() => IsBindableHashtagExisted)));

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

            CompositeDisposable.Add(new CollectionChangedEventListener(_draftedInputs,
                                                                       (o, ev) =>
                                                                       {
                                                                           RaisePropertyChanged(() => DraftCount);
                                                                           RaisePropertyChanged(() => IsDraftsExisted);
                                                                       }));

            CompositeDisposable.Add(_bindingAuthInfos =
                                    ViewModelHelper.CreateReadOnlyDispatcherCollection(
                                        InputAreaModel.BindingAuthInfos,
                                        _ => new AuthenticateInfoViewModel(_),
                                        DispatcherHelper.UIDispatcher));

            CompositeDisposable.Add(new CollectionChangedEventListener(
                                        _bindingAuthInfos,
                                        (_, __) => RaisePropertyChanged(() => IsBindingAuthInfoExisted)));

            bool accountSelectReflecting = false;
            _accountSelector.OnSelectedAccountsChanged += () =>
            {
                if (!_isSuppressAccountChangeRelay)
                {
                    // write-back
                    accountSelectReflecting = true;
                    InputAreaModel.BindingAuthInfos.Clear();
                    _accountSelector.SelectedAccounts
                                    .ForEach(InputAreaModel.BindingAuthInfos.Add);
                    accountSelectReflecting = false;
                    _baseSelectedAccounts = InputAreaModel.BindingAuthInfos.Select(_ => _.Id).ToArray();
                }
                InputInfo.AuthInfos = AccountSelector.SelectedAccounts;
                RaisePropertyChanged(() => AuthInfoGridRowColumn);
                UpdateTextCount();
                RaisePropertyChanged(() => IsPostLimitPredictionEnabled);
            };
            CompositeDisposable.Add(_accountSelector);
            CompositeDisposable.Add(
                new CollectionChangedEventListener(
                    InputAreaModel.BindingAuthInfos,
                    (_, __) =>
                    {
                        RaisePropertyChanged(() => IsPostLimitPredictionEnabled);
                        if (accountSelectReflecting) return;
                        _baseSelectedAccounts = InputAreaModel.BindingAuthInfos
                                                              .Select(a => a.Id)
                                                              .ToArray();
                        ApplyBaseSelectedAccounts();
                        UpdateTextCount();
                    }));
            CompositeDisposable.Add(
                new EventListener<Action<IEnumerable<AuthenticateInfo>, string, CursorPosition, TwitterStatus>>(
                    _ => InputAreaModel.OnSetTextRequested += _,
                    _ => InputAreaModel.OnSetTextRequested -= _,
                    (infos, body, cursor, inReplyTo) =>
                    {
                        OpenInput(false);
                        if (!CheckClearInput(body)) return;
                        if (infos != null)
                        {
                            OverrideSelectedAccounts(infos);
                        }
                        InReplyTo = new StatusViewModel(inReplyTo);
                        switch (cursor)
                        {
                            case CursorPosition.Begin:
                                Messenger.RaiseAsync(new TextBoxSetCaretMessage(0));
                                break;
                            case CursorPosition.End:
                                Messenger.RaiseAsync(new TextBoxSetCaretMessage(InputText.Length));
                                break;
                        }
                    }));
            CompositeDisposable.Add(
                new EventListener<Action<IEnumerable<AuthenticateInfo>, TwitterUser>>(
                    _ => InputAreaModel.OnSendDirectMessageRequested += _,
                    _ => InputAreaModel.OnSendDirectMessageRequested -= _,
                    (infos, user) =>
                    {
                        OpenInput(false);
                        CheckClearInput();
                        OverrideSelectedAccounts(infos);
                        DirectMessageTo = new UserViewModel(user);
                    }));

            _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();
        }