From 5ede134e9f9ca2109766d6403e20e30ffcfeeec1 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 6 Apr 2012 13:43:30 -0700 Subject: [PATCH] Added contact chooser option to people picker --- .../astrid/actfm/EditPeopleControlSet.java | 35 ++++++++++++------- .../astrid/actfm/sync/ActFmSyncService.java | 7 ++++ .../actfm/sync/ActFmSyncV2Provider.java | 6 ++-- astrid/res/values/strings-actfm.xml | 3 ++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index a4a001732..5204473a5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -72,6 +72,8 @@ public class EditPeopleControlSet extends PopupControlSet { public static final String EXTRA_TASK_ID = "task"; //$NON-NLS-1$ + private static final String CONTACT_CHOOSER_USER = "the_contact_user"; //$NON-NLS-1$ + private Task task; private final ArrayList nonSharedTags = new ArrayList(); @@ -366,6 +368,7 @@ public class EditPeopleControlSet extends PopupControlSet { unassigned.put("id", Task.USER_ID_UNASSIGNED); sharedPeople.add(1, unassigned); } + addAstridFriends(sharedPeople); // de-duplicate by user id and/or email @@ -425,12 +428,23 @@ public class EditPeopleControlSet extends PopupControlSet { } } + AssignedToUser chooseContact = new AssignedToUser(activity.getString(R.string.actfm_EPA_choose_contact), + new JSONObject().put("default_picture", R.drawable.icn_friends) + .put(CONTACT_CHOOSER_USER, true)); + int contactsIndex = addUnassigned ? 2 : 1; + listValues.add(contactsIndex, chooseContact); + if (assignedIndex >= contactsIndex) + assignedIndex++; + for (AssignedChangedListener l : listeners) { if (l.shouldShowTaskRabbit()) { taskRabbitUser = new AssignedToUser(activity.getString(R.string.actfm_EPA_task_rabbit), new JSONObject().put("default_picture", R.drawable.task_rabbit_image)); - listValues.add(addUnassigned ? 2 : 1, taskRabbitUser); + int taskRabbitIndex = addUnassigned ? 3 : 2; + listValues.add(taskRabbitIndex, taskRabbitUser); if(l.didPostToTaskRabbit()){ - assignedIndex = listValues.size()-1; + assignedIndex = taskRabbitIndex; + } else if (assignedIndex >= taskRabbitIndex) { + assignedIndex++; } } } @@ -524,8 +538,6 @@ public class EditPeopleControlSet extends PopupControlSet { for (AssignedChangedListener l : listeners) { if(l.showTaskRabbitForUser(user.label, user.user)) { -// assignedList.setItemChecked(selected, true); -// assignedList.setItemChecked(position, false); assignedDisplay.setText(user.toString()); assignedCustom.setText(""); //$NON-NLS-1$ DialogUtilities.dismissDialog(activity, dialog); @@ -533,6 +545,13 @@ public class EditPeopleControlSet extends PopupControlSet { } } + + if (user.user.has(CONTACT_CHOOSER_USER)) { + Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); + fragment.startActivityForResult(intent, TaskEditFragment.REQUEST_CODE_CONTACT); + return; + } + assignedDisplay.setText(user.toString()); assignedCustom.setText(""); //$NON-NLS-1$ selected = position; @@ -568,14 +587,6 @@ public class EditPeopleControlSet extends PopupControlSet { sharedWithDialog.show(); } }); - -// assignedCustom.setOnClickListener(new OnClickListener() { -// @Override -// public void onClick(View v) { -// Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); -// fragment.startActivityForResult(intent, TaskEditFragment.REQUEST_CODE_CONTACT); -// } -// }); } // --- events 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 abc57acbc..58ea9ba8f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -735,11 +735,18 @@ public final class ActFmSyncService { JSONObject result = actFmInvoker.invoke("user_list", "token", token, "modified_after", serverTime); JSONArray users = result.getJSONArray("list"); + HashSet ids = new HashSet(); for (int i = 0; i < users.length(); i++) { JSONObject userObject = users.getJSONObject(i); + ids.add(userObject.optLong("id")); actFmDataService.saveUserData(userObject); } + if (serverTime == 0) { + Long[] allIds = ids.toArray(new Long[ids.size()]); + actFmDataService.userDao.deleteWhere(Criterion.not(User.ID.in(allIds))); + } + return result.optInt("time", 0); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java index 9a316dca3..b295c842f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java @@ -121,7 +121,7 @@ public class ActFmSyncV2Provider extends SyncV2Provider { actFmPreferenceService.recordSyncStart(); - startUsersFetcher(callback, finisher); + startUsersFetcher(manual, callback, finisher); startTagFetcher(callback, finisher); @@ -134,12 +134,12 @@ public class ActFmSyncV2Provider extends SyncV2Provider { } /** fetch changes to users/friends */ - private void startUsersFetcher(final SyncResultCallback callback, + private void startUsersFetcher(final boolean manual, final SyncResultCallback callback, final AtomicInteger finisher) { new Thread(new Runnable() { @Override public void run() { - int time = Preferences.getInt(LAST_USERS_FETCH_TIME, 0); + int time = manual ? 0 : Preferences.getInt(LAST_USERS_FETCH_TIME, 0); try { time = actFmSyncService.fetchUsers(time); Preferences.setInt(LAST_USERS_FETCH_TIME, time); diff --git a/astrid/res/values/strings-actfm.xml b/astrid/res/values/strings-actfm.xml index 0f09c32a1..c2256c781 100644 --- a/astrid/res/values/strings-actfm.xml +++ b/astrid/res/values/strings-actfm.xml @@ -139,6 +139,9 @@ Unassigned + + Choose a contact + Outsource it!