Fixed several references to non-string userids

pull/14/head
Sam Bosley 12 years ago
parent 51bf8445e6
commit c7d7167763

@ -165,6 +165,10 @@ public final class Task extends RemoteModel {
@Deprecated public static final StringProperty USER = new StringProperty( @Deprecated public static final StringProperty USER = new StringProperty(
TABLE, USER_JSON_PROPERTY_NAME); TABLE, USER_JSON_PROPERTY_NAME);
/** User email (for assigning by email) */
public static final StringProperty USER_EMAIL = new StringProperty(
TABLE, "userEmail");
/** Creator user id */ /** Creator user id */
public static final StringProperty CREATOR_ID = new StringProperty( public static final StringProperty CREATOR_ID = new StringProperty(
TABLE, "creatorId", Property.PROP_FLAG_USER_ID); TABLE, "creatorId", Property.PROP_FLAG_USER_ID);
@ -209,6 +213,15 @@ public final class Task extends RemoteModel {
/** user id = myself */ /** user id = myself */
public static final String USER_ID_SELF = "0"; public static final String USER_ID_SELF = "0";
public static boolean isRealUserId(String userId) {
if (userId == null)
return false;
return !(Task.USER_ID_SELF.equals(userId) ||
Task.USER_ID_UNASSIGNED.equals(userId) ||
Task.USER_ID_EMAIL.equals(userId) ||
Task.USER_ID_IGNORE.equals(userId));
}
// --- notification flags // --- notification flags
/** whether to send a reminder at deadline */ /** whether to send a reminder at deadline */

@ -200,21 +200,10 @@ public class GCMIntentService extends GCMBaseIntentService {
Intent notifyIntent = null; Intent notifyIntent = null;
int notifId; int notifId;
long user_idTemp = -2; final String user_id = intent.getStringExtra("oid");
final String user_idString = intent.getStringExtra("oid");
if (user_idString != null) {
try {
user_idTemp = Long.parseLong(user_idString);
} catch(NumberFormatException e) {
// We tried
Log.e("c2dm-receive", "oid-parse", e);
}
}
final long user_id = user_idTemp;
final String token_id = intent.getStringExtra("tid"); final String token_id = intent.getStringExtra("tid");
// unregister // unregister
if (!actFmPreferenceService.isLoggedIn() || user_id != ActFmPreferenceService.userId()) { if (!actFmPreferenceService.isLoggedIn() || !ActFmPreferenceService.userId().equals(user_id)) {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
@ -372,11 +361,10 @@ public class GCMIntentService extends GCMBaseIntentService {
try { try {
Update update = new Update(); Update update = new Update();
update.setValue(Update.UUID, intent.getStringExtra("activity_id")); update.setValue(Update.UUID, intent.getStringExtra("activity_id"));
update.setValue(Update.USER_ID, Long.parseLong(intent.getStringExtra("user_id"))); update.setValue(Update.USER_ID, intent.getStringExtra("user_id"));
JSONObject user = new JSONObject(); JSONObject user = new JSONObject();
user.put("id", update.getValue(Update.USER_ID)); user.put("id", update.getValue(Update.USER_ID));
user.put("name", intent.getStringExtra("user_name")); user.put("name", intent.getStringExtra("user_name"));
update.setValue(Update.USER, user.toString());
update.setValue(Update.ACTION, "commented"); update.setValue(Update.ACTION, "commented");
update.setValue(Update.ACTION_CODE, "tag_comment"); update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.TARGET_NAME, intent.getStringExtra("title")); update.setValue(Update.TARGET_NAME, intent.getStringExtra("title"));

@ -8,9 +8,7 @@ package com.todoroo.astrid.actfm.sync;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.text.TextUtils;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
@ -27,7 +25,6 @@ import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
@ -142,43 +139,4 @@ public final class ActFmDataService {
cursor.close(); cursor.close();
} }
} }
/**
* Save / Merge JSON user
* @param userObject
* @throws JSONException
*/
@SuppressWarnings("nls")
public void saveUserData(JSONObject userObject) throws JSONException {
Criterion criterion = User.REMOTE_ID.eq(userObject.getLong("id"));
if (!TextUtils.isEmpty(userObject.optString("email")))
criterion = Criterion.or(criterion, Criterion.and(User.EMAIL.isNotNull(), User.EMAIL.eq(userObject.optString("email"))));
TodorooCursor<User> cursor = userDao.query(Query.select(User.PROPERTIES).where(criterion));
try {
cursor.moveToFirst();
User user = new User();
if (!cursor.isAfterLast()) {
user.readFromCursor(cursor);
}
ActFmSyncService.JsonHelper.userFromJson(userObject, user);
userDao.persist(user);
} finally {
cursor.close();
}
}
public void addUserByEmail(String email) {
TodorooCursor<User> cursor = userDao.query(Query.select(User.ID).where(User.EMAIL.eq(email)));
try {
if (cursor.getCount() == 0) {
User user = new User();
user.setValue(User.REMOTE_ID, Task.USER_ID_IGNORE);
user.setValue(User.EMAIL, email);
userDao.persist(user);
}
} finally {
cursor.close();
}
}
} }

@ -71,8 +71,6 @@ import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.helper.ImageDiskCache; import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.service.MetadataService; 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.TagDataService;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
@ -437,29 +435,29 @@ public final class ActFmSyncService {
boolean sharing = false; boolean sharing = false;
if(values.containsKey(Task.USER_ID.name) && task.getTransitory(TaskService.TRANS_ASSIGNED) != null) { // if(values.containsKey(Task.USER_ID.name) && task.getTransitory(TaskService.TRANS_ASSIGNED) != null) {
if(task.getValue(Task.USER_ID) == Task.USER_ID_EMAIL) { // if(task.getValue(Task.USER_ID) == Task.USER_ID_EMAIL) {
try { // try {
JSONObject user = new JSONObject(task.getValue(Task.USER)); // JSONObject user = new JSONObject(task.getValue(Task.USER));
String userEmail = user.optString("email"); // String userEmail = user.optString("email");
if (!TextUtils.isEmpty(userEmail)) { // if (!TextUtils.isEmpty(userEmail)) {
params.add("user_email"); // params.add("user_email");
params.add(userEmail); // params.add(userEmail);
//
actFmDataService.addUserByEmail(userEmail); // actFmDataService.addUserByEmail(userEmail);
sharing = true; // sharing = true;
} // }
} catch (JSONException e) { // } catch (JSONException e) {
Log.e("Error parsing user", task.getValue(Task.USER), e); // Log.e("Error parsing user", task.getValue(Task.USER), e);
} // }
} else { // } else {
params.add("user_id"); // params.add("user_id");
if(task.getValue(Task.USER_ID) == Task.USER_ID_SELF) // if(task.getValue(Task.USER_ID) == Task.USER_ID_SELF)
params.add(ActFmPreferenceService.userId()); // params.add(ActFmPreferenceService.userId());
else // else
params.add(task.getValue(Task.USER_ID)); // params.add(task.getValue(Task.USER_ID));
} // }
} // }
// if (values.containsKey(Task.SHARED_WITH.name)) { // if (values.containsKey(Task.SHARED_WITH.name)) {
// try { // try {
@ -1067,11 +1065,11 @@ public final class ActFmSyncService {
} }
private void saveUsers(JSONArray users, HashSet<Long> ids) throws JSONException { private void saveUsers(JSONArray users, HashSet<Long> ids) throws JSONException {
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")); // ids.add(userObject.optLong("id"));
actFmDataService.saveUserData(userObject); // actFmDataService.saveUserData(userObject);
} // }
} }
public int fetchUsers() throws JSONException, IOException { public int fetchUsers() throws JSONException, IOException {
@ -1498,12 +1496,12 @@ public final class ActFmSyncService {
JsonHelper.taskFromJson(item, remote, metadata); JsonHelper.taskFromJson(item, remote, metadata);
if(remote.getValue(Task.USER_ID) == 0) { // if(remote.getValue(Task.USER_ID) == 0) {
if(!remote.isSaved()) // if(!remote.isSaved())
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_CREATED); // StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_CREATED);
else if(remote.isCompleted()) // else if(remote.isCompleted())
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMPLETED); // StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMPLETED);
} // }
if(!remote.isSaved() && remote.hasDueDate() && if(!remote.isSaved() && remote.hasDueDate() &&
remote.getValue(Task.DUE_DATE) < DateUtilities.now()) remote.getValue(Task.DUE_DATE) < DateUtilities.now())
@ -1713,10 +1711,10 @@ public final class ActFmSyncService {
public static void updateFromJson(JSONObject json, Update model) throws JSONException { public static void updateFromJson(JSONObject json, Update model) throws JSONException {
model.setValue(Update.REMOTE_ID, json.getLong("id")); model.setValue(Update.REMOTE_ID, json.getLong("id"));
readUser(json.getJSONObject("user"), model, Update.USER_ID, Update.USER); // readUser(json.getJSONObject("user"), model, Update.USER_ID, Update.USER);
if (!json.isNull("other_user")) { // if (!json.isNull("other_user")) {
readUser(json.getJSONObject("other_user"), model, Update.OTHER_USER_ID, Update.OTHER_USER); // readUser(json.getJSONObject("other_user"), model, Update.OTHER_USER_ID, Update.OTHER_USER);
} // }
model.setValue(Update.ACTION, json.getString("action")); model.setValue(Update.ACTION, json.getString("action"));
model.setValue(Update.ACTION_CODE, json.getString("action_code")); model.setValue(Update.ACTION_CODE, json.getString("action_code"));
model.setValue(Update.TARGET_NAME, json.getString("target_name")); model.setValue(Update.TARGET_NAME, json.getString("target_name"));
@ -1733,23 +1731,23 @@ public final class ActFmSyncService {
public static void readUser(JSONObject user, AbstractModel model, LongProperty idProperty, public static void readUser(JSONObject user, AbstractModel model, LongProperty idProperty,
StringProperty userProperty) throws JSONException { StringProperty userProperty) throws JSONException {
long id = user.optLong("id", -2); // long id = user.optLong("id", -2);
if(id == -2) { // if(id == -2) {
model.setValue(idProperty, -1L); // model.setValue(idProperty, -1L);
if(userProperty != null) { // if(userProperty != null) {
JSONObject unassigned = new JSONObject(); // JSONObject unassigned = new JSONObject();
unassigned.put("id", -1L); // unassigned.put("id", -1L);
model.setValue(userProperty, unassigned.toString()); // model.setValue(userProperty, unassigned.toString());
} // }
} else if (id == ActFmPreferenceService.userId()) { // } else if (id == ActFmPreferenceService.userId()) {
model.setValue(idProperty, 0L); // model.setValue(idProperty, 0L);
if (userProperty != null) // if (userProperty != null)
model.setValue(userProperty, ActFmPreferenceService.thisUser().toString()); // model.setValue(userProperty, ActFmPreferenceService.thisUser().toString());
} else { // } else {
model.setValue(idProperty, id); // model.setValue(idProperty, id);
if(userProperty != null) // if(userProperty != null)
model.setValue(userProperty, user.toString()); // model.setValue(userProperty, user.toString());
} // }
} }
/** /**
@ -1771,8 +1769,8 @@ public final class ActFmSyncService {
model.setValue(TagData.REMOTE_ID, json.getLong("id")); model.setValue(TagData.REMOTE_ID, json.getLong("id"));
model.setValue(TagData.NAME, json.getString("name")); model.setValue(TagData.NAME, json.getString("name"));
if (!featuredList) // if (!featuredList)
readUser(json.getJSONObject("user"), model, TagData.USER_ID, TagData.USER); // readUser(json.getJSONObject("user"), model, TagData.USER_ID, TagData.USER);
if (featuredList) if (featuredList)
model.setFlag(TagData.FLAGS, TagData.FLAG_FEATURED, true); model.setFlag(TagData.FLAGS, TagData.FLAG_FEATURED, true);
@ -1819,8 +1817,8 @@ public final class ActFmSyncService {
model.setValue(Task.UUID, null); model.setValue(Task.UUID, null);
else else
model.setValue(Task.UUID, remoteId); model.setValue(Task.UUID, remoteId);
readUser(json.getJSONObject("user"), model, Task.USER_ID, Task.USER); // readUser(json.getJSONObject("user"), model, Task.USER_ID, Task.USER);
readUser(json.getJSONObject("creator"), model, Task.CREATOR_ID, null); // readUser(json.getJSONObject("creator"), model, Task.CREATOR_ID, null);
model.setValue(Task.TITLE, json.getString("title")); model.setValue(Task.TITLE, json.getString("title"));
model.setValue(Task.IMPORTANCE, json.getInt("importance")); model.setValue(Task.IMPORTANCE, json.getInt("importance"));
int urgency = json.getBoolean("has_due_time") ? Task.URGENCY_SPECIFIC_DAY_TIME : Task.URGENCY_SPECIFIC_DAY; int urgency = json.getBoolean("has_due_time") ? Task.URGENCY_SPECIFIC_DAY_TIME : Task.URGENCY_SPECIFIC_DAY;

@ -76,10 +76,10 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
@Override @Override
public void pushRemoteModel(Task model) { public void pushRemoteModel(Task model) {
long userId = model.getValue(Task.USER_ID); // long userId = model.getValue(Task.USER_ID);
if (userId != Task.USER_ID_SELF && userId != ActFmPreferenceService.userId()) // if (userId != Task.USER_ID_SELF && userId != ActFmPreferenceService.userId())
model.putTransitory(TaskService.TRANS_ASSIGNED, true); // model.putTransitory(TaskService.TRANS_ASSIGNED, true);
actFmSyncService.pushTaskOnSave(model, model.getMergedValues()); // actFmSyncService.pushTaskOnSave(model, model.getMergedValues());
} }
}; };

@ -199,7 +199,7 @@ public final class GtasksSyncService {
com.google.api.services.tasks.model.Task remoteModel = null; com.google.api.services.tasks.model.Task remoteModel = null;
boolean newlyCreated = false; boolean newlyCreated = false;
if (values.containsKey(Task.USER_ID.name) && values.getAsLong(Task.USER_ID.name) != Task.USER_ID_SELF) { if (values.containsKey(Task.USER_ID.name) && !Task.USER_ID_SELF.equals(values.getAsString(Task.USER_ID.name))) {
if (gtasksMetadata != null && !TextUtils.isEmpty(gtasksMetadata.getValue(GtasksMetadata.ID))) { if (gtasksMetadata != null && !TextUtils.isEmpty(gtasksMetadata.getValue(GtasksMetadata.ID))) {
try { try {
invoker.deleteGtask(gtasksMetadata.getValue(GtasksMetadata.LIST_ID), gtasksMetadata.getValue(GtasksMetadata.ID)); invoker.deleteGtask(gtasksMetadata.getValue(GtasksMetadata.LIST_ID), gtasksMetadata.getValue(GtasksMetadata.ID));

@ -440,7 +440,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
Update update = new Update(); Update update = new Update();
update.setValue(Update.MESSAGE, message); update.setValue(Update.MESSAGE, message);
update.setValue(Update.ACTION_CODE, actionCode); update.setValue(Update.ACTION_CODE, actionCode);
update.setValue(Update.USER_ID, 0L); update.setValue(Update.USER_ID, Task.USER_ID_SELF);
if(task.containsNonNullValue(Task.UUID) && !RemoteModel.NO_UUID.equals(task.getValue(Task.UUID))) if(task.containsNonNullValue(Task.UUID) && !RemoteModel.NO_UUID.equals(task.getValue(Task.UUID)))
update.setValue(Update.TASK_UUID, task.getValue(Task.UUID)); update.setValue(Update.TASK_UUID, task.getValue(Task.UUID));
update.setValue(Update.TASK_LOCAL, task.getId()); update.setValue(Update.TASK_LOCAL, task.getId());

@ -68,7 +68,7 @@ public class PeopleFilterExposer extends BroadcastReceiver {
User user = new User(); User user = new User();
for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) { for (users.moveToFirst(); !users.isAfterLast(); users.moveToNext()) {
user.readFromCursor(users); user.readFromCursor(users);
if (user.getValue(User.REMOTE_ID) == ActFmPreferenceService.userId()) if (ActFmPreferenceService.userId().equals(user.getValue(User.UUID)))
continue; continue;
Filter currFilter = filterFromUserData(user); Filter currFilter = filterFromUserData(user);
if (currFilter != null) if (currFilter != null)

@ -160,7 +160,7 @@ public class Notifications extends BroadcastReceiver {
if (!Preferences.getBoolean(R.string.p_rmd_enabled, true)) if (!Preferences.getBoolean(R.string.p_rmd_enabled, true))
return false; return false;
// you're done, or not yours - don't sound, do delete // you're done, or not yours - don't sound, do delete
if(task.isCompleted() || task.isDeleted() || task.getValue(Task.USER_ID) != 0) if(task.isCompleted() || task.isDeleted() || !Task.USER_ID_SELF.equals(task.getValue(Task.USER_ID)))
return false; return false;
// new task edit in progress // new task edit in progress

@ -192,7 +192,7 @@ public final class ReminderService {
// Make sure no alarms are scheduled other than the next one. When that one is shown, it // Make sure no alarms are scheduled other than the next one. When that one is shown, it
// will schedule the next one after it, and so on and so forth. // will schedule the next one after it, and so on and so forth.
clearAllAlarms(task); clearAllAlarms(task);
if(task.isCompleted() || task.isDeleted() || task.getValue(Task.USER_ID) != 0) { if(task.isCompleted() || task.isDeleted() || !Task.USER_ID_SELF.equals(task.getValue(Task.USER_ID))) {
return; return;
} }

@ -42,6 +42,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
@ -83,7 +84,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
} }
int deleteIntentLabel; int deleteIntentLabel;
if (tag.memberCount > 0 && tag.userId != 0) if (tag.memberCount > 0 && !Task.USER_ID_SELF.equals(tag.userId))
deleteIntentLabel = R.string.tag_cm_leave; deleteIntentLabel = R.string.tag_cm_leave;
else else
deleteIntentLabel = R.string.tag_cm_delete; deleteIntentLabel = R.string.tag_cm_delete;
@ -219,7 +220,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT, TagData.USER_ID); TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT, TagData.USER_ID);
if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0 && tagData.getValue(TagData.USER_ID) == 0) { if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0 && Task.USER_ID_SELF.equals(tagData.getValue(TagData.USER_ID))) {
DialogUtilities.okCancelDialog(this, getString(R.string.actfm_tag_operation_owner_delete), getOkListener(), getCancelListener()); DialogUtilities.okCancelDialog(this, getString(R.string.actfm_tag_operation_owner_delete), getOkListener(), getCancelListener());
return; return;
} }

@ -108,7 +108,7 @@ public final class TagService {
public long id; public long id;
public String uuid; public String uuid;
public String image; public String image;
public long userId; public String userId;
public long memberCount; public long memberCount;
@Deprecated public long remoteId; @Deprecated public long remoteId;
@ -416,7 +416,7 @@ public final class TagService {
if(tagData != null) { if(tagData != null) {
tagData.setValue(TagData.DELETION_DATE, DateUtilities.now()); tagData.setValue(TagData.DELETION_DATE, DateUtilities.now());
PluginServices.getTagDataService().save(tagData); PluginServices.getTagDataService().save(tagData);
shared = tagData.getValue(TagData.MEMBER_COUNT) > 0 && tagData.getValue(TagData.USER_ID) != 0; // Was I a list member and NOT owner? shared = tagData.getValue(TagData.MEMBER_COUNT) > 0 && !Task.USER_ID_SELF.equals(tagData.getValue(TagData.USER_ID)); // Was I a list member and NOT owner?
} }
Toast.makeText(context, context.getString(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted), Toast.makeText(context, context.getString(shared ? R.string.TEA_tags_left : R.string.TEA_tags_deleted, tag, deleted),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();

@ -14,9 +14,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -932,13 +929,9 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
&& !TextUtils.isEmpty(model.getValue(Task.RECURRENCE)); && !TextUtils.isEmpty(model.getValue(Task.RECURRENCE));
String assignedTo = peopleControlSet.getAssignedToString(); String assignedTo = peopleControlSet.getAssignedToString();
String assignedEmail = ""; //$NON-NLS-1$ String assignedEmail = ""; //$NON-NLS-1$
long assignedId = Task.USER_ID_IGNORE; String assignedId = Task.USER_ID_IGNORE;
try { if (Task.USER_ID_EMAIL.equals(model.getValue(Task.USER_ID))) {
JSONObject assignedUser = new JSONObject(model.getValue(Task.USER)); assignedEmail = model.getValue(Task.USER_EMAIL);
assignedEmail = assignedUser.optString("email", ""); //$NON-NLS-1$ //$NON-NLS-2$
assignedId = assignedUser.optLong("id", Task.USER_ID_IGNORE); //$NON-NLS-1$
} catch (JSONException e) {
//
} }
if (taskEditActivity) { if (taskEditActivity) {
@ -948,7 +941,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
data.putExtra(TOKEN_ASSIGNED_TO_DISPLAY, assignedTo); data.putExtra(TOKEN_ASSIGNED_TO_DISPLAY, assignedTo);
if (!TextUtils.isEmpty(assignedEmail)) if (!TextUtils.isEmpty(assignedEmail))
data.putExtra(TOKEN_ASSIGNED_TO_EMAIL, assignedEmail); data.putExtra(TOKEN_ASSIGNED_TO_EMAIL, assignedEmail);
if (assignedId > 0) if (Task.isRealUserId(assignedId));
data.putExtra(TOKEN_ASSIGNED_TO_ID, assignedId); data.putExtra(TOKEN_ASSIGNED_TO_ID, assignedId);
} }
if (showRepeatAlert) { if (showRepeatAlert) {

@ -5,10 +5,6 @@
*/ */
package com.todoroo.astrid.activity; package com.todoroo.astrid.activity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.app.Activity; import android.app.Activity;
import android.app.SearchManager; import android.app.SearchManager;
@ -51,7 +47,6 @@ import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.people.PeopleFilterMode; import com.todoroo.astrid.people.PeopleFilterMode;
@ -628,7 +623,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if (data.getBooleanExtra(TaskEditFragment.TOKEN_TASK_WAS_ASSIGNED, false)) { if (data.getBooleanExtra(TaskEditFragment.TOKEN_TASK_WAS_ASSIGNED, false)) {
String assignedTo = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_DISPLAY); String assignedTo = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_DISPLAY);
String assignedEmail = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_EMAIL); String assignedEmail = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_EMAIL);
long assignedId = data.getLongExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_ID, Task.USER_ID_IGNORE); String assignedId = data.getStringExtra(TaskEditFragment.TOKEN_ASSIGNED_TO_ID);
taskAssignedTo(assignedTo, assignedEmail, assignedId); taskAssignedTo(assignedTo, assignedEmail, assignedId);
} else if (data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK) != null) { } else if (data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK) != null) {
Task repeating = data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK); Task repeating = data.getParcelableExtra(TaskEditFragment.TOKEN_NEW_REPEATING_TASK);
@ -664,7 +659,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
tlf.refresh(); tlf.refresh();
} }
public void taskAssignedTo(final String assignedDisplay, String assignedEmail, final long assignedId) { public void taskAssignedTo(final String assignedDisplay, String assignedEmail, final String assignedId) {
final TaskListFragment tlf = getTaskListFragment(); final TaskListFragment tlf = getTaskListFragment();
if (tlf != null && tlf.isInbox()) { if (tlf != null && tlf.isInbox()) {
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@ -679,72 +674,73 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
getString(R.string.actfm_view_task_text, assignedDisplay), getString(R.string.actfm_view_task_text, assignedDisplay),
R.string.actfm_view_task_ok, R.string.actfm_view_task_cancel, R.string.actfm_view_task_ok, R.string.actfm_view_task_cancel,
0, okListener, null); 0, okListener, null);
} else if (tlf != null && (!TextUtils.isEmpty(assignedEmail) || assignedId > 0)) { } else if (tlf != null && (!TextUtils.isEmpty(assignedEmail) || Task.isRealUserId(assignedId))) {
checkAddTagMember(tlf, assignedDisplay, assignedEmail, assignedId); checkAddTagMember(tlf, assignedDisplay, assignedEmail, assignedId);
} }
} }
private void checkAddTagMember(final TaskListFragment tlf, final String assignedDisplay, String assignedEmail, long assignedId) { private void checkAddTagMember(final TaskListFragment tlf, final String assignedDisplay, String assignedEmail, String assignedId) {
final TagData td = tlf.getActiveTagData(); throw new RuntimeException("Hey Sam! You should reimplement this");
if (td != null) { // final TagData td = tlf.getActiveTagData();
String members = td.getValue(TagData.MEMBERS); // if (td != null) {
if (members == null) // String members = td.getValue(TagData.MEMBERS);
members = ""; //$NON-NLS-1$ // if (members == null)
if (TextUtils.isEmpty(members) || TextUtils.isEmpty(assignedEmail) || !members.contains(assignedEmail)) { // members = ""; //$NON-NLS-1$
// show dialog to ask if user should be added to the tag-members // if (TextUtils.isEmpty(members) || TextUtils.isEmpty(assignedEmail) || !members.contains(assignedEmail)) {
JSONObject user = new JSONObject(); // // show dialog to ask if user should be added to the tag-members
JSONArray membersArray = null; // JSONObject user = new JSONObject();
boolean memberFound = false; // JSONArray membersArray = null;
try { // boolean memberFound = false;
if (!TextUtils.isEmpty(assignedEmail)) // try {
user.put("email", assignedEmail); //$NON-NLS-1$ // if (!TextUtils.isEmpty(assignedEmail))
if (assignedId > 0) // user.put("email", assignedEmail); //$NON-NLS-1$
user.put("id", assignedId); //$NON-NLS-1$ // if (assignedId > 0)
membersArray = new JSONArray(members); // user.put("id", assignedId); //$NON-NLS-1$
// membersArray = new JSONArray(members);
for (int i = 0; i < membersArray.length(); i++) { //
JSONObject member = membersArray.getJSONObject(i); // for (int i = 0; i < membersArray.length(); i++) {
long memberId = member.optLong("id", Task.USER_ID_IGNORE); //$NON-NLS-1$ // JSONObject member = membersArray.getJSONObject(i);
if (memberId > 0 && memberId == assignedId) { // long memberId = member.optLong("id", Task.USER_ID_IGNORE); //$NON-NLS-1$
memberFound = true; // if (memberId > 0 && memberId == assignedId) {
break; // memberFound = true;
} // break;
} // }
if (!memberFound) { // }
String ownerString = td.getValue(TagData.USER); // if (!memberFound) {
JSONObject owner = new JSONObject(ownerString); // String ownerString = td.getValue(TagData.USER);
long ownerId = owner.optLong("id", Task.USER_ID_IGNORE); //$NON-NLS-1$ // JSONObject owner = new JSONObject(ownerString);
if (ownerId > 0 && assignedId == ownerId) // long ownerId = owner.optLong("id", Task.USER_ID_IGNORE); //$NON-NLS-1$
memberFound = true; // if (ownerId > 0 && assignedId == ownerId)
} // memberFound = true;
} catch (JSONException e) { // }
return; // } catch (JSONException e) {
} // return;
// }
if (memberFound) //
return; // if (memberFound)
// return;
membersArray.put(user); //
// membersArray.put(user);
final JSONArray finalArray = membersArray; //
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() { // final JSONArray finalArray = membersArray;
@Override // DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int which) { // @Override
td.setValue(TagData.MEMBERS, finalArray.toString()); // public void onClick(DialogInterface d, int which) {
td.setValue(TagData.MEMBER_COUNT, finalArray.length()); // td.setValue(TagData.MEMBERS, finalArray.toString());
PluginServices.getTagDataService().save(td); // td.setValue(TagData.MEMBER_COUNT, finalArray.length());
tlf.refresh(); // PluginServices.getTagDataService().save(td);
} // tlf.refresh();
}; // }
DialogUtilities.okCancelCustomDialog(this, // };
getString(R.string.actfm_EPA_add_person_to_list_title), // DialogUtilities.okCancelCustomDialog(this,
getString(R.string.actfm_EPA_add_person_to_list, assignedDisplay, assignedDisplay), // getString(R.string.actfm_EPA_add_person_to_list_title),
R.string.actfm_EPA_add_person_to_list_ok, // getString(R.string.actfm_EPA_add_person_to_list, assignedDisplay, assignedDisplay),
R.string.actfm_EPA_add_person_to_list_cancel, // R.string.actfm_EPA_add_person_to_list_ok,
android.R.drawable.ic_dialog_alert, // R.string.actfm_EPA_add_person_to_list_cancel,
okListener, null); // android.R.drawable.ic_dialog_alert,
} // okListener, null);
} // }
// }
} }
public void incrementFilterCount(Filter filter) { public void incrementFilterCount(Filter filter) {

@ -467,8 +467,8 @@ public class TaskService {
Task original = new Task(); Task original = new Task();
original.setId(itemId); original.setId(itemId);
Task clone = clone(original); Task clone = clone(original);
long userId = clone.getValue(Task.USER_ID); String userId = clone.getValue(Task.USER_ID);
if (userId != Task.USER_ID_SELF && userId != ActFmPreferenceService.userId()) if (!Task.USER_ID_SELF.equals(userId) && !ActFmPreferenceService.userId().equals(userId))
clone.putTransitory(TRANS_ASSIGNED, true); clone.putTransitory(TRANS_ASSIGNED, true);
clone.setValue(Task.CREATION_DATE, DateUtilities.now()); clone.setValue(Task.CREATION_DATE, DateUtilities.now());
clone.setValue(Task.COMPLETION_DATE, 0L); clone.setValue(Task.COMPLETION_DATE, 0L);

@ -8,9 +8,6 @@ package com.todoroo.astrid.ui;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
@ -328,13 +325,9 @@ public class QuickAddBar extends LinearLayout {
String assignedTo = peopleControl.getAssignedToString(); String assignedTo = peopleControl.getAssignedToString();
String assignedEmail = ""; String assignedEmail = "";
long assignedId = Task.USER_ID_IGNORE; String assignedId = task.getValue(Task.USER_ID);
try { if (Task.USER_ID_EMAIL.equals(task.getValue(Task.USER_ID))) {
JSONObject assignedUser = new JSONObject(task.getValue(Task.USER)); assignedEmail = task.getValue(Task.USER_EMAIL);
assignedEmail = assignedUser.optString("email", ""); //$NON-NLS-1$ //$NON-NLS-2$
assignedId = assignedUser.optLong("id", Task.USER_ID_IGNORE);
} catch (JSONException e) {
//
} }
resetControlSets(); resetControlSets();

Loading…
Cancel
Save