Пример #1
0
        /// <summary>
        /// Button handler
        /// </summary>
        /// <param name="sender">The object that invoked the event</param>
        /// <param name="e">The event arguments</param>
        async void MSendMessage_Click(object sender, EventArgs e)
        {
            //Try to send the message
            if (await MessageSender.SendGroupMessage(mMessage.Text, MainActivity.credentials, MainActivity.serverURL + MainActivity.group_message))
            {
                //If the message was successful, save it to the device
                Message m = new Message();

                m.Date     = DateTime.Now.ToString();
                m.UserName = "******";
                m.MsgText  = mMessage.Text;
                m.incoming = false;

                MessageRepository.SaveMessage(m);

                //Clear the text field
                mMessage.Text = "";

                Toast.MakeText(this, "Message Sent!", ToastLength.Short).Show();
            }
            else
            {
                Toast.MakeText(this, "Message Failed!", ToastLength.Short).Show();
            }
        }
Пример #2
0
        /// <summary>
        /// Open the conversation window
        /// </summary>
        /// <param name="position">The position of the user in the list of usernames that the conversation is with</param>
        public void viewConversation(int position)
        {
            //Get the elements on the screen
            SetContentView(Resource.Layout.messaging);
            Button   mButton = FindViewById <Button>(Resource.Id.btnSendMsg);
            EditText mText   = FindViewById <EditText>(Resource.Id.sendMessageTxt);

            taskListView = (ListView)FindViewById(Resource.Id.listView);

            //Get the messages in the conversation
            msgs = MessageRepository.GetUsersMessage(new string[] { users[position] }).ToList();

            //Set the adapter to use messages
            taskList             = new MsgListAdapter(this, msgs);
            taskListView.Adapter = taskList;

            //When the send button is clicked
            mButton.Click += async(object sender, EventArgs e) =>
            {
                if (!mText.Text.Equals(""))
                {
                    //If the message is sent successfully, store it and display it in the list
                    if (await MessageSender.SendSingleMessage(mText.Text, users[position], MainActivity.credentials, MainActivity.serverURL + MainActivity.single_message))
                    {
                        //Create a message object
                        Message m = new Message();
                        m.MsgText  = mText.Text;
                        m.UserName = users[position];
                        m.Date     = DateTime.Now.ToString();
                        m.incoming = false;

                        //Update the message on the screen
                        newMessage(m);

                        //Save the message
                        MessageRepository.SaveMessage(m);

                        //Clear the input box
                        mText.Text = "";
                    }
                    else
                    {
                        Toast.MakeText(this, "Sending message was unsuccessful", ToastLength.Short).Show();
                    }
                }
            };
        }
Пример #3
0
        /// <summary>
        /// On send message click, this will retrieve the data inputed by the user
        /// and attempt to send a message via MessageSender. User will be notified
        /// if the message was sent successfully or not.
        /// </summary>
        /// <param name="sender">The object that invoked the event</param>
        /// <param name="e">The event arguments</param>
        async void MSendMessage_Click(object sender, EventArgs e)
        {
            //Try to send a message to another user
            if (await MessageSender.SendSingleMessage(mMessage.Text, userSelected, MainActivity.credentials, URLs.serverURL + URLs.single_message))
            {
                //Create a message object to store on the device
                Message m = new Message();
                m.Date     = System.DateTime.Now.ToString();
                m.UserName = userSelected;
                m.MsgText  = mMessage.Text;
                m.incoming = false;
                MessageRepository.SaveMessage(m);

                //Clear the input box
                mMessage.Text = "";
                Toast.MakeText(this, "Message Sent!", ToastLength.Short).Show();
            }
            else
            {
                Toast.MakeText(this, "Message Failed!", ToastLength.Short).Show();
            }
        }