예제 #1
0
        private void ConnectMethod()
        {
            if (InputName.Text == "")
            {
                MessageBox.Show("Incorrect data!");
                ConnectButton.Enabled = true;
                return;
            }
            else
            {
                this.FormBorderStyle       = FormBorderStyle.Sizable;
                this.ControlBox            = true;
                this.Text                  = InputName.Text;
                this.AllABonents.Enabled   = true;
                this.InputMessage.Enabled  = true;
                this.SendButton.Enabled    = true;
                this.OutputMessage.Enabled = true;
                this.ConnectButton.Text    = "Disconnect";
                this.InputName.ReadOnly    = true;

                client      = new ServerClient(new InstanceContext(this));
                userName    = InputName.Text;
                id          = client.Connect(InputName.Text);
                isConnected = true;
                nameInList  = userName + " — Online";
                client.ProvideMessage(id);

                //if (AllABonents.Items.Contains(InputName.Text + " — Offline"))
                //    AllABonents.Items[id] = nameInList;
                //else
                //    AllABonents.Items.Add(nameInList);
                this.ActiveControl = InputMessage;
                InputMessage.Focus();
            }
        }
        private void UsernameHint_OnTap(object sender, GestureEventArgs e)
        {
            InputMessage.Focus();

            var frameworkElement = sender as FrameworkElement;

            if (frameworkElement != null)
            {
                var user = frameworkElement.DataContext as IUserName;
                if (user != null)
                {
                    var index = 0;
                    for (var i = InputMessage.Text.Length - 1; i >= 0; i--)
                    {
                        if (InputMessage.Text[i] == '@')
                        {
                            index = i;
                            break;
                        }
                    }

                    InputMessage.Text            = string.Format("{0}{1} ", InputMessage.Text.Substring(0, index + 1), user.UserName);
                    InputMessage.SelectionStart  = InputMessage.Text.Length;
                    InputMessage.SelectionLength = 0;
                }
            }
        }
 private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (Property.NameEquals(e.PropertyName, () => ViewModel.ScrollToBottomVisibility))
     {
         if (ViewModel.ScrollToBottomVisibility == Visibility.Visible)
         {
             //ShowScrollToBottomButton();
         }
         else
         {
             //HideScrollToBottomButton();
         }
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.Reply))
     {
         if (ViewModel.Reply != null)
         {
             if (ViewModel.Reply is TLMessagesContainter)
             {
             }
             else
             {
                 InputMessage.Focus();
             }
         }
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.IsSelectionEnabled))
     {
         if (ViewModel.IsSelectionEnabled)
         {
             SwitchToSelectionMode();
         }
         else
         {
             SwitchToNormalMode();
         }
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.ChooseAttachment) &&
              ViewModel.ChooseAttachment != null)
     {
         ViewModel.ChooseAttachment.PropertyChanged += OnChooseAttachmentPropertyChanged;
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.ImageViewer) &&
              ViewModel.ImageViewer != null)
     {
         ViewModel.ImageViewer.PropertyChanged += OnImageViewerPropertyChanged;
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.ImageEditor) &&
              ViewModel.ImageEditor != null)
     {
         ViewModel.ImageEditor.PropertyChanged += OnImageEditorPropertyChanged;
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.With))
     {
         ApplicationBar.IsVisible = !ViewModel.IsChatForbidden && !ViewModel.IsChooseAttachmentOpen;
     }
     else if (Property.NameEquals(e.PropertyName, () => ViewModel.CanSend))
     {
         _sendButton.IsEnabled = ViewModel.CanSend;
     }
 }
        public DialogDetailsView()
        {
            InitializeComponent();

            AnimationContext = LayoutRoot;

            _sendButton.Click   += (sender, args) => ViewModel.Send();
            _attachButton.Click += (sender, args) =>
            {
                EmojiPlaceholder.Visibility = Visibility.Collapsed;
                //DialogPhoto.Visibility = Visibility.Visible;
                //Title.Visibility = Visibility.Visible;

                ChooseAttachment.Focus();
                ViewModel.Attach();
            };
            _smileButton.Click += (sender, args) =>
            {
                if (_emojiKeyboard == null)
                {
                    _emojiKeyboard = EmojiControl.GetInstance();

                    _emojiKeyboard.BindTextBox(InputMessage);
                    EmojiPlaceholder.Content = _emojiKeyboard;
                    _emojiKeyboard.IsOpen    = true;
                }

                if (EmojiPlaceholder.Visibility == Visibility.Visible)
                {
                    if (InputMessage == FocusManager.GetFocusedElement())
                    {
                        _smileButtonPressed = true;

                        EmojiPlaceholder.Opacity = 1.0;
                        EmojiPlaceholder.Height  = EmojiControl.PortraitOrientationHeight;
                        Items.Focus();
                    }
                    else
                    {
                        EmojiPlaceholder.Visibility = Visibility.Collapsed;
                        //DialogPhoto.Visibility = Visibility.Visible;
                        //Title.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    var awaitKeyboardDown = false;
                    if (InputMessage == FocusManager.GetFocusedElement())
                    {
                        awaitKeyboardDown = true;
                        Items.Focus();
                    }

                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        if (awaitKeyboardDown)
                        {
                            Thread.Sleep(400);
                        }
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            EmojiPlaceholder.Opacity    = 1.0;
                            EmojiPlaceholder.Visibility = Visibility.Visible;
                            //DialogPhoto.Visibility = Visibility.Collapsed;
                            //Title.Visibility = Visibility.Collapsed;
                        });
                    });
                }
            };
            _manageButton.Click  += (sender, args) => SwitchToSelectionMode();
            _forwardButton.Click += (sender, args) =>
            {
                var selectedItems = ViewModel.Items.Where(x => x.Id != null && x.IsSelected).ToList();
                if (selectedItems.Count == 0)
                {
                    return;
                }

                ViewModel.IsSelectionEnabled = false;

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    try
                    {
                        if (Items.Visibility == Visibility.Visible)
                        {
                            var writeableBitmap   = new WriteableBitmap(Items, null);
                            ViewModel.With.Bitmap = writeableBitmap;
                        }
                    }
                    catch (Exception ex)
                    {
                        Telegram.Api.Helpers.Execute.ShowDebugMessage("WritableBitmap exception " + ex);
                    }

                    ViewModel.ForwardMessages(selectedItems);
                });
            };
            _deleteButton.Click += (sender, args) => ViewModel.DeleteMessages();

            Loaded += (sender, args) =>
            {
                SetRootFrameBinding();

                if (!ViewModel.StateService.IsEmptyBackground)
                {
                    var color = Colors.White;
                    color.A = 254;
                    SystemTray.ForegroundColor = color;
                }

                if (ViewModel.StateService.CurrentBackground != null)
                {
                    var color = Colors.White;
                    color.A = 254;
                    SystemTray.ForegroundColor = color;
                }

                if (ViewModel.With is TLBroadcastChat)
                {
                    _forwardButton.IsEnabled = false;
                }

                ThreadPool.QueueUserWorkItem(state =>
                {
                    Thread.Sleep(300);

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (ViewModel.StateService.FocusOnInputMessage)
                        {
                            ViewModel.StateService.FocusOnInputMessage = false;
                            InputMessage.Focus();
                        }
                    });
                });
                if (ViewModel.ChooseAttachment != null)
                {
                    ViewModel.ChooseAttachment.PropertyChanged += OnChooseAttachmentPropertyChanged;
                }
                if (ViewModel.ImageViewer != null)
                {
                    ViewModel.ImageViewer.PropertyChanged += OnImageViewerPropertyChanged;
                }
                if (ViewModel.ImageEditor != null)
                {
                    ViewModel.ImageEditor.PropertyChanged += OnImageEditorPropertyChanged;
                }
                ViewModel.PropertyChanged += OnViewModelPropertyChanged;
                ViewModel.ScrollToBottom  += OnViewModelScrollToBottom;

                BuildLocalizedAppBar();
                //MessageBox.Show("Time: " + timer.Elapsed);
            };

            Unloaded += (sender, args) =>
            {
                RemoveRootFrameBinding();

                if (ViewModel.ChooseAttachment != null)
                {
                    ViewModel.ChooseAttachment.PropertyChanged -= OnChooseAttachmentPropertyChanged;
                }
                if (ViewModel.ImageViewer != null)
                {
                    ViewModel.ImageViewer.PropertyChanged -= OnImageViewerPropertyChanged;
                }
                if (ViewModel.ImageEditor != null)
                {
                    ViewModel.ImageEditor.PropertyChanged -= OnImageEditorPropertyChanged;
                }
                ViewModel.ScrollToBottom  -= OnViewModelScrollToBottom;
                ViewModel.PropertyChanged -= OnViewModelPropertyChanged;
            };
        }