Exemple #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            CustomNavigationBar.TintColor = StyleHelper.Style.AccentColor;
            if (StyleHelper.Style.UseLogoInsteadOfConnectionStatus)
            {
                var titleImage = new UIImageView
                {
                    Image = UIImage.FromBundle(StyleHelper.Style.LogoBoundleName)
                };
                CustomNavigationItem.AddTitleView(titleImage);
            }
            else
            {
                _customTitleView = new ConnectionStatusView(CGRect.Empty);
                CustomNavigationItem.AddTitleView(_customTitleView);
            }
            CustomNavigationItem.SetCommand(UIBarButtonSystemItem.Add, ViewModel.CreateChatCommand, false);

            ChatsTableView.RegisterNibForCellReuse(ChatSummaryViewCell.Nib, ChatSummaryViewCell.Key);
            ChatsTableView.RowHeight       = 80;
            ChatsTableView.TableFooterView = new UIView();

            var source = ViewModel.Chats.GetTableViewSource((cell, viewModel, index) =>
            {
                (cell as ChatSummaryViewCell).BindViewModel(viewModel);
            }, ChatSummaryViewCell.Key);

            ChatsTableView.Source   = source;
            ChatsTableView.Delegate = new CustomViewDelegate(source, ViewModel);
            _sourceRef = WeakReferenceEx.Create(source);
        }
 private void InitNavigationBar()
 {
     CustomNavigationItem.Title = ViewModel.LocalizedStrings.DetailsTitle;
     CustomNavigationItem.SetCommand(
         UIImage.FromBundle(StyleHelper.Style.BackButtonBundleName),
         ViewModel.BackCommand,
         true);
 }
 private void InitNavigationBar()
 {
     CustomNavigationItem.Title = ViewModel.LocalizedStrings.CreateGroup;
     CustomNavigationItem.SetCommand(
         UIImage.FromBundle(StyleHelper.Style.BackButtonBundleName),
         ViewModel.BackCommand,
         true);
     CustomNavigationItem.SetCommand(
         ViewModel.LocalizedStrings.Create,
         StyleHelper.Style.AccentColor,
         new RelayCommand(AddChat),
         false);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _customTitleView = new ConnectionStatusView(CGRect.Empty);

            TableNode = new ASTableNode(UITableViewStyle.Grouped);
            Table     = TableNode.View;

            Input = new ChatInputView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            Input.Init(this);

            CustomNavigationItem.AddTitleView(_customTitleView);
            CustomNavigationItem.SetCommand(
                UIImage.FromBundle(StyleHelper.Style.BackButtonBundleName),
                ViewModel.BackCommand,
                true);

            if (ViewModel.HasInfo)
            {
                CustomNavigationItem.SetCommand(
                    UIImage.FromBundle(StyleHelper.Style.ChatDetailsButtonBundleName),
                    ViewModel.ShowInfoCommand,
                    false);
            }

            MainView.InsertSubview(Table, 1);
            InitTableView();

            _contextMenuHandler = new ContextMenuHandler <ChatMessageViewModel>(CreateContextMenuComponentForViewModel);

            Input.EditingCloseButton.SetCommand(ViewModel.MessageInput.CancelEditingCommand);
            Input.OpenCameraButton.SetCommand(ViewModel.MessageInput.OpenCameraCommand);
            Input.OpenGalleryButton.SetCommand(ViewModel.MessageInput.OpenGalleryCommand);
            Input.SendButton.SetCommand(ViewModel.MessageInput.SendMessageCommand);
            Input.DeleteButton.SetCommand(ViewModel.MessageInput.DeleteImageCommand);
            Input.SetLabels(
                ViewModel.MessageInput.EditMessageHeaderString,
                ViewModel.MessageInput.EnterMessagePlaceholderString);

            ScrollToBottomButton.SetCommand(new RelayCommand(() => ScrollToBottom(true)));
            ScrollToBottomButton.SetBackgroundImage(UIImage.FromBundle(StyleHelper.Style.ScrollDownBoundleName), UIControlState.Normal);
        }
        protected override void DoAttachBindings()
        {
            base.DoAttachBindings();

            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.AvatarUrl).WhenSourceChanges(() =>
            {
                _chatDetailsHeaderView.SetChatAvatar(ViewModel.HeaderViewModel.AvatarUrl, ViewModel.HeaderViewModel.ChatName);
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.ChatName, () => _chatDetailsHeaderView.ChatNameField.Text, BindingMode.TwoWay));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.ChatName).WhenSourceChanges(() =>
            {
                var chatName = ViewModel.HeaderViewModel.ChatName;
                if (!string.IsNullOrEmpty(chatName) && !ViewModel.CanEdit)
                {
                    _chatDetailsHeaderView.ChatNameTextView.Text = chatName;
                    _chatDetailsHeaderView.ChatNameTextView.EnableAutoScroll();
                }
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.IsMuted, () => _chatDetailsHeaderView.IsNotificationsMuted));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.IsBusy, () => _chatDetailsHeaderView.IsMuteNotificationsAvailable)
                         .ConvertSourceToTarget(x => !x));

            Bindings.Add(this.SetBinding(() => ViewModel.MembersCountText, () => _chatDetailsHeaderView.ChatMembersCount));
            Bindings.Add(this.SetBinding(() => _simpleImagePicker.ViewModel.ImageCacheKey).WhenSourceChanges(() =>
            {
                var newImageCacheKey = _simpleImagePicker.ViewModel.ImageCacheKey;

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

                _previewImageKey = newImageCacheKey;

                _chatDetailsHeaderView.SetEditedChatAvatar(_previewImageKey);

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

            Bindings.Add(this.SetBinding(() => ViewModel.IsLoading).WhenSourceChanges(() =>
            {
                if (ViewModel.IsLoading)
                {
                    BusyIndicator.StartAnimating();
                }
                else
                {
                    BusyIndicator.StopAnimating();
                }
                _chatDetailsHeaderView.MembersCountLabelHidden = ViewModel.IsLoading;
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.CanEdit).WhenSourceChanges(() =>
            {
                _chatDetailsHeaderView.HideChangeChatPhoto(!ViewModel.CanEdit);
                _chatDetailsHeaderView.EnableEditMode(ViewModel.CanEdit);

                if (!ViewModel.CanEdit)
                {
                    _chatDetailsHeaderView.Frame = new CGRect(0, 0, 200, 260);

                    return;
                }

                if (!_isChangeChatPhotoInitialized)
                {
                    _chatDetailsHeaderView.SetChangeChatPhotoCommand(new RelayCommand(OpenPicker), ViewModel.LocalizedStrings.ChangePhoto);
                    _chatDetailsHeaderView.SetChangeChatName(ViewModel.HeaderViewModel.StartEditingCommand);

                    _isChangeChatPhotoInitialized = true;
                }
            }));
            Bindings.Add(this.SetBinding(() => ViewModel.HeaderViewModel.IsInEditMode).WhenSourceChanges(() =>
            {
                if (ViewModel.HeaderViewModel.IsInEditMode)
                {
                    CustomNavigationItem.SetCommand(ViewModel.LocalizedStrings.Save, UIColor.Black, new RelayCommand(Save), false);
                }
                else
                {
                    CustomNavigationItem.SetRightBarButtonItem(null, true);

                    _chatDetailsHeaderView.EndEditing();
                }
            }));
        }