Esempio n. 1
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable<long> initialBoundAccounts)
        {
            this._parent = parent;
            // get status model
            this.Model = status;
            this.RetweetedOriginalModel = status.RetweetedOriginal;

            // bind accounts 
            this._bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            this._favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.FavoritedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._favoritedUsers);
            this.CompositeDisposable.Add(
                this._favoritedUsers.ListenCollectionChanged()
                               .Subscribe(_ =>
                               {
                                   this.RaisePropertyChanged(() => this.IsFavorited);
                                   this.RaisePropertyChanged(() => this.IsFavoritedUserExists);
                                   this.RaisePropertyChanged(() => this.FavoriteCount);
                               }));
            this._retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.RetweetedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._retweetedUsers);
            this.CompositeDisposable.Add(
                this._retweetedUsers.ListenCollectionChanged()
                               .Subscribe(_ =>
                               {
                                   this.RaisePropertyChanged(() => this.IsRetweeted);
                                   this.RaisePropertyChanged(() => this.IsRetweetedUserExists);
                                   this.RaisePropertyChanged(() => this.RetweetCount);
                               }));
            if (this.RetweetedOriginalModel != null)
            {
                this.CompositeDisposable.Add(
                            this.RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged()
                                                  .Subscribe(_ => this.RaisePropertyChanged(() => this.IsFavorited)));
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged()
                                          .Subscribe(_ => this.RaisePropertyChanged(() => this.IsRetweeted)));
            }

            // listen settings
            this.CompositeDisposable.Add(
                new EventListener<Action<bool>>(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => CanFavorite)));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            // resolve images
            var imgsubj = this.Model.ImagesSubject;
            if (imgsubj != null)
            {
                lock (imgsubj)
                {
                    var subscribe = imgsubj
                        .Finally(() =>
                        {
                            this.RaisePropertyChanged(() => this.Images);
                            this.RaisePropertyChanged(() => this.FirstImage);
                            this.RaisePropertyChanged(() => this.IsImageAvailable);
                        })
                        .Subscribe();
                    this.CompositeDisposable.Add(subscribe);
                }
            }

            // look-up in-reply-to
            this._isInReplyToExists = this.Status.InReplyToStatusId.HasValue && this.Status.InReplyToStatusId != 0;
        }
Esempio n. 2
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable<long> initialBoundAccounts)
        {
            Interlocked.Increment(ref _instanceCount);
            this.CompositeDisposable.Add(() => Interlocked.Decrement(ref _instanceCount));
            this._parent = parent;
            // get status model
            this.Model = status;
            this.RetweetedOriginalModel = status.RetweetedOriginal;

            // bind accounts 
            this._bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            this._favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.FavoritedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._favoritedUsers);
            this.CompositeDisposable.Add(
                this._favoritedUsers.ListenCollectionChanged()
                               .Subscribe(_ =>
                               {
                                   this.RaisePropertyChanged(() => this.IsFavorited);
                                   this.RaisePropertyChanged(() => this.IsFavoritedUserExists);
                                   this.RaisePropertyChanged(() => this.FavoriteCount);
                               }));
            this._retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.RetweetedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._retweetedUsers);
            this.CompositeDisposable.Add(
                this._retweetedUsers.ListenCollectionChanged()
                               .Subscribe(_ =>
                               {
                                   this.RaisePropertyChanged(() => this.IsRetweeted);
                                   this.RaisePropertyChanged(() => this.IsRetweetedUserExists);
                                   this.RaisePropertyChanged(() => this.RetweetCount);
                               }));
            if (this.RetweetedOriginalModel != null)
            {
                this.CompositeDisposable.Add(
                            this.RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged()
                                                  .Subscribe(_ => this.RaisePropertyChanged(() => this.IsFavorited)));
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged()
                                          .Subscribe(_ => this.RaisePropertyChanged(() => this.IsRetweeted)));
            }

            // resolve images
            var imgsubj = this.Model.ImagesSubject;
            if (imgsubj != null)
            {
                lock (imgsubj)
                {
                    var subscribe = imgsubj
                        .Finally(() =>
                        {
                            this.RaisePropertyChanged(() => this.Images);
                            this.RaisePropertyChanged(() => this.FirstImage);
                            this.RaisePropertyChanged(() => this.IsImageAvailable);
                        })
                        .Subscribe();
                    this.CompositeDisposable.Add(subscribe);
                }
            }

            // look-up in-reply-to
            this._isInReplyToExists = this.Status.InReplyToStatusId.HasValue && this.Status.InReplyToStatusId != 0;
        }
