示例#1
0
        private void SendMessage()
        {
            string content = this.MessageText.Text;

            if (!String.IsNullOrWhiteSpace(content))
            {
                if (_isSendingMessage)
                {
                    return;
                }

                _isSendingMessage = true;

                // Add message to the message list
                Message message = new Message {
                    Sender = null, Content = content, SendDate = DateTime.MinValue
                };
                _source.AddItem(message);
                this.MessageList.ReloadData();
                this.MessageList.ScrollToRow(
                    NSIndexPath.FromItemSection((nint)(_source.Count - 1), 0),
                    UITableViewScrollPosition.Bottom,
                    false);

                _cts1 = new CancellationTokenSource();
                AppController.SendMessage(_cts1,
                                          _email,
                                          content,
                                          (data) =>
                {
                    message.MessageId = data.MessageId;
                    message.SendDate  = data.SendDate.GetValueOrDefault();
                    this.MessageList.ReloadData();
                },
                                          (error) =>
                {
                    message.SendDate = DateTime.MaxValue;
                    this.MessageList.ReloadData();

                    UIToast.MakeText(error, UIToastLength.Long).Show();
                },
                                          () =>
                {
                    _isSendingMessage = false;
                });

                // Ready to send new message
                this.MessageText.Text = String.Empty;
                AdjustMessageTextHeight();
            }
        }
示例#2
0
        private void SendMessage()
        {
            string content = this.MessageText.Text;

            if (!String.IsNullOrWhiteSpace(content))
            {
                if (_isSendingMessage)
                {
                    return;
                }

                _isSendingMessage = true;

                // Add message to the message list
                Message message = new Message {
                    Sender = null, Content = content, SendDate = DateTime.MinValue
                };
                _adapter.AddItem(message);
                this.MessageList.ReloadData();
                this.MessageList.SmoothScrollToPosition(_adapter.ItemCount);

                _cts1 = new CancellationTokenSource();
                AppController.SendMessage(_cts1,
                                          _email,
                                          content,
                                          (data) =>
                {
                    message.MessageId = data.MessageId;
                    message.SendDate  = data.SendDate.GetValueOrDefault();
                    this.MessageList.ReloadData();
                },
                                          (error) =>
                {
                    message.SendDate = DateTime.MaxValue;
                    this.MessageList.ReloadData();

                    Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                },
                                          () =>
                {
                    _isSendingMessage = false;
                });

                // Ready to send new message
                this.MessageText.Text = String.Empty;
            }
        }