package com.rcarrillocruz.android.openstackdroid;

import android.app.Activity;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class ConnectionProfileActivity extends Activity {
	private Uri connectionProfileUri;
	
	private EditText mProfileName;
	private EditText mEndpoint;
	private EditText mUsername;
	private EditText mPassword;
	private EditText mTenantId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.connection_profile_activity);
		
		mProfileName = (EditText) findViewById(R.id.profile_name_edittext);
		mEndpoint = (EditText) findViewById(R.id.endpoint_edittext);
		mUsername = (EditText) findViewById(R.id.username_edittext);
		mPassword = (EditText) findViewById(R.id.password_edittext);
		mTenantId = (EditText) findViewById(R.id.tenant_id_edittext);
		
		connectionProfileUri = null;
	}

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.connection_profile_menu, menu);
        return true;
    }
    
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()) {
		case R.id.save_profile:
			saveConnectionProfile();
			return true;
		}
		
		return super.onOptionsItemSelected(item);
	}

	private void saveConnectionProfile() {
		// TODO Auto-generated method stub
		String profileName = (String) mProfileName.getText().toString();
		String endpoint = mEndpoint.getText().toString();
		String username = mUsername.getText().toString();
		String password = mPassword.getText().toString();
		String tenantId = mTenantId.getText().toString();
		
		ContentValues values = new ContentValues();
		values.put(ConnectionProfileTable.COLUMN_PROFILE_NAME, profileName);
		values.put(ConnectionProfileTable.COLUMN_ENDPOINT, endpoint);
		values.put(ConnectionProfileTable.COLUMN_USERNAME, username);
		values.put(ConnectionProfileTable.COLUMN_PASSWORD, password);
		values.put(ConnectionProfileTable.COLUMN_TENANT_ID, tenantId);
		
		connectionProfileUri = getContentResolver().insert(ConnectionProfileContentProvider.CONTENT_URI, values);
		
		finish();
	}
}

@@ -111,16 +111,48 @@
 Values;%0A
+import android.database.Cursor;%0A
 import a
@@ -1058,45 +1058,270 @@
 %09%0A%09%09
-connectionProfileUri = null;%0A%09%7D%0A%0A    
+Bundle extras = getIntent().getExtras();%0A%09%09%0A%09%09if (extras == null) %7B%0A%09%09%09connectionProfileUri = null;%09%09%09%0A%09%09%7D else %7B%0A%09%09%09connectionProfileUri = extras.getParcelable(ConnectionProfileContentProvider.CONTENT_ITEM_TYPE);%0A%09%09%09populateForm(connectionProfileUri);%0A%09%09%7D%0A%09%7D%0A%0A%09
 publ
@@ -2410,16 +2410,55 @@
 Id);%0A%09%09%0A
+%09%09if (connectionProfileUri == null) %7B%0A%09
 %09%09connec
@@ -2560,20 +2560,1315 @@
 es);
-%0A%09%09%0A%09%09finish
+%09%09%09%0A%09%09%7D else %7B%0A%09%09%09getContentResolver().update(connectionProfileUri, values, null, null);%0A%09%09%7D%0A%09%09%0A%09%09finish();%0A%09%7D%0A%0A    private void populateForm(Uri uri) %7B%0A%09%09// TODO Auto-generated method stub%0A    %09String%5B%5D projection = %7BConnectionProfileTable.COLUMN_PROFILE_NAME, ConnectionProfileTable.COLUMN_ENDPOINT, %0A    %09%09%09%09%09%09   ConnectionProfileTable.COLUMN_USERNAME, ConnectionProfileTable.COLUMN_PASSWORD,%0A    %09%09%09%09%09%09   ConnectionProfileTable.COLUMN_TENANT_ID%7D;%0A    %09%0A    %09Cursor cursor = getContentResolver().query(uri, projection, null, null, null);%0A    %09cursor.moveToFirst();%0A    %09%0A    %09String profileName = cursor.getString(cursor.getColumnIndex(ConnectionProfileTable.COLUMN_PROFILE_NAME));%0A    %09String endpoint = cursor.getString(cursor.getColumnIndex(ConnectionProfileTable.COLUMN_ENDPOINT));%0A    %09String username = cursor.getString(cursor.getColumnIndex(ConnectionProfileTable.COLUMN_USERNAME));%0A    %09String password = cursor.getString(cursor.getColumnIndex(ConnectionProfileTable.COLUMN_PASSWORD));%0A    %09String tenantId = cursor.getString(cursor.getColumnIndex(ConnectionProfileTable.COLUMN_TENANT_ID));%0A    %09%0A    %09mProfileName.setText(profileName);%0A    %09mEndpoint.setText(endpoint);%0A    %09mUsername.setText(username);%0A    %09mPassword.setText(password);%0A    %09mTenantId.setText(tenantId);%0A    %09%0A    %09cursor.close
 ();%0A

Add code for handling edit profile action and add a menu for save button