Upgrade to api level 6 and send creation date when saving task

pull/14/head
Sam Bosley 13 years ago
parent f2baeb259c
commit f6d3df10a3

@ -269,9 +269,15 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
body.setOrientation(LinearLayout.VERTICAL); body.setOrientation(LinearLayout.VERTICAL);
body.setPadding(10, 0, 10, 0); body.setPadding(10, 0, 10, 0);
final EditText name = addEditField(body, final EditText firstNameField = addEditField(body,
R.string.actfm_ALA_name_label); R.string.actfm_ALA_firstname_label);
name.setInputType(InputType.TYPE_CLASS_TEXT | firstNameField.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PERSON_NAME |
InputType.TYPE_TEXT_FLAG_CAP_WORDS);
final EditText lastNameField = addEditField(body,
R.string.actfm_ALA_lastname_label);
lastNameField.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PERSON_NAME | InputType.TYPE_TEXT_VARIATION_PERSON_NAME |
InputType.TYPE_TEXT_FLAG_CAP_WORDS); InputType.TYPE_TEXT_FLAG_CAP_WORDS);
@ -282,7 +288,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
@Override @Override
public void onClick(View v) { public void onClick(View v) {
isNew.set(!isNew.get()); isNew.set(!isNew.get());
int nameIndex = body.indexOfChild(name); int nameIndex = body.indexOfChild(lastNameField);
int visibility = isNew.get() ? View.VISIBLE : View.GONE; int visibility = isNew.get() ? View.VISIBLE : View.GONE;
int passwordVisibility = isNew.get() ? View.GONE : View.VISIBLE; int passwordVisibility = isNew.get() ? View.GONE : View.VISIBLE;
toggleNew.setText(isNew.get() ? R.string.actfm_ALA_pw_returning toggleNew.setText(isNew.get() ? R.string.actfm_ALA_pw_returning
@ -290,6 +296,8 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
dialog.get().setTitle( dialog.get().setTitle(
isNew.get() ? R.string.actfm_ALA_signup_title isNew.get() ? R.string.actfm_ALA_signup_title
: R.string.actfm_ALA_login_title); : R.string.actfm_ALA_login_title);
body.getChildAt(nameIndex - 3).setVisibility(visibility);
body.getChildAt(nameIndex - 2).setVisibility(visibility);
body.getChildAt(nameIndex - 1).setVisibility(visibility); body.getChildAt(nameIndex - 1).setVisibility(visibility);
body.getChildAt(nameIndex).setVisibility(visibility); body.getChildAt(nameIndex).setVisibility(visibility);
@ -331,11 +339,14 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
android.R.string.ok, new DialogInterface.OnClickListener() { android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dlg, int which) { public void onClick(DialogInterface dlg, int which) {
String nameString = isNew.get() ? name.getText().toString() String firstName = isNew.get() ? firstNameField.getText().toString()
: null; : null;
AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, name, email, password); String lastName = isNew.get() ? lastNameField.getText().toString()
: null;
AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, firstNameField, lastNameField, email, password);
authenticate(email.getText().toString(), authenticate(email.getText().toString(),
nameString, ActFmInvoker.PROVIDER_PASSWORD, firstName, lastName, ActFmInvoker.PROVIDER_PASSWORD,
password.getText().toString()); password.getText().toString());
if (isNew.get()) if (isNew.get())
@ -346,7 +357,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dlg, int which) { public void onClick(DialogInterface dlg, int which) {
AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, name, email, password); AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, firstNameField, lastNameField, email, password);
} }
}).show()); }).show());
@ -427,10 +438,11 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
JSONObject json; JSONObject json;
try { try {
json = Util.parseJson(response); json = Util.parseJson(response);
String name = json.getString("name"); //$NON-NLS-1$ String firstName = json.getString("first_name"); //$NON-NLS-1$
String lastName = json.getString("last_name");
String email = json.getString("email"); //$NON-NLS-1$ String email = json.getString("email"); //$NON-NLS-1$
authenticate(email, name, ActFmInvoker.PROVIDER_FACEBOOK, authenticate(email, firstName, lastName, ActFmInvoker.PROVIDER_FACEBOOK,
facebook.getAccessToken()); facebook.getAccessToken());
StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_FB); StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_FB);
} catch (FacebookError e) { } catch (FacebookError e) {
@ -467,7 +479,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
// --- utilities // --- utilities
@SuppressWarnings("nls") @SuppressWarnings("nls")
public void authenticate(final String email, final String name, final String provider, public void authenticate(final String email, final String firstName, final String lastName, final String provider,
final String secret) { final String secret) {
if (progressDialog == null) if (progressDialog == null)
progressDialog = DialogUtilities.progressDialog(this, progressDialog = DialogUtilities.progressDialog(this,
@ -477,7 +489,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
@Override @Override
public void run() { public void run() {
try { try {
final JSONObject result = actFmInvoker.authenticate(email, name, final JSONObject result = actFmInvoker.authenticate(email, firstName, lastName,
provider, secret); provider, secret);
final String token = actFmInvoker.getToken(); final String token = actFmInvoker.getToken();
@ -591,7 +603,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener
} else if (requestCode == REQUEST_CODE_GOOGLE) { } else if (requestCode == REQUEST_CODE_GOOGLE) {
String email= data.getStringExtra(ActFmGoogleAuthActivity.RESULT_EMAIL); String email= data.getStringExtra(ActFmGoogleAuthActivity.RESULT_EMAIL);
String token = data.getStringExtra(ActFmGoogleAuthActivity.RESULT_TOKEN); String token = data.getStringExtra(ActFmGoogleAuthActivity.RESULT_TOKEN);
authenticate(email, email, "google", token); authenticate(email, email, "", "google", token);
} }
} }

@ -296,15 +296,26 @@ public final class ActFmSyncService {
* Synchronize with server when data changes * Synchronize with server when data changes
*/ */
public void pushTaskOnSave(Task task, ContentValues values) { public void pushTaskOnSave(Task task, ContentValues values) {
Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID, Task.CREATION_DATE);
long remoteId; long remoteId;
if(task.containsValue(Task.REMOTE_ID)) { if(task.containsValue(Task.REMOTE_ID)) {
remoteId = task.getValue(Task.REMOTE_ID); remoteId = task.getValue(Task.REMOTE_ID);
} else { } else {
Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID);
if(taskForRemote == null) if(taskForRemote == null)
return; return;
remoteId = taskForRemote.getValue(Task.REMOTE_ID); remoteId = taskForRemote.getValue(Task.REMOTE_ID);
} }
long creationDate;
if (task.containsValue(Task.CREATION_DATE)) {
creationDate = task.getValue(Task.CREATION_DATE);
} else {
if (taskForRemote == null)
return;
creationDate = taskForRemote.getValue(Task.CREATION_DATE);
}
boolean newlyCreated = remoteId == 0; boolean newlyCreated = remoteId == 0;
ArrayList<Object> params = new ArrayList<Object>(); ArrayList<Object> params = new ArrayList<Object>();
@ -402,6 +413,8 @@ public final class ActFmSyncService {
if(params.size() == 0 || !checkForToken()) if(params.size() == 0 || !checkForToken())
return; return;
params.add("created_at"); params.add(creationDate);
if(!newlyCreated) { if(!newlyCreated) {
params.add("id"); params.add(remoteId); params.add("id"); params.add(remoteId);
} else if(!values.containsKey(Task.TITLE.name)) { } else if(!values.containsKey(Task.TITLE.name)) {

@ -221,6 +221,12 @@
<!-- share login: Name --> <!-- share login: Name -->
<string name="actfm_ALA_name_label">Name</string> <string name="actfm_ALA_name_label">Name</string>
<!-- share login: Name -->
<string name="actfm_ALA_firstname_label">First Name</string>
<!-- share login: Name -->
<string name="actfm_ALA_lastname_label">Last Name</string>
<!-- share login: Email --> <!-- share login: Email -->
<string name="actfm_ALA_email_label">Email</string> <string name="actfm_ALA_email_label">Email</string>

Loading…
Cancel
Save