package pt.isep.mei.simov.droneappcontroller;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

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

public class LoginActivity extends Activity {
    String email;
    String passwd;

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

    public void postData(View vw) {
        EditText edEmail = (EditText) findViewById(R.id.email);
        EditText edPasswd = (EditText) findViewById(R.id.passwd);

        email = edEmail.getText().toString();
        passwd = edPasswd.getText().toString();

        Log.i("XMPP", "Credencials: " + email + " and " + passwd);

        if (email.equals("") || passwd.equals("")) {
            Toast.makeText(this, "Por favor preencha os campos de autenticação",
                    Toast.LENGTH_LONG).show();
        } else {
            ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

            if (!(networkInfo != null && networkInfo.isConnected()))
            {
                Toast.makeText(getApplicationContext(), "Não existe conexão à internet. Por favor, ligue o acesso à internet", Toast.LENGTH_SHORT).show();
            } else{

                Intent i=new Intent(this,ListOfDrones.class);
                i.putExtra("id", email);
                i.putExtra("passwd", passwd);
                this.startActivity(i);
            }
        }
    }

    public void registerData (View vw) {
        Intent i = new Intent(this, RegisterActivity.class);
        startActivity(i);
    }
}