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;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -32,8 +33,12 @@ import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
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
@ -56,6 +61,8 @@ public class ProducteevLoginActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContextManager.setContext(this);
setContentView(R.layout.producteev_login_activity);
setTitle(R.string.producteev_PLA_title);
@ -85,9 +92,13 @@ public class ProducteevLoginActivity extends Activity {
if(email.length() == 0 || password.length() == 0) {
errors.setVisibility(View.VISIBLE);
errors.setText(R.string.producteev_PLA_errorEmpty);
return;
}
performLogin(email.toString(), password.toString());
}
}
});
Button createNew = (Button) findViewById(R.id.createNew);
@ -99,14 +110,108 @@ public class ProducteevLoginActivity extends Activity {
else {
Editable email = emailEditText.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.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
/**

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

@ -145,10 +145,7 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
try {
String authToken = preferences.getToken();
String z = stripslashes(0, "71o3346pr40o5o4nt4n7t6n287t4op28","2");
String v = stripslashes(2, "9641n76n9s1736q1578q1o1337q19233","4ae");
invoker = new ProducteevInvoker(z, v);
invoker = getInvoker();
String email = Preferences.getStringValue(R.string.producteev_PPr_email);
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!
// ----------------------------------------------------------------------

Loading…
Cancel
Save