Added contact chooser option to people picker

pull/14/head
Sam Bosley 13 years ago
parent 6168534e0a
commit 5ede134e9f

@ -72,6 +72,8 @@ public class EditPeopleControlSet extends PopupControlSet {
public static final String EXTRA_TASK_ID = "task"; //$NON-NLS-1$ 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 Task task;
private final ArrayList<Metadata> nonSharedTags = new ArrayList<Metadata>(); private final ArrayList<Metadata> nonSharedTags = new ArrayList<Metadata>();
@ -366,6 +368,7 @@ public class EditPeopleControlSet extends PopupControlSet {
unassigned.put("id", Task.USER_ID_UNASSIGNED); unassigned.put("id", Task.USER_ID_UNASSIGNED);
sharedPeople.add(1, unassigned); sharedPeople.add(1, unassigned);
} }
addAstridFriends(sharedPeople); addAstridFriends(sharedPeople);
// de-duplicate by user id and/or email // 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) { for (AssignedChangedListener l : listeners) {
if (l.shouldShowTaskRabbit()) { if (l.shouldShowTaskRabbit()) {
taskRabbitUser = new AssignedToUser(activity.getString(R.string.actfm_EPA_task_rabbit), new JSONObject().put("default_picture", R.drawable.task_rabbit_image)); 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()){ 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) { for (AssignedChangedListener l : listeners) {
if(l.showTaskRabbitForUser(user.label, user.user)) { if(l.showTaskRabbitForUser(user.label, user.user)) {
// assignedList.setItemChecked(selected, true);
// assignedList.setItemChecked(position, false);
assignedDisplay.setText(user.toString()); assignedDisplay.setText(user.toString());
assignedCustom.setText(""); //$NON-NLS-1$ assignedCustom.setText(""); //$NON-NLS-1$
DialogUtilities.dismissDialog(activity, dialog); 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()); assignedDisplay.setText(user.toString());
assignedCustom.setText(""); //$NON-NLS-1$ assignedCustom.setText(""); //$NON-NLS-1$
selected = position; selected = position;
@ -568,14 +587,6 @@ public class EditPeopleControlSet extends PopupControlSet {
sharedWithDialog.show(); 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 // --- events

@ -735,11 +735,18 @@ public final class ActFmSyncService {
JSONObject result = actFmInvoker.invoke("user_list", JSONObject result = actFmInvoker.invoke("user_list",
"token", token, "modified_after", serverTime); "token", token, "modified_after", serverTime);
JSONArray users = result.getJSONArray("list"); JSONArray users = result.getJSONArray("list");
HashSet<Long> ids = new HashSet<Long>();
for (int i = 0; i < users.length(); i++) { for (int i = 0; i < users.length(); i++) {
JSONObject userObject = users.getJSONObject(i); JSONObject userObject = users.getJSONObject(i);
ids.add(userObject.optLong("id"));
actFmDataService.saveUserData(userObject); 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); return result.optInt("time", 0);
} }

@ -121,7 +121,7 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
actFmPreferenceService.recordSyncStart(); actFmPreferenceService.recordSyncStart();
startUsersFetcher(callback, finisher); startUsersFetcher(manual, callback, finisher);
startTagFetcher(callback, finisher); startTagFetcher(callback, finisher);
@ -134,12 +134,12 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
} }
/** fetch changes to users/friends */ /** fetch changes to users/friends */
private void startUsersFetcher(final SyncResultCallback callback, private void startUsersFetcher(final boolean manual, final SyncResultCallback callback,
final AtomicInteger finisher) { final AtomicInteger finisher) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
int time = Preferences.getInt(LAST_USERS_FETCH_TIME, 0); int time = manual ? 0 : Preferences.getInt(LAST_USERS_FETCH_TIME, 0);
try { try {
time = actFmSyncService.fetchUsers(time); time = actFmSyncService.fetchUsers(time);
Preferences.setInt(LAST_USERS_FETCH_TIME, time); Preferences.setInt(LAST_USERS_FETCH_TIME, time);

@ -139,6 +139,9 @@
<!-- task sharing dialog: anyone --> <!-- task sharing dialog: anyone -->
<string name="actfm_EPA_unassigned">Unassigned</string> <string name="actfm_EPA_unassigned">Unassigned</string>
<!-- task sharing dialog: choose a contact -->
<string name="actfm_EPA_choose_contact">Choose a contact</string>
<!-- task sharing dialog: use task rabbit --> <!-- task sharing dialog: use task rabbit -->
<string name="actfm_EPA_task_rabbit">Outsource it!</string> <string name="actfm_EPA_task_rabbit">Outsource it!</string>

Loading…
Cancel
Save