Esempio n. 1
0
        protected override void DoAttachBindings()
        {
            base.DoAttachBindings();

            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.ChatName, () => _chatNameEditText.Text, BindingMode.TwoWay));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.ChatName, () => _chatNameText.Text));
            Bindings.Add(this.SetBinding(() => ViewModel.MembersCountText, () => _chatMembersCountTextView.Text));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.AvatarUrl).WhenSourceChanges(() =>
            {
                Execute.BeginOnUIThread(() =>
                {
                    _chatPhotoImageView.LoadImageWithTextPlaceholder(
                        ViewModel.HeaderViewModel.AvatarUrl,
                        ViewModel.HeaderViewModel.ChatName,
                        new AvatarPlaceholderDrawable.AvatarStyles
                    {
                        BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
                        Size = new System.Drawing.Size(64, 64)
                    },
                        x => x.Transform(new CircleTransformation()));
                });
            }));
            Bindings.Add(this.SetBinding(() => _imagePicker.ViewModel.ImageCacheKey).WhenSourceChanges(() =>
            {
                var newImageCacheKey = _imagePicker.ViewModel.ImageCacheKey;

                if (string.IsNullOrEmpty(newImageCacheKey) || newImageCacheKey == _previewImageKey)
                {
                    return;
                }

                _previewImageKey = newImageCacheKey;

                Execute.BeginOnUIThread(() =>
                {
                    ViewModel.HeaderViewModel.StartEditingCommand.Execute(null);
                });

                ImageService.Instance
                .LoadFile(_previewImageKey)
                .DownSampleInDip(95, 95)
                .Transform(new CircleTransformation())
                .IntoAsync(_chatEditedPhotoImageView);
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.IsMuted, () => _muteNotificationsSwitch.Checked)
                         .ConvertSourceToTarget(x => !x));
            Bindings.Add(this.SetBinding(() => ViewModel.IsBusy, () => _muteNotificationsSwitch.Clickable)
                         .ConvertSourceToTarget(x => !x));
            Bindings.Add(this.SetBinding(() => ViewModel.IsLoading).WhenSourceChanges(() =>
            {
                _busyOverlayView.Visibility          = BoolToViewStateConverter.ConvertGone(ViewModel.IsLoading);
                _chatMembersCountTextView.Visibility = BoolToViewStateConverter.ConvertGone(!ViewModel.IsLoading);
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.CanEdit, BindingMode.OneTime).WhenSourceChanges(() =>
            {
                if (ViewModel.CanEdit)
                {
                    _changeChatPhotoButton.Visibility = ViewStates.Visible;

                    _chatNameEditText.Visibility = ViewStates.Visible;
                    _chatNameText.Visibility     = ViewStates.Gone;
                }
                else
                {
                    _changeChatPhotoButton.Visibility = ViewStates.Gone;

                    _chatNameEditText.Visibility = ViewStates.Gone;
                    _chatNameText.Visibility     = ViewStates.Visible;

                    _chatNameText.Selected = true;
                }
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.IsInEditMode).WhenSourceChanges(() =>
            {
                if (ViewModel.HeaderViewModel.IsInEditMode)
                {
                    _navigationBarView.RightTextButton.Visibility = ViewStates.Visible;
                    _chatEditedPhotoImageView.Visibility          = ViewStates.Visible;
                }
                else
                {
                    _previewImageKey = null;
                    _navigationBarView.RightTextButton.Visibility = ViewStates.Gone;

                    _chatNameEditText.ClearFocus();
                    _chatNameEditText.ClearComposingText();

                    KeyboardService.HideSoftKeyboard(_chatNameEditText);
                }
            }));

            _chatNameEditText.FocusChange += OnEditTextFocusChanged;
            _addMemberContainer.Click     += OnAddMemberClick;
        }
Esempio n. 2
0
        public override void BindViewModel(ChatSummaryViewModel viewModel)
        {
            _viewModelRef = WeakReferenceEx.Create(viewModel);

            _messageBodyPhotoLabel.Text = viewModel.LocalizedStrings.Photo;
            _messageBodyPhotoImageView.SetImageResource(StyleHelper.Style.LastMessageBodyPhotoIcon);

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.ChatName, () => _chatNameTextView.Text));
            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.LastMessageViewModel.Username, () => _userNameTextView.Text));
            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.LastMessageViewModel.Body).WhenSourceChanges(() =>
            {
                _messageBodyTextView.Text       = _viewModelRef.Target.LastMessageViewModel.Body;
                _messageBodyTextView.Visibility = BoolToViewStateConverter.ConvertGone(_viewModelRef.Target.LastMessageViewModel.HasBody);
            }));
            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.LastMessageViewModel.DateTime, () => _dateTimeTextView.Text));

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.ChatPhotoUrl).WhenSourceChanges(() =>
            {
                if (_chatPhotoImageView == null)
                {
                    return;
                }

                _chatPhotoImageView.LoadImageWithTextPlaceholder(
                    _viewModelRef.Target.ChatPhotoUrl,
                    _viewModelRef.Target.ChatName,
                    new AvatarPlaceholderDrawable.AvatarStyles
                {
                    BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
                    Size = new System.Drawing.Size(44, 44)
                },
                    x => x.Transform(new CircleTransformation()));
            }));

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.UnreadMessageCount).WhenSourceChanges(() =>
            {
                if (_unreadMessageCountTextView != null)
                {
                    _unreadMessageCountTextView.Text       = _viewModelRef.Target.UnreadMessageCount.ToString();
                    _unreadMessageCountTextView.Visibility = BoolToViewStateConverter.ConvertGone(_viewModelRef.Target.UnreadMessageCount > 0);
                }
            }));

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.IsMuted).WhenSourceChanges(() =>
            {
                if (_unreadMessageCountTextView != null)
                {
                    var colorResId = _viewModelRef.Target.IsMuted
                        ? StyleHelper.Style.UnreadMutedMessagesCountColor
                        : StyleHelper.Style.UnreadMessagesCountColor;

                    var color = ContextCompat.GetColor(_unreadMessageCountTextView.Context, colorResId);

                    _unreadMessageCountTextView.Background = CreateBackgroundWithCornerRadius(color, 56f);
                }
            }));

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.LastMessageViewModel.Status).WhenSourceChanges(() =>
            {
                Color color;

                switch (_viewModelRef.Target.LastMessageViewModel.Status)
                {
                case ChatMessageStatus.Read:
                    color = Color.GreenYellow;
                    break;

                case ChatMessageStatus.Other:
                    color = Color.Transparent;
                    break;

                default:
                    color = Color.ParseColor(ChatStatusDefaultColor);
                    break;
                }

                _messageStatusIndicatorView?.SetBackgroundColor(color);
            }));

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.LastMessageViewModel.HasPhoto).WhenSourceChanges(() =>
            {
                if (!_viewModelRef.Target.LastMessageViewModel.HasBody && _viewModelRef.Target.LastMessageViewModel.HasPhoto)
                {
                    _messageBodyTextView.Visibility  = ViewStates.Gone;
                    _messageBodyPhotoView.Visibility = ViewStates.Visible;
                }
                else
                {
                    _messageBodyTextView.Visibility  = BoolToViewStateConverter.ConvertGone(_viewModelRef.Target.LastMessageViewModel.HasBody);
                    _messageBodyPhotoView.Visibility = ViewStates.Gone;
                }
            }));
        }