public BackstageAccountViewModel(BackstageViewModel parent, BackstageAccountModel model)
 {
     _parent = parent;
     _model = model;
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.ConnectionStateChanged += h,
             h => _model.ConnectionStateChanged -= h)
                   .Subscribe(_ => ConnectionStateChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.TwitterUserChanged += h,
             h => _model.TwitterUserChanged -= h)
                   .Subscribe(_ => UserChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.FallbackStateUpdated += h,
             h => _model.FallbackStateUpdated -= h)
                   .Subscribe(_ => this.FallbackStateUpdated()));
     this.CompositeDisposable.Add(
         Observable.Interval(TimeSpan.FromSeconds(5))
                   .Subscribe(_ =>
                   {
                       var count = PostLimitPredictionService.GetCurrentWindowCount(model.Account.Id);
                       MaxUpdate = Setting.PostLimitPerWindow.Value;
                       RemainUpdate = MaxUpdate - count;
                       this.RaisePropertyChanged(() => RemainUpdate);
                       this.RaisePropertyChanged(() => MaxUpdate);
                       this.RaisePropertyChanged(() => IsWarningPostLimit);
                   }));
     this.CompositeDisposable.Add(() =>
     {
         if (this._uvmCache == null) return;
         var cache = this._uvmCache;
         this._uvmCache = null;
         cache.Dispose();
     });
     UpdateUserCache();
 }
 public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
 {
     this._parent = parent;
     this._screenName = screenName;
     var cd = new CompositeDisposable();
     this.CompositeDisposable.Add(cd);
     cd.Add(
         StoreHelper.GetUser(screenName)
                    .Finally(() => Communicating = false)
                    .ObserveOnDispatcher()
                    .Subscribe(
                        user =>
                        {
                            User = new UserViewModel(user);
                            var ps = this._statuses;
                            var usm = new UserTimelineModel(user.Id, TimelineType.User);
                            this._statuses = new UserTimelineViewModel(this, usm);
                            this.RaisePropertyChanged(() => Statuses);
                            cd.Add(_statuses);
                            if (ps != null)
                            {
                                ps.Dispose();
                            }
                            var pf = this._favorites;
                            var ufm = new UserTimelineModel(user.Id, TimelineType.Favorites);
                            this._favorites = new UserTimelineViewModel(this, ufm);
                            this.RaisePropertyChanged(() => Favorites);
                            cd.Add(_favorites);
                            if (pf != null)
                            {
                                pf.Dispose();
                            }
                            var pfw = this._following;
                            this._following = new UserFollowingViewModel(this);
                            this.RaisePropertyChanged(() => Following);
                            cd.Add(_following);
                            if (pfw != null)
                            {
                                pfw.Dispose();
                            }
                            var pfr = this._followers;
                            this._followers = new UserFollowersViewModel(this);
                            this.RaisePropertyChanged(() => Followers);
                            cd.Add(_followers);
                            if (pfr != null)
                            {
                                pfr.Dispose();
                            }
                            Setting.Accounts.Collection
                                   .Where(a => a.Id != user.Id)
                                   .Select(a => new RelationControlViewModel(this, a, user))
                                   .ForEach(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();
                        }));
 }
        /// <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();
        }
Beispiel #4
0
 private UserViewModel CreateUserViewModel(TwitterUser user)
 {
     var uvm = new UserViewModel(user);
     try
     {
         CompositeDisposable.Add(uvm);
         return uvm;
     }
     catch (ObjectDisposedException)
     {
         // release all subscriptions
         uvm.Dispose();
         return uvm;
     }
 }
