Got Producteev Login activity and signup working fully.

pull/14/head
Tim Su 14 years ago
parent 6784b38cb1
commit cb7afcea2c

@ -20,6 +20,7 @@
package com.todoroo.astrid.producteev; package com.todoroo.astrid.producteev;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -32,8 +33,12 @@ import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.producteev.api.ProducteevInvoker;
import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider;
import com.todoroo.astrid.utility.Preferences;
/** /**
* This activity allows users to sign in or log in to Producteev * This activity allows users to sign in or log in to Producteev
@ -56,6 +61,8 @@ public class ProducteevLoginActivity extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ContextManager.setContext(this);
setContentView(R.layout.producteev_login_activity); setContentView(R.layout.producteev_login_activity);
setTitle(R.string.producteev_PLA_title); setTitle(R.string.producteev_PLA_title);
@ -85,9 +92,13 @@ public class ProducteevLoginActivity extends Activity {
if(email.length() == 0 || password.length() == 0) { if(email.length() == 0 || password.length() == 0) {
errors.setVisibility(View.VISIBLE); errors.setVisibility(View.VISIBLE);
errors.setText(R.string.producteev_PLA_errorEmpty); errors.setText(R.string.producteev_PLA_errorEmpty);
return;
} }
performLogin(email.toString(), password.toString());
} }
} }
}); });
Button createNew = (Button) findViewById(R.id.createNew); Button createNew = (Button) findViewById(R.id.createNew);
@ -99,14 +110,108 @@ public class ProducteevLoginActivity extends Activity {
else { else {
Editable email = emailEditText.getText(); Editable email = emailEditText.getText();
Editable password = passwordEditText.getText(); Editable password = passwordEditText.getText();
if(email.length() == 0 || password.length() == 0) { Editable confirmPassword = ((EditText)findViewById(R.id.confirmPassword)).getText();
Editable firstName = ((EditText)findViewById(R.id.firstName)).getText();
Editable lastName = ((EditText)findViewById(R.id.lastName)).getText();
if(email.length() == 0 || password.length() == 0 ||
confirmPassword.length() == 0 || firstName.length() == 0 ||
lastName.length() == 0) {
errors.setVisibility(View.VISIBLE); errors.setVisibility(View.VISIBLE);
errors.setText(R.string.producteev_PLA_errorEmpty); errors.setText(R.string.producteev_PLA_errorEmpty);
return;
}
if(!confirmPassword.toString().equals(password.toString())) {
errors.setVisibility(View.VISIBLE);
errors.setText(R.string.producteev_PLA_errorMatch);
return;
}
performSignup(email.toString(), password.toString(),
firstName.toString(), lastName.toString());
}
}
});
}
private void performLogin(final String email, final String password) {
final ProgressDialog dialog = dialogUtilities.progressDialog(this,
getString(R.string.DLG_wait));
final TextView errors = (TextView) findViewById(R.id.error);
dialog.show();
new Thread() {
@Override
public void run() {
ProducteevInvoker invoker = ProducteevSyncProvider.getInvoker();
final StringBuilder errorMessage = new StringBuilder();
try {
invoker.authenticate(email, password);
Preferences.setString(R.string.producteev_PPr_email, email);
Preferences.setString(R.string.producteev_PPr_password, password);
ProducteevUtilities.INSTANCE.setToken(invoker.getToken());
synchronize();
} catch (Exception e) {
errorMessage.append(e.getMessage());
} finally {
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if(errorMessage.length() > 0) {
errors.setVisibility(View.VISIBLE);
errors.setText(errorMessage);
}
}
});
} }
// }
}.start();
}
private void performSignup(final String email, final String password,
final String firstName, final String lastName) {
final ProgressDialog dialog = dialogUtilities.progressDialog(this,
getString(R.string.DLG_wait));
final TextView errors = (TextView) findViewById(R.id.error);
dialog.show();
new Thread() {
@Override
public void run() {
ProducteevInvoker invoker = ProducteevSyncProvider.getInvoker();
final StringBuilder errorMessage = new StringBuilder();
try {
invoker.usersSignUp(email, firstName, lastName, password, null);
invoker.authenticate(email, password);
Preferences.setString(R.string.producteev_PPr_email, email);
Preferences.setString(R.string.producteev_PPr_password, password);
ProducteevUtilities.INSTANCE.setToken(invoker.getToken());
synchronize();
} catch (Exception e) {
errorMessage.append(e.getMessage());
} finally {
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if(errorMessage.length() > 0) {
errors.setVisibility(View.VISIBLE);
errors.setText(errorMessage);
} }
} }
}); });
}
}
}.start();
}
/**
* Perform synchronization
*/
protected void synchronize() {
startService(new Intent(ProducteevBackgroundService.SYNC_ACTION, null,
this, ProducteevBackgroundService.class));
finish();
} }
} }

@ -81,6 +81,21 @@ public class ProducteevInvoker {
} }
// --- users
/**
* Sign up as the given user
*/
public JSONObject usersSignUp(String email, String firstName, String lastName, String
password, Long fbUid) throws IOException, ApiServiceException {
return invokeGet("users/signup.json",
"email", email,
"firstname", firstName,
"lastname", lastName,
"password", password,
"fbuid", fbUid);
}
// --- tasks // --- tasks
/** /**

@ -87,7 +87,7 @@ public class ProducteevRestClient implements RestClient {
} }
int statusCode = response.getStatusLine().getStatusCode(); int statusCode = response.getStatusLine().getStatusCode();
if(statusCode != HTTP_OK) { if(statusCode != HTTP_OK || (body != null && body.startsWith("{\"error\":"))) { //$NON-NLS-1$
ApiServiceException error; ApiServiceException error;
try { try {
JSONObject errorObject = new JSONObject(body).getJSONObject("error"); //$NON-NLS-1$ JSONObject errorObject = new JSONObject(body).getJSONObject("error"); //$NON-NLS-1$

@ -145,10 +145,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
try { try {
String authToken = preferences.getToken(); String authToken = preferences.getToken();
invoker = getInvoker();
String z = stripslashes(0, "71o3346pr40o5o4nt4n7t6n287t4op28","2");
String v = stripslashes(2, "9641n76n9s1736q1578q1o1337q19233","4ae");
invoker = new ProducteevInvoker(z, v);
String email = Preferences.getStringValue(R.string.producteev_PPr_email); String email = Preferences.getStringValue(R.string.producteev_PPr_email);
String password = Preferences.getStringValue(R.string.producteev_PPr_password); String password = Preferences.getStringValue(R.string.producteev_PPr_password);
@ -183,6 +180,12 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
} }
} }
public static ProducteevInvoker getInvoker() {
String z = stripslashes(0, "71o3346pr40o5o4nt4n7t6n287t4op28","2");
String v = stripslashes(2, "9641n76n9s1736q1578q1o1337q19233","4ae");
return new ProducteevInvoker(z, v);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// ----------------------------------------------------- synchronization! // ----------------------------------------------------- synchronization!
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

Loading…
Cancel
Save