package pt.isep.mei.simov.droneappcontroller;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import org.jivesoftware.smack.XMPPConnection;

import java.util.ArrayList;

/**
 * Created by almeida on 18-12-2014.
 */


public class ListOfDrones extends Activity {

    private XMPPConnection connection;

    private ListView listView ;
    private ArrayAdapter<String> listAdapter ;
    private ArrayList users;

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

        Bundle b = getIntent().getExtras();
        String user = b.getString("id");
        String passwd = b.getString("passwd");

        Connection c = new Connection(user,passwd);
        users = c.getUsers();
        connection = c.getConnection();


        listView = (ListView) findViewById( R.id.listOfDrones );
        listAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.simplerow);
        listView.setAdapter( listAdapter );

        for (int i = 0; i < users.size(); i++){
            listAdapter.add(users.get(i).toString());
        }

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i = new Intent(getApplicationContext(), ControllerActivity.class);
                i.putExtra("to", listAdapter.getItem(position));
                startActivity(i);
            }
        });
    }
}