Esempio n. 3
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable <long> initialBoundAccounts)
        {
            _parent = parent;
            // get status model
            Model = status;
            RetweetedStatusModel = status.RetweetedStatus;

            // bind accounts
            _bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            CompositeDisposable.Add(
                _favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.FavoritedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _favoritedUsers.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => IsFavorited);
                RaisePropertyChanged(() => IsFavoritedUserExists);
                RaisePropertyChanged(() => FavoriteCount);
            }));
            CompositeDisposable.Add(
                _retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.RetweetedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _retweetedUsers.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => IsRetweeted);
                RaisePropertyChanged(() => IsRetweetedUserExists);
                RaisePropertyChanged(() => RetweetCount);
            }));

            if (RetweetedStatusModel != null)
            {
                CompositeDisposable.Add(
                    RetweetedStatusModel.FavoritedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsFavorited)));
                CompositeDisposable.Add(
                    RetweetedStatusModel.RetweetedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsRetweeted)));
            }

            // listen settings
            CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => RaisePropertyChanged(() => CanFavorite)));
            CompositeDisposable.Add(
                new EventListener <Action <ThumbnailMode> >(
                    h => Setting.ThumbnailMode.ValueChanged += h,
                    h => Setting.ThumbnailMode.ValueChanged -= h,
                    _ =>
            {
                RaisePropertyChanged(() => IsThumbnailAvailable);
                RaisePropertyChanged(() => IsThumbnailsAvailable);
            }));
            CompositeDisposable.Add(
                new EventListener <Action <TweetDisplayMode> >(
                    h => Setting.TweetDisplayMode.ValueChanged += h,
                    h => Setting.TweetDisplayMode.ValueChanged -= h,
                    _ =>
            {
                RaisePropertyChanged(() => IsExpanded);
                RaisePropertyChanged(() => IsSingleLine);
            }));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            CompositeDisposable.Add(_images = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                        Model.Images, m => new ThumbnailImageViewModel(m), DispatcherHelper.UIDispatcher));
            // resolve images
            CompositeDisposable.Add(_images.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => ThumbnailImage);
                RaisePropertyChanged(() => IsImageAvailable);
                RaisePropertyChanged(() => IsThumbnailAvailable);
                RaisePropertyChanged(() => IsThumbnailsAvailable);
            }));

            // look-up in-reply-to
            _isInReplyToExists = Status.InReplyToStatusId.HasValue && Status.InReplyToStatusId != 0;
        }
