From 1864b0e39521473b853f32662fd4cd652b70fb38 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 7 Feb 2012 11:11:21 -0800 Subject: [PATCH] Fixed array index errors in google auth activities, fixed possible JSON issue in pushtaskonsave --- .../astrid/actfm/ActFmGoogleAuthActivity.java | 13 ++++++++----- .../todoroo/astrid/actfm/sync/ActFmSyncService.java | 7 +++++-- .../astrid/gtasks/auth/GtasksLoginActivity.java | 13 ++++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java index 4c922a9e0..a63c57838 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java @@ -100,11 +100,14 @@ public class ActFmGoogleAuthActivity extends ListActivity { @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - final ProgressDialog pd = DialogUtilities.progressDialog(this, this.getString(R.string.gtasks_GLA_authenticating)); - pd.show(); - final Account a = accountManager.getAccountByName(nameArray[position - 1]); // Subtract 1 because apparently android counts the header view as part of the adapter. - accountName = a.name; - getAuthToken(a, pd); + int offsetPosition = position - 1; // Subtract 1 because apparently android counts the header view as part of the adapter. + if (offsetPosition >= 0 && offsetPosition < nameArray.length) { + final ProgressDialog pd = DialogUtilities.progressDialog(this, this.getString(R.string.gtasks_GLA_authenticating)); + pd.show(); + final Account a = accountManager.getAccountByName(nameArray[position - 1]); + accountName = a.name; + getAuthToken(a, pd); + } } private void getAuthToken(Account a, final ProgressDialog pd) { 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 93965f029..b84b836d5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -346,8 +346,11 @@ public final class ActFmSyncService { if(task.getValue(Task.USER_ID) == Task.USER_ID_EMAIL) { try { JSONObject user = new JSONObject(task.getValue(Task.USER)); - params.add("user_email"); - params.add(user.get("email")); + String userEmail = user.optString("email"); + if (!TextUtils.isEmpty(userEmail)) { + params.add("user_email"); + params.add(userEmail); + } } catch (JSONException e) { Log.e("Error parsing user", task.getValue(Task.USER), e); } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java index a15f50a7b..1637bfcde 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java @@ -120,11 +120,14 @@ public class GtasksLoginActivity extends ListActivity { @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - final ProgressDialog pd = DialogUtilities.progressDialog(this, this.getString(R.string.gtasks_GLA_authenticating)); - pd.show(); - final Account a = accountManager.getAccountByName(nameArray[position - 1]); // Subtract 1 because apparently android counts the header view as part of the adapter. - accountName = a.name; - getAuthToken(a, pd); + int offsetPosition = position - 1; // Subtract 1 because apparently android counts the header view as part of the adapter. + if (offsetPosition >= 0 && offsetPosition < nameArray.length) { + final ProgressDialog pd = DialogUtilities.progressDialog(this, this.getString(R.string.gtasks_GLA_authenticating)); + pd.show(); + final Account a = accountManager.getAccountByName(nameArray[offsetPosition]); + accountName = a.name; + getAuthToken(a, pd); + } } private void getAuthToken(Account a, final ProgressDialog pd) {