From f6d3df10a37a7909af99f452a655597aa21190ab Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 17 Feb 2012 18:07:58 -0800 Subject: [PATCH] Upgrade to api level 6 and send creation date when saving task --- .../astrid/actfm/ActFmLoginActivity.java | 38 ++++++++++++------- .../astrid/actfm/sync/ActFmSyncService.java | 15 +++++++- astrid/res/values/strings-actfm.xml | 6 +++ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java index 09cb421b0..6a66fff17 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java @@ -269,9 +269,15 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener body.setOrientation(LinearLayout.VERTICAL); body.setPadding(10, 0, 10, 0); - final EditText name = addEditField(body, - R.string.actfm_ALA_name_label); - name.setInputType(InputType.TYPE_CLASS_TEXT | + final EditText firstNameField = addEditField(body, + R.string.actfm_ALA_firstname_label); + 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_FLAG_CAP_WORDS); @@ -282,7 +288,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener @Override public void onClick(View v) { isNew.set(!isNew.get()); - int nameIndex = body.indexOfChild(name); + int nameIndex = body.indexOfChild(lastNameField); int visibility = isNew.get() ? View.VISIBLE : View.GONE; int passwordVisibility = isNew.get() ? View.GONE : View.VISIBLE; toggleNew.setText(isNew.get() ? R.string.actfm_ALA_pw_returning @@ -290,6 +296,8 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener dialog.get().setTitle( isNew.get() ? R.string.actfm_ALA_signup_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).setVisibility(visibility); @@ -331,11 +339,14 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int which) { - String nameString = isNew.get() ? name.getText().toString() + String firstName = isNew.get() ? firstNameField.getText().toString() : 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(), - nameString, ActFmInvoker.PROVIDER_PASSWORD, + firstName, lastName, ActFmInvoker.PROVIDER_PASSWORD, password.getText().toString()); if (isNew.get()) @@ -346,7 +357,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int which) { - AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, name, email, password); + AndroidUtilities.hideSoftInputForViews(ActFmLoginActivity.this, firstNameField, lastNameField, email, password); } }).show()); @@ -427,10 +438,11 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener JSONObject json; try { 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$ - authenticate(email, name, ActFmInvoker.PROVIDER_FACEBOOK, + authenticate(email, firstName, lastName, ActFmInvoker.PROVIDER_FACEBOOK, facebook.getAccessToken()); StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_FB); } catch (FacebookError e) { @@ -467,7 +479,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener // --- utilities @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) { if (progressDialog == null) progressDialog = DialogUtilities.progressDialog(this, @@ -477,7 +489,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener @Override public void run() { try { - final JSONObject result = actFmInvoker.authenticate(email, name, + final JSONObject result = actFmInvoker.authenticate(email, firstName, lastName, provider, secret); final String token = actFmInvoker.getToken(); @@ -591,7 +603,7 @@ public class ActFmLoginActivity extends FragmentActivity implements AuthListener } else if (requestCode == REQUEST_CODE_GOOGLE) { String email= data.getStringExtra(ActFmGoogleAuthActivity.RESULT_EMAIL); String token = data.getStringExtra(ActFmGoogleAuthActivity.RESULT_TOKEN); - authenticate(email, email, "google", token); + authenticate(email, email, "", "google", token); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 6c6597fe3..ad99fe4d2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -296,15 +296,26 @@ public final class ActFmSyncService { * Synchronize with server when data changes */ public void pushTaskOnSave(Task task, ContentValues values) { + Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID, Task.CREATION_DATE); + long remoteId; if(task.containsValue(Task.REMOTE_ID)) { remoteId = task.getValue(Task.REMOTE_ID); } else { - Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID); if(taskForRemote == null) return; 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; ArrayList params = new ArrayList(); @@ -402,6 +413,8 @@ public final class ActFmSyncService { if(params.size() == 0 || !checkForToken()) return; + params.add("created_at"); params.add(creationDate); + if(!newlyCreated) { params.add("id"); params.add(remoteId); } else if(!values.containsKey(Task.TITLE.name)) { diff --git a/astrid/res/values/strings-actfm.xml b/astrid/res/values/strings-actfm.xml index 803fa5dba..363f69ed0 100644 --- a/astrid/res/values/strings-actfm.xml +++ b/astrid/res/values/strings-actfm.xml @@ -221,6 +221,12 @@ Name + + First Name + + + Last Name + Email