package edu.utexas.ee360p_teamproject;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.List;

import edu.utexas.ee360p_teamproject.ClientRequestHandler.RequestHandler;


public class ChatRoomActivity extends AppCompatActivity {

    private String myName;
    private int portNumber;
    private int messagesReceived;
    private Thread notificatonHandler;

    private List<String> chats = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_room);

        //Get the Intent that started this activity and extract the string
        Intent intent = getIntent();

        Bundle extras = intent.getExtras();
        //receive port number and name
        myName = extras.getString("EXTRA_USERNAME");
        messagesReceived = 0;

        /////TODO - check for new messages in bckgrnd (updateChatList(#)) ------ ASYNCH TASK?? 
            //sends messages received to server
            //waits for server to respond for new messages
            //display new messages
        notificatonHandler = new Thread(runnable);

        // listener for send messages
        final Button sendMessage = (Button) findViewById(R.id.sendMessage);
        sendMessage.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                EditText message = (EditText) findViewById(R.id.messageToSend);
                String msgString = message.getText().toString();

                MessageC toSend = new MessageC(myName, msgString, System.currentTimeMillis());
                String msg = toSend.toString();

                //sendMsg(MessageC.toTCPString) -- send message to middle man
                RequestHandler.sendMessage(new MessageC(myName, msg, System.currentTimeMillis()));

                //maybe TODO - update chatList

            }
        });

    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            while (true){
                //call function to get updates
                List<MessageC> notifications = RequestHandler.notifications(messagesReceived);

                //add new messages in a queue
                if((notifications == null) || notifications.isEmpty()){

                }
                else{

                }





            }
        }
    };

}

@@ -1499,81 +1499,18 @@
 ner(
-new View.OnClickListener()%7B%0A            public void onClick(View v)%7B%0A    
+view -%3E %7B%0A
     
@@ -1581,20 +1581,16 @@
 oSend);%0A
-    
         
@@ -1655,20 +1655,16 @@
         
-    
 MessageC
@@ -1697,280 +1697,184 @@
 ame,
- msgString, System.currentTimeMillis());%0A                String msg = toSend.toString();%0A%0A                //sendMsg(MessageC.toTCPString) -- send message to middle man%0A                RequestHandler.sendMessage(new MessageC(myName, msg, System.currentTimeMillis()));%0A%0A    
+%0A                                           msgString,%0A                                           System.currentTimeMillis());%0A            RequestHandler.sendMessage(toSend);%0A%0A
     
@@ -1913,30 +1913,16 @@
 atList%0A%0A
-            %7D%0A
         
@@ -2367,21 +2367,16 @@
       %7D%0A
-%0A%0A%0A%0A%0A
         

fix bug in sendMessage.onClickListener