Пример #1
0
 public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
 {
     this._parent = parent;
     this._screenName = screenName;
     StoreHelper.GetUser(screenName)
                .Finally(() => Communicating = false)
                .Subscribe(
                    user =>
                    {
                        User = new UserViewModel(user);
                        var ps = this._statuses;
                        this._statuses = new UserStatusesViewModel(this);
                        this.RaisePropertyChanged(() => Statuses);
                        if (ps != null)
                        {
                            ps.Dispose();
                        }
                        var pf = this._favorites;
                        this._favorites = new UserFavoritesViewModel(this);
                        this.RaisePropertyChanged(() => Favorites);
                        if (pf != null)
                        {
                            pf.Dispose();
                        }
                        var pfw = this._following;
                        this._following = new UserFollowingViewModel(this);
                        this.RaisePropertyChanged(() => Following);
                        if (pfw != null)
                        {
                            pfw.Dispose();
                        }
                        var pfr = this._followers;
                        this._followers = new UserFollowersViewModel(this);
                        this.RaisePropertyChanged(() => Followers);
                        if (pfr != null)
                        {
                            pfr.Dispose();
                        }
                        Observable.Start(() => AccountsStore.Accounts)
                                  .SelectMany(a => a)
                                  .Where(a => a.UserId != user.Id)
                                  .Select(a => new RelationControlViewModel(this, a.AuthenticateInfo, user))
                                  .ObserveOn(DispatcherHolder.Dispatcher, DispatcherPriority.Render)
                                  .Subscribe(RelationControls.Add);
                    },
                    ex =>
                    {
                        parent.Messenger.Raise(new TaskDialogMessage(new TaskDialogOptions
                        {
                            Title = "ユーザー表示エラー",
                            MainIcon = VistaTaskDialogIcon.Error,
                            MainInstruction = "ユーザーを表示できません。",
                            Content = ex.Message,
                            CommonButtons = TaskDialogCommonButtons.Close
                        }));
                        User = null;
                        parent.CloseResults();
                    });
 }
Пример #2
0
        /// <summary>
        ///     Constructor
        /// </summary>
        public InputAreaViewModel()
        {
            _provider = new InputAreaSuggestItemProvider();
            _accountSelectionFlip = new AccountSelectionFlipViewModel();
            _accountSelectionFlip.Closed += () =>
            {
                // After selection accounts, return focus to text box
                // if input area is opened.
                if (IsOpening)
                {
                    FocusToTextBox();
                }
            };

            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.BindingAuthInfos,
                                        _ => new AuthenticateInfoViewModel(_),
                                        DispatcherHelper.UIDispatcher));

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

            var accountSelectReflecting = false;
            _accountSelectionFlip.SelectedAccountsChanged += () =>
            {
                if (!_isSuppressAccountChangeRelay)
                {
                    // write-back
                    accountSelectReflecting = true;
                    InputAreaModel.BindingAuthInfos.Clear();
                    _accountSelectionFlip.SelectedAccounts
                                    .ForEach(InputAreaModel.BindingAuthInfos.Add);
                    accountSelectReflecting = false;
                    _baseSelectedAccounts = InputAreaModel.BindingAuthInfos.Select(_ => _.Id).ToArray();
                }
                InputInfo.AuthInfos = AccountSelectionFlip.SelectedAccounts;
                RaisePropertyChanged(() => AuthInfoGridRowColumn);
                UpdateTextCount();
                RaisePropertyChanged(() => IsPostLimitPredictionEnabled);
            };
            CompositeDisposable.Add(_accountSelectionFlip);
            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.SetTextRequested += _,
                    _ => InputAreaModel.SetTextRequested -= _,
                    async (infos, body, cursor, inReplyTo) =>
                    {
                        OpenInput(false);
                        if (!CheckClearInput(body)) return;
                        if (infos != null)
                        {
                            OverrideSelectedAccounts(infos);
                        }
                        if (inReplyTo != null)
                        {
                            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<AuthenticateInfo>, 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();
        }