Beispiel #5
0
        public UserInfoViewModel(SearchFlipViewModel parent, string screenName)
        {
            this._parent = parent;
            this._screenName = screenName;
            this.CompositeDisposable.Add(
                parent.ListenPropertyChanged(() => parent.DisplaySlimView)
                      .Subscribe(_ => RaisePropertyChanged(() => DisplaySlimView)));
            this.CompositeDisposable.Add(
                StoreHelper.GetUser(screenName)
                           .Finally(() => Communicating = false)
                           .ObserveOnDispatcher()
                           .Subscribe(
                               user =>
                               {
                                   User = new UserViewModel(user);
                                   this.CompositeDisposable.Add(User);

                                   this.CompositeDisposable.Add(this._statuses = new UserTimelineViewModel(this,
                                       new UserTimelineModel(user.Id, TimelineType.User)));
                                   this.RaisePropertyChanged(() => Statuses);

                                   this.CompositeDisposable.Add(this._favorites = new UserTimelineViewModel(this,
                                       new UserTimelineModel(user.Id, TimelineType.Favorites)));
                                   this.RaisePropertyChanged(() => Favorites);

                                   this.CompositeDisposable.Add(this._following = new UserFollowingViewModel(this));
                                   this.RaisePropertyChanged(() => Following);

                                   this.CompositeDisposable.Add(this._followers = new UserFollowersViewModel(this));
                                   this.RaisePropertyChanged(() => Followers);

                                   Setting.Accounts.Collection
                                          .Where(a => a.Id != user.Id)
                                          .Select(a => new RelationControlViewModel(this, a, user))
                                          .ForEach(RelationControls.Add);
                               },
                               ex =>
                               {
                                   parent.Messenger.RaiseSafe(() => new TaskDialogMessage(new TaskDialogOptions
                                   {
                                       Title = SearchFlipResources.MsgUserInfoLoadErrorTitle,
                                       MainIcon = VistaTaskDialogIcon.Error,
                                       MainInstruction = SearchFlipResources.MsgUserInfoLoadErrorInst,
                                       Content = ex.Message,
                                       CommonButtons = TaskDialogCommonButtons.Close
                                   }));
                                   User = null;
                                   parent.CloseResults();
                               }));
        }
        private async void LoadUser(string screenName)
        {
            try
            {
                var user = await StoreHelper.GetUserAsync(screenName);
                // overwrite by oficially-provided screen name
                this._screenName = user.ScreenName;
                RaisePropertyChanged(() => ScreenName);

                User = new UserViewModel(user);
                this.CompositeDisposable.Add(User);

                Setting.Accounts.Collection
                       .Where(a => a.Id != user.Id)
                       .Select(a => new RelationControlViewModel(this, a, user))
                       .ForEach(RelationControls.Add);

                this.CompositeDisposable.Add(this._statuses = new UserTimelineViewModel(this,
                    new UserTimelineModel(user.Id, TimelineType.User)));
                this.RaisePropertyChanged(() => Statuses);

                this.CompositeDisposable.Add(this._favorites = new UserTimelineViewModel(this,
                    new UserTimelineModel(user.Id, TimelineType.Favorites)));
                this.RaisePropertyChanged(() => Favorites);

                this.CompositeDisposable.Add(this._following = new UserFollowingViewModel(this));
                this.RaisePropertyChanged(() => Following);

                this.CompositeDisposable.Add(this._followers = new UserFollowersViewModel(this));
                this.RaisePropertyChanged(() => Followers);
            }
            catch (Exception ex)
            {
                _parent.Messenger.RaiseSafe(() => new TaskDialogMessage(new TaskDialogOptions
                {
                    Title = SearchFlipResources.MsgUserInfoLoadErrorTitle,
                    MainIcon = VistaTaskDialogIcon.Error,
                    MainInstruction =
                        SearchFlipResources.MsgUserInfoLoadErrorInstFormat.SafeFormat(
                            SearchFlipResources.MsgUserProfile),
                    Content = ex.Message,
                    CommonButtons = TaskDialogCommonButtons.Close
                }));
                User = null;
                _parent.CloseResults();
            }
            finally
            {
                Communicating = false;
            }
        }
Beispiel #7
0
 private UserViewModel CreateUserViewModel(TwitterUser user)
 {
     var uvm = new UserViewModel(user);
     this._disposables.Add(uvm);
     return uvm;
 }