public void Bind(ChatUserViewModel viewModel)
        {
            _viewModel = viewModel;

            _avatar.LoadImageWithTextPlaceholder(
                viewModel.PhotoUrl,
                viewModel.Username,
                StyleHelper.Style.ChatAvatarStyles,
                x => x.Transform(new CircleTransformation()));

            _textView.Text = viewModel.Username;

            _view.Clickable = _viewModel.IsActive;

            _inactiveOverlay.Visibility  = BoolToViewStateConverter.ConvertGone(!_viewModel.IsActive);
            _onlineStatusView.Visibility = BoolToViewStateConverter.ConvertGone(_viewModel.IsOnline);

            if (_checkboxImageView != null) // reused for few layouts
            {
                _checkboxImageView.Visibility = BoolToViewStateConverter.ConvertInvisible(_viewModel.IsSelectable);

                _selectedBinding?.Detach();
                _selectedBinding = this.SetBinding(() => _viewModel.IsSelected).WhenSourceChanges(() =>
                {
                    var resId = _viewModel.IsSelected ? StyleHelper.Style.CheckedIcon : StyleHelper.Style.UnCheckedIcon;
                    _checkboxImageView.SetImageResource(resId);
                });
            }
        }
Esempio n. 2
0
        protected override void DoAttachBindings()
        {
            base.DoAttachBindings();

            Bindings.Add(this.SetBinding(() => ViewModel.NoResultVisible).WhenSourceChanges(() =>
            {
                _searchNoResultView.Visibility = BoolToViewStateConverter.ConvertGone(ViewModel.NoResultVisible);
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.SearchQuery, () => _editText.Text, BindingMode.TwoWay));
            Bindings.Add(this.SetBinding(() => ViewModel.IsBusy, () => _busyOverlayView.Visibility)
                         .ConvertSourceToTarget(BoolToViewStateConverter.ConvertGone));

            _newGroupLayout.Click += NewGroupLayoutClick;
        }
        protected override void DoAttachBindings()
        {
            base.DoAttachBindings();

            Bindings.Add(this.SetBinding(() => ViewModel.ContactNameSearchQuery, () => _editText.Text, BindingMode.TwoWay));
            Bindings.Add(this.SetBinding(() => ViewModel.HasSelectedContacts).WhenSourceChanges(() =>
            {
                _addedMembers.Visibility = ViewModel.HasSelectedContacts
                    ? ViewStates.Visible
                    : ViewStates.Gone;
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.IsBusy).WhenSourceChanges(() =>
            {
                _busyOverlayView.Visibility = BoolToViewStateConverter.ConvertGone(ViewModel.IsBusy);
            }));
        }
Esempio n. 4
0
        public void BindViewModel(ChatMessageInputViewModel viewModel)
        {
            _viewModelRef = new WeakReferenceEx <ChatMessageInputViewModel>(viewModel);

            _bindings.Add(this.SetBinding(() => _viewModelRef.Target.MessageBody, () => _messageEditText.Text, BindingMode.TwoWay));
            _bindings.Add(this.SetBinding(() => _viewModelRef.Target.IsInEditMessageMode).WhenSourceChanges(() =>
            {
                if (_viewModelRef.Target.IsInEditMessageMode)
                {
                    _editingMessageBodyTextView.Text = _viewModelRef.Target.EditedMessageOriginalBody;

                    KeyboardService.ShowSoftKeyboard(_messageEditText);
                }
                else
                {
                    KeyboardService.HideSoftKeyboard(_messageEditText);
                }

                _editingMessageLayout.Visibility = BoolToViewStateConverter.ConvertGone(_viewModelRef.Target.IsInEditMessageMode);
            }));
            _bindings.Add(this.SetBinding(() => _viewModelRef.Target.ImageObject).WhenSourceChanges(() =>
            {
                if (_viewModelRef.Target.ImageObject == null)
                {
                    _imagePreview.SetImageBitmap(null);
                    _editImageContainer.Visibility = ViewStates.Gone;
                }
                else
                {
                    _imagePreview.SetImageBitmap((Android.Graphics.Bitmap)_viewModelRef.Target.ImageObject);
                    _editImageContainer.Visibility = ViewStates.Visible;
                }
            }));

            if (!_inited)
            {
                _messageEditText.Hint      = _viewModelRef.Target.EnterMessagePlaceholderString;
                _editingMessageHeader.Text = _viewModelRef.Target.EditMessageHeaderString;

                _takeAttachmentButton.SetCommand(_viewModelRef.Target.OpenCameraCommand);
                _addAttachmentButton.SetCommand(_viewModelRef.Target.OpenGalleryCommand);
                _sendButton.SetCommand(_viewModelRef.Target.SendMessageCommand);
                _removeImageButton.SetCommand(_viewModelRef.Target.DeleteImageCommand);
                _editingMessageCloseButton.SetCommand(_viewModelRef.Target.CancelEditingCommand);
                _inited = true;
            }
        }
 private void ScrollDownButtonVisibilityHandler(bool isVisible)
 {
     _isAutoScrollToFooterEnabled      = !isVisible;
     _scrollDownImageButton.Visibility = BoolToViewStateConverter.ConvertGone(isVisible);
 }
Esempio n. 6
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. 7
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;
                }
            }));
        }
        public override void BindViewModel(ChatMessageViewModel viewModel)
        {
            _viewModelRef = WeakReferenceEx.Create(viewModel);

            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.Body).WhenSourceChanges(() =>
            {
                // TODO: check
                Execute.OnUIThread(() =>
                {
                    var hideMessageBody            = string.IsNullOrEmpty(_viewModelRef.Target.Body) && _viewModelRef.Target.HasAttachment;
                    MessageBodyTextView.Visibility = BoolToViewStateConverter.ConvertGone(hideMessageBody == false);
                    MessageBodyTextView.Text       = _viewModelRef.Target.Body;
                });
            }));
            Bindings.Add(this.SetBinding(() => _viewModelRef.Target.TextDateTime).WhenSourceChanges(() =>
            {
                // TODO: check
                Execute.OnUIThread(() =>
                {
                    MessageDateTimeTextView.Text = _viewModelRef.Target.TextDateTime;
                });
            }));

            if (_viewModelRef.Target.HasAttachment)
            {
                var model = _viewModelRef.Target.Model;
                var expr  = default(TaskParameter);

                AttachmentImageView.SetImageResource(StyleHelper.Style.AttachmentImagePlaceholder);
                UpdateAttachmentImageViewSizeAndVisibility();

                if (!string.IsNullOrEmpty(model.ImageCacheKey))
                {
                    expr = ImageService.Instance.LoadFile(model.ImageCacheKey);
                }
                else if (!string.IsNullOrEmpty(model.ImageRemoteUrl))
                {
                    expr = ImageService.Instance.LoadUrl(model.ImageRemoteUrl);
                }

                if (expr == null)
                {
                    return;
                }

                _downloadAttachTask = expr.DownSampleInDip(90, 90)
                                      .Finish(x =>
                {
                    Execute.BeginOnUIThread(UpdateAttachmentImageViewSizeAndVisibility);
                });
                _downloadAttachTask.IntoAsync(AttachmentImageView);
            }
            else
            {
                _downloadAttachTask?.Dispose();
                AttachmentImageView.SetImageDrawable(null);
                AttachmentImageView.Visibility = ViewStates.Gone;
            }

            if (_isIncomingMessageViewType && SenderPhotoImageView != null)
            {
                SenderPhotoImageView.LoadImageWithTextPlaceholder(
                    _viewModelRef.Target.SenderPhotoUrl,
                    _viewModelRef.Target.SenderName,
                    new WhiteLabel.Droid.Controls.AvatarPlaceholderDrawable.AvatarStyles
                {
                    BackgroundHexColors = StyleHelper.Style.ChatAvatarStyles.BackgroundHexColors,
                    Size = new System.Drawing.Size(35, 35)
                },
                    x => x.Transform(new CircleTransformation()));
            }

            if (!_isIncomingMessageViewType && MessageStatusView != null)
            {
                Bindings.Add(this.SetBinding(() => _viewModelRef.Target.Status).WhenSourceChanges(() =>
                {
                    // TODO: check
                    Execute.OnUIThread(() =>
                    {
                        if (_viewModelRef.Target == null)
                        {
                            return;
                        }

                        ChangeMessageViewStatus(_viewModelRef.Target.Status);
                    });
                }));
            }
        }