|
|
|
@ -2,7 +2,6 @@ package com.todoroo.astrid.actfm;
|
|
|
|
|
|
|
|
|
|
import greendroid.widget.AsyncImageView;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
@ -13,7 +12,6 @@ import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
@ -40,23 +38,16 @@ import android.widget.Toast;
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.service.ContextManager;
|
|
|
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
|
|
|
import com.todoroo.andlib.service.ExceptionService;
|
|
|
|
|
import com.todoroo.andlib.utility.DialogUtilities;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmInvoker;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
|
|
|
|
|
import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper;
|
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
|
|
|
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
|
|
|
|
|
import com.todoroo.astrid.data.Metadata;
|
|
|
|
|
import com.todoroo.astrid.data.TagData;
|
|
|
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
|
import com.todoroo.astrid.service.AstridDependencyInjector;
|
|
|
|
|
import com.todoroo.astrid.service.MetadataService;
|
|
|
|
|
import com.todoroo.astrid.service.StatisticsConstants;
|
|
|
|
|
import com.todoroo.astrid.service.StatisticsService;
|
|
|
|
|
import com.todoroo.astrid.service.TagDataService;
|
|
|
|
|
import com.todoroo.astrid.service.TaskService;
|
|
|
|
|
import com.todoroo.astrid.service.ThemeService;
|
|
|
|
@ -64,7 +55,6 @@ import com.todoroo.astrid.tags.TagService;
|
|
|
|
|
import com.todoroo.astrid.ui.PeopleContainer;
|
|
|
|
|
import com.todoroo.astrid.ui.PeopleContainer.OnAddNewPersonListener;
|
|
|
|
|
import com.todoroo.astrid.ui.PopupControlSet;
|
|
|
|
|
import com.todoroo.astrid.utility.Flags;
|
|
|
|
|
|
|
|
|
|
public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
|
|
|
|
@ -108,8 +98,6 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
|
|
|
|
|
private final ArrayList<AssignedToUser> listValues = new ArrayList<AssignedToUser>();
|
|
|
|
|
|
|
|
|
|
private String saveToast = null;
|
|
|
|
|
|
|
|
|
|
private final int loginRequestCode;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
@ -302,12 +290,14 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject myself = new JSONObject();
|
|
|
|
|
myself.put("id", 0L);
|
|
|
|
|
myself.put("id", Task.USER_ID_SELF);
|
|
|
|
|
sharedPeople.add(0, myself);
|
|
|
|
|
|
|
|
|
|
if (actFmPreferenceService.isLoggedIn()) {
|
|
|
|
|
boolean hasTags = task.getTransitory("tags") != null &&
|
|
|
|
|
((HashSet<String>)task.getTransitory("tags")).size() > 0;
|
|
|
|
|
if (actFmPreferenceService.isLoggedIn() && hasTags) {
|
|
|
|
|
JSONObject unassigned = new JSONObject();
|
|
|
|
|
unassigned.put("id", -1L);
|
|
|
|
|
unassigned.put("id", Task.USER_ID_UNASSIGNED);
|
|
|
|
|
sharedPeople.add(1, unassigned);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -361,15 +351,15 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
for (int i = 0; i < listValues.size(); i++) {
|
|
|
|
|
JSONObject user = listValues.get(i).user;
|
|
|
|
|
if (user != null) {
|
|
|
|
|
if (user.optLong("id") == assignedId || (user.optString("email").equals(assignedEmail) && !(TextUtils.isEmpty(assignedEmail))))
|
|
|
|
|
if (user.optLong("id") == assignedId ||
|
|
|
|
|
(user.optString("email").equals(assignedEmail) &&
|
|
|
|
|
!(TextUtils.isEmpty(assignedEmail))))
|
|
|
|
|
assignedIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int selected = assignedIndex;
|
|
|
|
|
// final ArrayAdapter<AssignedToUser> usersAdapter = new ArrayAdapter<AssignedToUser>(activity,
|
|
|
|
|
// android.R.layout.simple_list_item_single_choice, listValues);
|
|
|
|
|
|
|
|
|
|
final AssignedUserAdapter usersAdapter = new AssignedUserAdapter(activity, listValues);
|
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@ -388,6 +378,7 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
super(context, R.layout.assigned_adapter_row, people);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
@Override
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
|
if(convertView == null)
|
|
|
|
@ -425,7 +416,7 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
long id) {
|
|
|
|
|
AssignedToUser user = (AssignedToUser) assignedList.getAdapter().getItem(position);
|
|
|
|
|
assignedDisplay.setText(user.toString());
|
|
|
|
|
assignedCustom.setText("");
|
|
|
|
|
assignedCustom.setText(""); //$NON-NLS-1$
|
|
|
|
|
refreshDisplayView();
|
|
|
|
|
DialogUtilities.dismissDialog(activity, dialog);
|
|
|
|
|
}
|
|
|
|
@ -435,7 +426,7 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
assignedClear.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
assignedCustom.setText("");
|
|
|
|
|
assignedCustom.setText(""); //$NON-NLS-1$
|
|
|
|
|
assignedList.setItemChecked(0, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -477,8 +468,8 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
if(task == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
saveToast = toast;
|
|
|
|
|
boolean dirty = false;
|
|
|
|
|
String sharedToast = null;
|
|
|
|
|
try {
|
|
|
|
|
JSONObject userJson = null;
|
|
|
|
|
TextView assignedView = null;
|
|
|
|
@ -498,11 +489,14 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
activity.getString(R.string.actfm_EPA_invalid_email, userJson.optString("email")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(userJson == null || userJson.optLong("id", -2) == 0) {
|
|
|
|
|
dirty = task.getValue(Task.USER_ID) == 0L ? dirty : true;
|
|
|
|
|
task.setValue(Task.USER_ID, 0L);
|
|
|
|
|
if(userJson == null || userJson.optLong("id", Task.USER_ID_EMAIL) == Task.USER_ID_SELF) {
|
|
|
|
|
dirty = task.getValue(Task.USER_ID) == Task.USER_ID_SELF ? dirty : true;
|
|
|
|
|
task.setValue(Task.USER_ID, Task.USER_ID_SELF);
|
|
|
|
|
if(!TextUtils.isEmpty(task.getValue(Task.USER)))
|
|
|
|
|
task.setValue(Task.USER, "{}");
|
|
|
|
|
task.setValue(Task.USER, "");
|
|
|
|
|
} else if(userJson.optLong("id") == Task.USER_ID_UNASSIGNED) {
|
|
|
|
|
dirty = task.getValue(Task.USER_ID) == Task.USER_ID_UNASSIGNED ? dirty : true;
|
|
|
|
|
task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED);
|
|
|
|
|
} else {
|
|
|
|
|
String user = userJson.toString();
|
|
|
|
|
|
|
|
|
@ -510,21 +504,29 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
String taskUserEmail = "";
|
|
|
|
|
try {
|
|
|
|
|
JSONObject taskUser = new JSONObject(task.getValue(Task.USER));
|
|
|
|
|
taskUserId = taskUser.optLong("id", -2);
|
|
|
|
|
taskUserId = taskUser.optLong("id", Task.USER_ID_EMAIL);
|
|
|
|
|
taskUserEmail = taskUser.optString("email");
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
// sad times
|
|
|
|
|
}
|
|
|
|
|
long userId = userJson.optLong("id", -2);
|
|
|
|
|
long userId = userJson.optLong("id", Task.USER_ID_EMAIL);
|
|
|
|
|
String userEmail = userJson.optString("email");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean match = (userId == taskUserId && userId != -2);
|
|
|
|
|
boolean match = (userId == taskUserId && userId != Task.USER_ID_EMAIL);
|
|
|
|
|
match = match || (userEmail.equals(taskUserEmail) && !TextUtils.isEmpty(userEmail));
|
|
|
|
|
|
|
|
|
|
dirty = match ? dirty : true;
|
|
|
|
|
task.setValue(Task.USER_ID, userJson.optLong("id", -2));
|
|
|
|
|
task.setValue(Task.USER_ID, userJson.optLong("id", Task.USER_ID_EMAIL));
|
|
|
|
|
task.setValue(Task.USER, user);
|
|
|
|
|
|
|
|
|
|
String assignedName = userJson.optString("name", userEmail);
|
|
|
|
|
|
|
|
|
|
if(task.getTransitory("tags") == null ||
|
|
|
|
|
((HashSet<String>)task.getTransitory("tags")).size() == 0) {
|
|
|
|
|
sharedToast = activity.getString(R.string.actfm_EPA_assigned_toast, assignedName,
|
|
|
|
|
assignedName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JSONObject sharedWith = parseSharedWithAndTags();
|
|
|
|
@ -543,13 +545,15 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
public void onClick(DialogInterface d, int which) {
|
|
|
|
|
makePrivateTask();
|
|
|
|
|
AssignedToUser me = (AssignedToUser) assignedList.getAdapter().getItem(0);
|
|
|
|
|
task.setValue(Task.USER_ID, me.user.optLong("id", -2));
|
|
|
|
|
task.setValue(Task.USER_ID, me.user.optLong("id", Task.USER_ID_EMAIL));
|
|
|
|
|
task.setValue(Task.USER, me.user.toString());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
DialogUtilities.okCancelCustomDialog(activity, activity.getString(R.string.actfm_EPA_login_button),
|
|
|
|
|
activity.getString(R.string.actfm_EPA_login_to_share), R.string.actfm_EPA_login_button,
|
|
|
|
|
R.string.actfm_EPA_dont_share_button, android.R.drawable.ic_dialog_alert, okListener, cancelListener);
|
|
|
|
|
R.string.actfm_EPA_dont_share_button, android.R.drawable.ic_dialog_alert,
|
|
|
|
|
okListener, cancelListener);
|
|
|
|
|
showSaveToast(toast);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -557,14 +561,11 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
if(!TextUtils.isEmpty(task.getValue(Task.SHARED_WITH)) || sharedWith.length() != 0)
|
|
|
|
|
task.setValue(Task.SHARED_WITH, sharedWith.toString());
|
|
|
|
|
|
|
|
|
|
if(dirty)
|
|
|
|
|
taskService.save(task);
|
|
|
|
|
task.putTransitory("task-assigned", true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(dirty)
|
|
|
|
|
shareTask(sharedWith);
|
|
|
|
|
else
|
|
|
|
|
showSaveToast();
|
|
|
|
|
if(sharedToast != null)
|
|
|
|
|
toast = (toast != null) ? toast + "\n" + sharedToast : sharedToast + "\n";
|
|
|
|
|
showSaveToast(toast);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
@ -582,12 +583,14 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
private void makePrivateTask() {
|
|
|
|
|
assignToMe();
|
|
|
|
|
sharedWithContainer.removeAllViews();
|
|
|
|
|
sharedWithContainer.addPerson("");
|
|
|
|
|
sharedWithContainer.addPerson(""); //$NON-NLS-1$
|
|
|
|
|
refreshDisplayView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showSaveToast() {
|
|
|
|
|
int length = saveToast.indexOf('\n') > -1 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
|
|
|
|
|
private void showSaveToast(String saveToast) {
|
|
|
|
|
if(saveToast == null) return;
|
|
|
|
|
int length = saveToast.contains("\n") ? //$NON-NLS-1$
|
|
|
|
|
Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
|
|
|
|
|
Toast.makeText(activity, saveToast, length).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -631,104 +634,6 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
return sharedWith;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
private void shareTask(final JSONObject sharedWith) {
|
|
|
|
|
final JSONArray emails = sharedWith.optJSONArray("p");
|
|
|
|
|
|
|
|
|
|
final ProgressDialog pd = DialogUtilities.progressDialog(activity,
|
|
|
|
|
activity.getString(R.string.DLG_please_wait));
|
|
|
|
|
new Thread() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
ActFmInvoker invoker = new ActFmInvoker(actFmPreferenceService.getToken());
|
|
|
|
|
try {
|
|
|
|
|
if(task.getValue(Task.REMOTE_ID) == 0) {
|
|
|
|
|
actFmSyncService.pushTask(task.getId());
|
|
|
|
|
task.setValue(Task.REMOTE_ID, taskService.fetchById(task.getId(),
|
|
|
|
|
Task.REMOTE_ID).getValue(Task.REMOTE_ID));
|
|
|
|
|
}
|
|
|
|
|
if(task.getValue(Task.REMOTE_ID) == 0) {
|
|
|
|
|
DialogUtilities.okDialog(activity, "We had an error saving " +
|
|
|
|
|
"this task to Astrid.com. Could you let us know why this happened?", null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object[] args = buildSharingArgs(emails);
|
|
|
|
|
JSONObject result = invoker.invoke("task_share", args);
|
|
|
|
|
|
|
|
|
|
sharedWith.remove("p");
|
|
|
|
|
task.setValue(Task.SHARED_WITH, sharedWith.toString());
|
|
|
|
|
task.setValue(Task.DETAILS_DATE, 0L);
|
|
|
|
|
|
|
|
|
|
readTagData(result.getJSONArray("tags"));
|
|
|
|
|
JSONObject assignee = result.getJSONObject("assignee");
|
|
|
|
|
JsonHelper.readUser(assignee,
|
|
|
|
|
task, Task.USER_ID, Task.USER);
|
|
|
|
|
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
|
|
|
|
|
taskService.save(task);
|
|
|
|
|
|
|
|
|
|
String assignedName = assignee.optString("name");
|
|
|
|
|
long id = assignee.optLong("id", -2);
|
|
|
|
|
if (!(id == -2 || id == ActFmPreferenceService.userId() || assignedName == null)) {
|
|
|
|
|
saveToast += "\n" +
|
|
|
|
|
activity.getString(R.string.actfm_EPA_assigned_toast, assignedName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = result.optInt("shared", 0);
|
|
|
|
|
if(count > 0) {
|
|
|
|
|
saveToast += "\n" +
|
|
|
|
|
activity.getString(R.string.actfm_EPA_emailed_toast,
|
|
|
|
|
activity.getResources().getQuantityString(R.plurals.Npeople, count, count));
|
|
|
|
|
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_SHARED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH);
|
|
|
|
|
ContextManager.getContext().sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
|
|
|
|
|
|
|
|
|
|
DialogUtilities.dismissDialog(activity, pd);
|
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
showSaveToast();
|
|
|
|
|
activity.finish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
DialogUtilities.okDialog(activity,
|
|
|
|
|
activity.getString(R.string.SyP_ioerror),
|
|
|
|
|
android.R.drawable.ic_dialog_alert, e.toString(), null);
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
DialogUtilities.okDialog(activity,
|
|
|
|
|
activity.getString(R.string.SyP_ioerror),
|
|
|
|
|
android.R.drawable.ic_dialog_alert, e.toString(), null);
|
|
|
|
|
} finally {
|
|
|
|
|
DialogUtilities.dismissDialog(activity, pd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
private void readTagData(JSONArray tags) throws JSONException {
|
|
|
|
|
ArrayList<Metadata> metadata = new ArrayList<Metadata>();
|
|
|
|
|
for(int i = 0; i < tags.length(); i++) {
|
|
|
|
|
JSONObject tagObject = tags.getJSONObject(i);
|
|
|
|
|
TagData tagData = tagDataService.getTag(tagObject.getString("name"), TagData.ID);
|
|
|
|
|
if(tagData == null)
|
|
|
|
|
tagData = new TagData();
|
|
|
|
|
ActFmSyncService.JsonHelper.tagFromJson(tagObject, tagData);
|
|
|
|
|
tagDataService.save(tagData);
|
|
|
|
|
|
|
|
|
|
Metadata tagMeta = new Metadata();
|
|
|
|
|
tagMeta.setValue(Metadata.KEY, TagService.KEY);
|
|
|
|
|
tagMeta.setValue(TagService.TAG, tagData.getValue(TagData.NAME));
|
|
|
|
|
tagMeta.setValue(TagService.REMOTE_ID, tagData.getValue(TagData.REMOTE_ID));
|
|
|
|
|
metadata.add(tagMeta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
metadataService.synchronizeMetadata(task.getId(), metadata, MetadataCriteria.withKey(TagService.KEY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("nls")
|
|
|
|
|
protected Object[] buildSharingArgs(JSONArray emails) throws JSONException {
|
|
|
|
|
ArrayList<Object> values = new ArrayList<Object>();
|
|
|
|
@ -783,8 +688,11 @@ public class EditPeopleControlSet extends PopupControlSet {
|
|
|
|
|
/** Resume save
|
|
|
|
|
* @param data */
|
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
if(requestCode == loginRequestCode && resultCode == Activity.RESULT_OK)
|
|
|
|
|
saveSharingSettings(saveToast);
|
|
|
|
|
if(requestCode == loginRequestCode && resultCode == Activity.RESULT_OK) {
|
|
|
|
|
// clear user values & reset them to trigger a save
|
|
|
|
|
task.clearValue(Task.USER_ID);
|
|
|
|
|
task.clearValue(Task.USER);
|
|
|
|
|
}
|
|
|
|
|
else if (requestCode == loginRequestCode)
|
|
|
|
|
makePrivateTask();
|
|
|
|
|
}
|
|
|
|
|