|
|
@ -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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|