package pt.isep.mei.simov.droneappcontroller;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

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

public class RegisterActivity extends Activity {

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

        final EditText username = (EditText)findViewById(R.id.editName);
        final EditText passwd = (EditText)findViewById(R.id.passwd);

        Button buttonReg = (Button) findViewById(R.id.btnReg);
        buttonReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Connection c = new Connection("admin","adminpassword"); //este user não existe, o registo não está a funcionar com esta conta.
                if (c.createAccount(username.getText().toString(), passwd.getText().toString())){
                    Toast.makeText(getApplicationContext(), "Registration completed!",
                            Toast.LENGTH_LONG).show();
                    finish();
                }else {
                    Toast.makeText(getApplicationContext(), "Problem with registration!",
                            Toast.LENGTH_LONG).show();
                }
            }
        });
        Button cancel = (Button)findViewById(R.id.buttonCancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
