package com.harryjamesuk.ribbit;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SignUpActivity extends Activity {
	
	protected EditText mUsername;
	protected EditText mPassword;
	protected EditText mEmail;
	protected Button mSignUpButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sign_up);
		
		mUsername = (EditText)findViewById(R.id.usernameField);
		mPassword = (EditText)findViewById(R.id.passwordField);
		mEmail = (EditText)findViewById(R.id.emailField);
		mSignUpButton = (Button)findViewById(R.id.signupButton);
		mSignUpButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String username = mUsername.getText().toString();
				String password = mPassword.getText().toString();
				String email = mEmail.getText().toString();
				
				username = username.trim();
				password = password.trim();
				email = email.trim();
				
				if (username.isEmpty() || password.isEmpty() || email.isEmpty()) {
					AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
					builder.setMessage(R.string.signup_error_message)
					.setTitle(R.string.signup_error_title)
					.setPositiveButton(android.R.string.ok, null);
					
					AlertDialog dialog = builder.create();
					dialog.show();
				}
				else {
					// Create the new user!
				}
				
			}
		});
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.sign_up, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

@@ -88,16 +88,47 @@
 Dialog;%0A
+import android.content.Intent;%0A
 import a
@@ -290,16 +290,111 @@
 tText;%0A%0A
+import com.parse.ParseException;%0Aimport com.parse.ParseUser;%0Aimport com.parse.SignUpCallback;%0A%0A
 public c
@@ -1725,16 +1725,897 @@
 w user!%0A
+%09%09%09%09%09ParseUser newUser = new ParseUser();%0A%09%09%09%09%09newUser.setUsername(username);%0A%09%09%09%09%09newUser.setPassword(password);%0A%09%09%09%09%09newUser.setEmail(email);%0A%09%09%09%09%09newUser.signUpInBackground(new SignUpCallback() %7B%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09@Override%0A%09%09%09%09%09%09public void done(ParseException e) %7B%0A%09%09%09%09%09%09%09if (e == null) %7B%0A%09%09%09%09%09%09%09%09// Success!%0A%09%09%09%09%09%09%09%09Intent intent = new Intent(SignUpActivity.this, MainActivity.class);%0A%09%09%09%09%09%09%09%09intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);%0A%09%09%09%09%09%09%09%09intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);%0A%09%09%09%09%09%09%09%09startActivity(intent);%0A%09%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09%09AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);%0A%09%09%09%09%09%09%09%09builder.setMessage(e.getMessage())%0A%09%09%09%09%09%09%09%09.setTitle(R.string.signup_error_title)%0A%09%09%09%09%09%09%09%09.setPositiveButton(android.R.string.ok, null);%0A%09%09%09%09%09%09%09%09%0A%09%09%09%09%09%09%09%09AlertDialog dialog = builder.create();%0A%09%09%09%09%09%09%09%09dialog.show();%0A%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D);%0A
 %09%09%09%09%7D%0A%09%09

Set up User Registration with Parse