Esempio n. 4
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable <long> initialBoundAccounts)
        {
            this._parent = parent;
            // get status model
            this.Model = status;
            this.RetweetedOriginalModel = status.RetweetedOriginal;

            // bind accounts
            this._bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            this._favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.FavoritedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._favoritedUsers);
            this.CompositeDisposable.Add(
                this._favoritedUsers.ListenCollectionChanged()
                .Subscribe(_ =>
            {
                this.RaisePropertyChanged(() => this.IsFavorited);
                this.RaisePropertyChanged(() => this.IsFavoritedUserExists);
                this.RaisePropertyChanged(() => this.FavoriteCount);
            }));
            this._retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.RetweetedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._retweetedUsers);
            this.CompositeDisposable.Add(
                this._retweetedUsers.ListenCollectionChanged()
                .Subscribe(_ =>
            {
                this.RaisePropertyChanged(() => this.IsRetweeted);
                this.RaisePropertyChanged(() => this.IsRetweetedUserExists);
                this.RaisePropertyChanged(() => this.RetweetCount);
            }));
            if (this.RetweetedOriginalModel != null)
            {
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged()
                    .Subscribe(_ => this.RaisePropertyChanged(() => this.IsFavorited)));
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged()
                    .Subscribe(_ => this.RaisePropertyChanged(() => this.IsRetweeted)));
            }

            // listen settings
            this.CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => CanFavorite)));
            this.CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.ShowThumbnails.ValueChanged += h,
                    h => Setting.ShowThumbnails.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => IsThumbnailAvailable)));
            this.CompositeDisposable.Add(
                new EventListener <Action <TweetDisplayMode> >(
                    h => Setting.TweetDisplayMode.ValueChanged += h,
                    h => Setting.TweetDisplayMode.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => IsExpanded)));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            // resolve images
            var imgsubj = this.Model.ImagesSubject;

            if (imgsubj != null)
            {
                lock (imgsubj)
                {
                    var subscribe = imgsubj
                                    .Finally(() =>
                    {
                        this.RaisePropertyChanged(() => this.Images);
                        this.RaisePropertyChanged(() => this.ThumbnailImage);
                        this.RaisePropertyChanged(() => this.IsImageAvailable);
                        this.RaisePropertyChanged(() => this.IsThumbnailAvailable);
                    })
                                    .Subscribe();
                    this.CompositeDisposable.Add(subscribe);
                }
            }

            // look-up in-reply-to
            this._isInReplyToExists = this.Status.InReplyToStatusId.HasValue && this.Status.InReplyToStatusId != 0;
        }
Esempio n. 5
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
            IEnumerable<long> initialBoundAccounts)
        {
            _parent = parent;
            // get status model
            Model = status;
            RetweetedOriginalModel = status.RetweetedOriginal;

            // bind accounts 
            _bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            CompositeDisposable.Add(
                _favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.FavoritedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _favoritedUsers.ListenCollectionChanged(_ =>
                {
                    RaisePropertyChanged(() => IsFavorited);
                    RaisePropertyChanged(() => IsFavoritedUserExists);
                    RaisePropertyChanged(() => FavoriteCount);
                }));
            CompositeDisposable.Add(
                _retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.RetweetedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _retweetedUsers.ListenCollectionChanged(_ =>
                    {
                        RaisePropertyChanged(() => IsRetweeted);
                        RaisePropertyChanged(() => IsRetweetedUserExists);
                        RaisePropertyChanged(() => RetweetCount);
                    }));

            if (RetweetedOriginalModel != null)
            {
                CompositeDisposable.Add(
                    RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsFavorited)));
                CompositeDisposable.Add(
                    RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsRetweeted)));
            }

            // listen settings
            CompositeDisposable.Add(
                new EventListener<Action<bool>>(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => RaisePropertyChanged(() => CanFavorite)));
            CompositeDisposable.Add(
                new EventListener<Action<ThumbnailMode>>(
                    h => Setting.ThumbnailMode.ValueChanged += h,
                    h => Setting.ThumbnailMode.ValueChanged -= h,
                    _ =>
                    {
                        RaisePropertyChanged(() => IsThumbnailAvailable);
                        RaisePropertyChanged(() => IsThumbnailsAvailable);
                    }));
            CompositeDisposable.Add(
                new EventListener<Action<TweetDisplayMode>>(
                    h => Setting.TweetDisplayMode.ValueChanged += h,
                    h => Setting.TweetDisplayMode.ValueChanged -= h,
                    _ =>
                    {
                        RaisePropertyChanged(() => IsExpanded);
                        RaisePropertyChanged(() => IsSingleLine);
                    }));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            CompositeDisposable.Add(_images = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                Model.Images, m => new ThumbnailImageViewModel(m), DispatcherHelper.UIDispatcher));
            // resolve images
            CompositeDisposable.Add(_images.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => ThumbnailImage);
                RaisePropertyChanged(() => IsImageAvailable);
                RaisePropertyChanged(() => IsThumbnailAvailable);
                RaisePropertyChanged(() => IsThumbnailsAvailable);
            }));

            // look-up in-reply-to
            _isInReplyToExists = Status.InReplyToStatusId.HasValue && Status.InReplyToStatusId != 0;
        }