Updated a ton of references to REMOTE_ID to use UUID instead

pull/14/head
Sam Bosley 12 years ago
parent 17e126f487
commit 5886bbd25b

@ -6,6 +6,7 @@
package com.timsu.astrid; package com.timsu.astrid;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -132,12 +133,12 @@ public class C2DMReceiver extends BroadcastReceiver {
try { try {
if(intent.hasExtra("tag_id")) { if(intent.hasExtra("tag_id")) {
TodorooCursor<TagData> cursor = tagDataService.query( TodorooCursor<TagData> cursor = tagDataService.query(
Query.select(TagData.PROPERTIES).where(TagData.REMOTE_ID.eq( Query.select(TagData.PROPERTIES).where(TagData.UUID.eq(
intent.getStringExtra("tag_id")))); intent.getStringExtra("tag_id"))));
try { try {
TagData tagData = new TagData(); TagData tagData = new TagData();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
tagData.setValue(TagData.REMOTE_ID, Long.parseLong(intent.getStringExtra("tag_id"))); tagData.setValue(TagData.UUID, new BigInteger(intent.getStringExtra("tag_id")));
tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
tagDataService.save(tagData); tagDataService.save(tagData);
} else { } else {
@ -151,12 +152,12 @@ public class C2DMReceiver extends BroadcastReceiver {
} }
} else if(intent.hasExtra("task_id")) { } else if(intent.hasExtra("task_id")) {
TodorooCursor<Task> cursor = taskService.query( TodorooCursor<Task> cursor = taskService.query(
Query.select(Task.PROPERTIES).where(Task.REMOTE_ID.eq( Query.select(Task.PROPERTIES).where(Task.UUID.eq(
intent.getStringExtra("task_id")))); intent.getStringExtra("task_id"))));
try { try {
final Task task = new Task(); final Task task = new Task();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
task.setValue(Task.REMOTE_ID, Long.parseLong(intent.getStringExtra("task_id"))); task.setValue(Task.UUID, new BigInteger(intent.getStringExtra("task_id")));
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
taskService.save(task); taskService.save(task);
} else { } else {
@ -297,13 +298,13 @@ public class C2DMReceiver extends BroadcastReceiver {
private Intent createTaskIntent(Intent intent) { private Intent createTaskIntent(Intent intent) {
TodorooCursor<Task> cursor = taskService.query( TodorooCursor<Task> cursor = taskService.query(
Query.select(Task.PROPERTIES).where(Task.REMOTE_ID.eq( Query.select(Task.PROPERTIES).where(Task.UUID.eq(
intent.getStringExtra("task_id")))); intent.getStringExtra("task_id"))));
try { try {
final Task task = new Task(); final Task task = new Task();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
task.setValue(Task.TITLE, intent.getStringExtra("title")); task.setValue(Task.TITLE, intent.getStringExtra("title"));
task.setValue(Task.REMOTE_ID, Long.parseLong(intent.getStringExtra("task_id"))); task.setValue(Task.UUID, new BigInteger(intent.getStringExtra("task_id")));
task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED); task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED);
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
taskService.save(task); taskService.save(task);
@ -338,13 +339,13 @@ public class C2DMReceiver extends BroadcastReceiver {
private Intent createTagIntent(final Context context, final Intent intent) { private Intent createTagIntent(final Context context, final Intent intent) {
TodorooCursor<TagData> cursor = tagDataService.query( TodorooCursor<TagData> cursor = tagDataService.query(
Query.select(TagData.PROPERTIES).where(TagData.REMOTE_ID.eq( Query.select(TagData.PROPERTIES).where(TagData.UUID.eq(
intent.getStringExtra("tag_id")))); intent.getStringExtra("tag_id"))));
try { try {
final TagData tagData = new TagData(); final TagData tagData = new TagData();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
tagData.setValue(TagData.NAME, intent.getStringExtra("title")); tagData.setValue(TagData.NAME, intent.getStringExtra("title"));
tagData.setValue(TagData.REMOTE_ID, Long.parseLong(intent.getStringExtra("tag_id"))); tagData.setValue(TagData.UUID, new BigInteger(intent.getStringExtra("tag_id")));
tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
tagDataService.save(tagData); tagDataService.save(tagData);
@ -370,7 +371,7 @@ public class C2DMReceiver extends BroadcastReceiver {
if(intent.hasExtra("activity_id")) { if(intent.hasExtra("activity_id")) {
try { try {
Update update = new Update(); Update update = new Update();
update.setValue(Update.REMOTE_ID, Long.parseLong(intent.getStringExtra("activity_id"))); update.setValue(Update.UUID, new BigInteger(intent.getStringExtra("activity_id")));
update.setValue(Update.USER_ID, Long.parseLong(intent.getStringExtra("user_id"))); update.setValue(Update.USER_ID, Long.parseLong(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));

@ -5,6 +5,7 @@
*/ */
package com.todoroo.astrid.actfm; package com.todoroo.astrid.actfm;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -826,8 +827,8 @@ public class EditPeopleControlSet extends PopupControlSet {
protected Object[] buildSharingArgs(JSONArray emails) throws JSONException { protected Object[] buildSharingArgs(JSONArray emails) throws JSONException {
ArrayList<Object> values = new ArrayList<Object>(); ArrayList<Object> values = new ArrayList<Object>();
if(task.containsNonNullValue(Task.REMOTE_ID)) { if(task.containsNonNullValue(Task.UUID)) {
long currentTaskID = task.getValue(Task.REMOTE_ID); BigInteger currentTaskID = task.getValue(Task.UUID);
values.add("id"); values.add("id");
values.add(currentTaskID); values.add(currentTaskID);
} }

@ -6,6 +6,7 @@
package com.todoroo.astrid.actfm; package com.todoroo.astrid.actfm;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -333,7 +334,7 @@ public class TagSettingsActivity extends FragmentActivity {
@Override @Override
public void run() { public void run() {
actFmSyncService.pushTagDataOnSave(tagData, tagData.getMergedValues()); actFmSyncService.pushTagDataOnSave(tagData, tagData.getMergedValues());
if(setBitmap != null && tagData.getValue(TagData.REMOTE_ID) > 0) if(setBitmap != null && BigInteger.ZERO.compareTo(tagData.getValue(TagData.UUID)) != 0)
uploadTagPicture(setBitmap); uploadTagPicture(setBitmap);
runOnUiThread(loadTag); runOnUiThread(loadTag);
@ -428,7 +429,7 @@ public class TagSettingsActivity extends FragmentActivity {
@Override @Override
public void run() { public void run() {
try { try {
String url = actFmSyncService.setTagPicture(tagData.getValue(TagData.REMOTE_ID), bitmap); String url = actFmSyncService.setTagPicture(tagData.getValue(TagData.UUID), bitmap);
if (TextUtils.isEmpty(url)) return; if (TextUtils.isEmpty(url)) return;
if (imageCache.contains(tagData.getValue(TagData.PICTURE))) { if (imageCache.contains(tagData.getValue(TagData.PICTURE))) {
imageCache.move(tagData.getValue(TagData.PICTURE), url); imageCache.move(tagData.getValue(TagData.PICTURE), url);
@ -459,7 +460,7 @@ public class TagSettingsActivity extends FragmentActivity {
public void handleCameraResult(Bitmap bitmap) { public void handleCameraResult(Bitmap bitmap) {
picture.setImageBitmap(bitmap); picture.setImageBitmap(bitmap);
setBitmap = bitmap; setBitmap = bitmap;
if(tagData.getValue(TagData.REMOTE_ID) > 0) if(BigInteger.ZERO.compareTo(tagData.getValue(TagData.UUID)) != 0)
uploadTagPicture(bitmap); uploadTagPicture(bitmap);
saveTagPictureLocally(bitmap); saveTagPictureLocally(bitmap);
} }

@ -5,6 +5,8 @@
*/ */
package com.todoroo.astrid.actfm; package com.todoroo.astrid.actfm;
import java.math.BigInteger;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
@ -275,8 +277,8 @@ public class TagUpdatesFragment extends ListFragment {
} }
public void setLastViewed() { public void setLastViewed() {
if(tagData != null && tagData.getValue(TagData.REMOTE_ID) > 0) { if(tagData != null && BigInteger.ZERO.compareTo(tagData.getValue(TagData.UUID)) != 0) {
Preferences.setLong(UPDATES_LAST_VIEWED + tagData.getValue(TagData.REMOTE_ID), DateUtilities.now()); Preferences.setLong(UPDATES_LAST_VIEWED + tagData.getValue(TagData.UUID), DateUtilities.now());
Activity activity = getActivity(); Activity activity = getActivity();
if (activity instanceof TaskListActivity) if (activity instanceof TaskListActivity)
((TaskListActivity) activity).setCommentsCount(0); ((TaskListActivity) activity).setCommentsCount(0);
@ -359,7 +361,7 @@ public class TagUpdatesFragment extends ListFragment {
update.setValue(Update.MESSAGE, addCommentField.getText().toString()); update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment"); update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.USER_ID, 0L); update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TAGS, "," + tagData.getValue(TagData.REMOTE_ID) + ","); update.setValue(Update.TAGS, "," + tagData.getValue(TagData.UUID) + ",");
update.setValue(Update.TAGS_LOCAL, "," + tagData.getId() + ","); update.setValue(Update.TAGS_LOCAL, "," + tagData.getId() + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now()); update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, tagData.getValue(TagData.NAME)); update.setValue(Update.TARGET_NAME, tagData.getValue(TagData.NAME));

@ -5,6 +5,8 @@
*/ */
package com.todoroo.astrid.actfm; package com.todoroo.astrid.actfm;
import java.math.BigInteger;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -73,7 +75,11 @@ public class TagViewFragment extends TaskListFragment {
public static final String BROADCAST_TAG_ACTIVITY = AstridApiConstants.PACKAGE + ".TAG_ACTIVITY"; //$NON-NLS-1$ public static final String BROADCAST_TAG_ACTIVITY = AstridApiConstants.PACKAGE + ".TAG_ACTIVITY"; //$NON-NLS-1$
public static final String EXTRA_TAG_NAME = "tag"; //$NON-NLS-1$ public static final String EXTRA_TAG_NAME = "tag"; //$NON-NLS-1$
public static final String EXTRA_TAG_REMOTE_ID = "remoteId"; //$NON-NLS-1$
@Deprecated
private static final String EXTRA_TAG_REMOTE_ID = "remoteId"; //$NON-NLS-1$
public static final String EXTRA_TAG_UUID = "uuid"; //$NON-NLS-1$
public static final String EXTRA_TAG_DATA = "tagData"; //$NON-NLS-1$ public static final String EXTRA_TAG_DATA = "tagData"; //$NON-NLS-1$
@ -194,18 +200,24 @@ public class TagViewFragment extends TaskListFragment {
TaskListActivity activity = (TaskListActivity) getActivity(); TaskListActivity activity = (TaskListActivity) getActivity();
String tag = extras.getString(EXTRA_TAG_NAME); String tag = extras.getString(EXTRA_TAG_NAME);
long remoteId = extras.getLong(EXTRA_TAG_REMOTE_ID, 0); BigInteger uuid = BigInteger.ZERO;
if (extras.containsKey(EXTRA_TAG_UUID))
uuid = new BigInteger(extras.getString(EXTRA_TAG_UUID));
else if (extras.containsKey(EXTRA_TAG_REMOTE_ID)) // For legacy support with shortcuts, widgets, etc.
uuid = BigInteger.valueOf(extras.getLong(EXTRA_TAG_REMOTE_ID));
if(tag == null && remoteId == 0) if(tag == null && BigInteger.ZERO.compareTo(uuid) == 0)
return; return;
TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES).where(Criterion.or(TagData.NAME.eqCaseInsensitive(tag), TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES).where(
Criterion.and(TagData.REMOTE_ID.gt(0), TagData.REMOTE_ID.eq(remoteId))))); Criterion.or(TagData.NAME.eqCaseInsensitive(tag),
TagData.UUID.eq(uuid))));
try { try {
tagData = new TagData(); tagData = new TagData();
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
tagData.setValue(TagData.NAME, tag); tagData.setValue(TagData.NAME, tag);
tagData.setValue(TagData.REMOTE_ID, remoteId); tagData.setValue(TagData.UUID, uuid);
tagDataService.save(tagData); tagDataService.save(tagData);
} else { } else {
cursor.moveToFirst(); cursor.moveToFirst();

@ -8,6 +8,7 @@ package com.todoroo.astrid.actfm.sync;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -450,7 +451,7 @@ public final class ActFmSyncService {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
metadata.readFromCursor(cursor); metadata.readFromCursor(cursor);
if(metadata.containsNonNullValue(TagMetadata.TAG_UUID) && if(metadata.containsNonNullValue(TagMetadata.TAG_UUID) &&
metadata.getValue(TagMetadata.TAG_UUID) != 0) { metadata.getValue(TagMetadata.TAG_UUID).compareTo(BigInteger.ZERO) != 0) {
params.add("tag_ids[]"); params.add("tag_ids[]");
params.add(metadata.getValue(TagMetadata.TAG_UUID)); params.add(metadata.getValue(TagMetadata.TAG_UUID));
} else { } else {
@ -1098,7 +1099,7 @@ public final class ActFmSyncService {
* @throws IOException * @throws IOException
* @throws ActFmServiceException * @throws ActFmServiceException
*/ */
public String setTagPicture(long tagId, Bitmap bitmap) throws ActFmServiceException, IOException { public String setTagPicture(BigInteger tagId, Bitmap bitmap) throws ActFmServiceException, IOException {
if(!checkForToken()) if(!checkForToken())
return null; return null;
@ -1538,12 +1539,12 @@ public final class ActFmSyncService {
*/ */
public static void taskFromJson(JSONObject json, Task model, ArrayList<Metadata> metadata) throws JSONException { public static void taskFromJson(JSONObject json, Task model, ArrayList<Metadata> metadata) throws JSONException {
metadata.clear(); metadata.clear();
model.clearValue(Task.REMOTE_ID); model.clearValue(Task.UUID);
long remoteId = json.getLong("id"); BigInteger remoteId = new BigInteger(json.getString("id"));
if (remoteId == 0) if (remoteId.compareTo(BigInteger.ZERO) == 0)
model.setValue(Task.REMOTE_ID, null); model.setValue(Task.UUID, null);
else else
model.setValue(Task.REMOTE_ID, 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"));
@ -1574,7 +1575,7 @@ public final class ActFmSyncService {
String name = tag.getString("name"); String name = tag.getString("name");
if(TextUtils.isEmpty(name)) if(TextUtils.isEmpty(name))
continue; continue;
Metadata tagMetadata = TagMetadata.newTagMetadata(model.getId(), remoteId, name, tag.getLong("id")); Metadata tagMetadata = TagMetadata.newTagMetadata(model.getId(), remoteId, name, new BigInteger(tag.getString("id")));
metadata.add(tagMetadata); metadata.add(tagMetadata);
} }
} }

@ -1,16 +1,18 @@
package com.todoroo.astrid.actfm.sync.messages; package com.todoroo.astrid.actfm.sync.messages;
import java.math.BigInteger;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
public class BriefMe<TYPE extends RemoteModel> implements ClientToServerMessage { public class BriefMe<TYPE extends RemoteModel> implements ClientToServerMessage {
private final Class<? extends RemoteModel> modelClass; private final Class<? extends RemoteModel> modelClass;
private final long uuid; private final BigInteger uuid;
private long pushedAt; // TODO: Populate and use private long pushedAt; // TODO: Populate and use
public BriefMe(TYPE entity) { public BriefMe(TYPE entity) {
this.modelClass = entity.getClass(); this.modelClass = entity.getClass();
this.uuid = entity.getValue(RemoteModel.REMOTE_ID_PROPERTY); this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY);
} }
public void sendMessage() { public void sendMessage() {

@ -1,6 +1,7 @@
package com.todoroo.astrid.actfm.sync.messages; package com.todoroo.astrid.actfm.sync.messages;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -22,7 +23,7 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
private final Class<? extends RemoteModel> modelClass; private final Class<? extends RemoteModel> modelClass;
private final Class<OE> outstandingClass; private final Class<OE> outstandingClass;
private final long id; private final long id;
private final long uuid; private final BigInteger uuid;
private final List<OE> changes; private final List<OE> changes;
private long pushedAt; private long pushedAt;
private final OutstandingEntryDao<OE> outstandingDao; private final OutstandingEntryDao<OE> outstandingDao;
@ -35,15 +36,15 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
this.changes = new ArrayList<OE>(); this.changes = new ArrayList<OE>();
this.outstandingDao = outstandingDao; this.outstandingDao = outstandingDao;
if (!entity.containsValue(RemoteModel.REMOTE_ID_PROPERTY) if (!entity.containsValue(RemoteModel.UUID_PROPERTY)
|| !entity.containsValue(RemoteModel.PUSHED_AT_PROPERTY)) { || !entity.containsValue(RemoteModel.PUSHED_AT_PROPERTY)) {
entity = modelDao.fetch(entity.getId(), getModelProperties(modelClass)); entity = modelDao.fetch(entity.getId(), getModelProperties(modelClass));
} }
if (entity == null) { if (entity == null) {
this.uuid = 0; this.uuid = BigInteger.ZERO;
this.pushedAt = 0; this.pushedAt = 0;
} else { } else {
this.uuid = entity.getValue(RemoteModel.REMOTE_ID_PROPERTY); this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY);
this.pushedAt = entity.getValue(RemoteModel.PUSHED_AT_PROPERTY); this.pushedAt = entity.getValue(RemoteModel.PUSHED_AT_PROPERTY);
populateChanges(); populateChanges();
} }

@ -1,15 +1,17 @@
package com.todoroo.astrid.actfm.sync.messages; package com.todoroo.astrid.actfm.sync.messages;
import java.math.BigInteger;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
public class RequestDoubleCheck<TYPE extends RemoteModel> implements ClientToServerMessage { public class RequestDoubleCheck<TYPE extends RemoteModel> implements ClientToServerMessage {
private final Class<? extends RemoteModel> modelClass; private final Class<? extends RemoteModel> modelClass;
private final long uuid; private final BigInteger uuid;
public RequestDoubleCheck(TYPE entity) { public RequestDoubleCheck(TYPE entity) {
this.modelClass = entity.getClass(); this.modelClass = entity.getClass();
this.uuid = entity.getValue(RemoteModel.REMOTE_ID_PROPERTY); this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY);
} }
public void sendMessage() { public void sendMessage() {

@ -481,7 +481,7 @@ public class TasksXmlImporter {
private void saveTags() { private void saveTags() {
if(currentTask != null && tags.size() > 0) { if(currentTask != null && tags.size() > 0) {
TagService.getInstance().synchronizeTags(currentTask.getId(), currentTask.getValue(Task.REMOTE_ID), tags); TagService.getInstance().synchronizeTags(currentTask.getId(), currentTask.getValue(Task.UUID), tags);
} }
tags.clear(); tags.clear();
} }

@ -104,14 +104,14 @@ public class Astrid44SyncMigrator {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "Incomplete linking task " + m.getValue(Metadata.TASK) + " to " + m.getValue(TagMetadata.TAG_NAME)); Log.w(LOG_TAG, "Incomplete linking task " + m.getValue(Metadata.TASK) + " to " + m.getValue(TagMetadata.TAG_NAME));
if (!m.containsNonNullValue(TagMetadata.TASK_UUID) || m.getValue(TagMetadata.TASK_UUID) == 0) { if (!m.containsNonNullValue(TagMetadata.TASK_UUID) || m.getValue(TagMetadata.TASK_UUID).compareTo(BigInteger.ZERO) == 0) {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "No task uuid"); Log.w(LOG_TAG, "No task uuid");
updateTaskUuid(m); updateTaskUuid(m);
changes = true; changes = true;
} }
if (!m.containsNonNullValue(TagMetadata.TAG_UUID) || m.getValue(TagMetadata.TAG_UUID) == 0) { if (!m.containsNonNullValue(TagMetadata.TAG_UUID) || m.getValue(TagMetadata.TAG_UUID).compareTo(BigInteger.ZERO) == 0) {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "No tag uuid"); Log.w(LOG_TAG, "No tag uuid");
updateTagUuid(m); updateTagUuid(m);
@ -154,11 +154,11 @@ public class Astrid44SyncMigrator {
private void updateTaskUuid(Metadata m) { private void updateTaskUuid(Metadata m) {
long taskId = m.getValue(Metadata.TASK); long taskId = m.getValue(Metadata.TASK);
Task task = taskDao.fetch(taskId, Task.REMOTE_ID); Task task = taskDao.fetch(taskId, Task.UUID);
if (task != null) { if (task != null) {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "Linking with task uuid " + task.getValue(Task.REMOTE_ID)); Log.w(LOG_TAG, "Linking with task uuid " + task.getValue(Task.UUID));
m.setValue(TagMetadata.TASK_UUID, task.getValue(Task.REMOTE_ID)); m.setValue(TagMetadata.TASK_UUID, task.getValue(Task.UUID));
} else { } else {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "Task not found, deleting link"); Log.w(LOG_TAG, "Task not found, deleting link");
@ -168,11 +168,11 @@ public class Astrid44SyncMigrator {
private void updateTagUuid(Metadata m) { private void updateTagUuid(Metadata m) {
String tag = m.getValue(TagMetadata.TAG_NAME); String tag = m.getValue(TagMetadata.TAG_NAME);
TagData tagData = tagDataService.getTag(tag, TagData.REMOTE_ID); TagData tagData = tagDataService.getTag(tag, TagData.UUID);
if (tagData != null) { if (tagData != null) {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "Linking with tag uuid " + tagData.getValue(TagData.REMOTE_ID)); Log.w(LOG_TAG, "Linking with tag uuid " + tagData.getValue(TagData.UUID));
m.setValue(TagMetadata.TAG_UUID, tagData.getValue(TagData.REMOTE_ID)); m.setValue(TagMetadata.TAG_UUID, tagData.getValue(TagData.UUID));
} else { } else {
if (Constants.DEBUG) if (Constants.DEBUG)
Log.w(LOG_TAG, "Tag not found, deleting link"); Log.w(LOG_TAG, "Tag not found, deleting link");

@ -5,6 +5,7 @@
*/ */
package com.todoroo.astrid.tags; package com.todoroo.astrid.tags;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -73,12 +74,12 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(Metadata.KEY.name, TagMetadata.KEY); contentValues.put(Metadata.KEY.name, TagMetadata.KEY);
contentValues.put(TagMetadata.TAG_NAME.name, tag.tag); contentValues.put(TagMetadata.TAG_NAME.name, tag.tag);
contentValues.put(TagMetadata.TAG_UUID.name, tag.remoteId); contentValues.put(TagMetadata.TAG_UUID.name, tag.uuid.toString());
FilterWithUpdate filter = new FilterWithUpdate(tag.tag, FilterWithUpdate filter = new FilterWithUpdate(tag.tag,
title, tagTemplate, title, tagTemplate,
contentValues); contentValues);
if(tag.remoteId > 0) { if(BigInteger.ZERO.compareTo(tag.uuid) != 0) {
filter.listingTitle += " (" + tag.count + ")"; filter.listingTitle += " (" + tag.count + ")";
if(tag.count == 0) if(tag.count == 0)
filter.color = Color.GRAY; filter.color = Color.GRAY;
@ -109,7 +110,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
filter.imageUrl = tag.image; filter.imageUrl = tag.image;
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag); extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putLong(TagViewFragment.EXTRA_TAG_REMOTE_ID, tag.remoteId); extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.uuid.toString());
filter.customExtras = extras; filter.customExtras = extras;
return filter; return filter;

@ -1,5 +1,8 @@
package com.todoroo.astrid.tags; package com.todoroo.astrid.tags;
import java.math.BigInteger;
import com.todoroo.andlib.data.Property.BigIntegerProperty;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
@ -14,11 +17,11 @@ public class TagMetadata {
public static final StringProperty TAG_NAME = Metadata.VALUE1; public static final StringProperty TAG_NAME = Metadata.VALUE1;
/** Tag uuid */ /** Tag uuid */
public static final LongProperty TAG_UUID = new LongProperty( public static final BigIntegerProperty TAG_UUID = new BigIntegerProperty(
Metadata.TABLE, Metadata.VALUE2.name); Metadata.TABLE, Metadata.VALUE2.name);
/** Task uuid */ /** Task uuid */
public static final LongProperty TASK_UUID = new LongProperty( public static final BigIntegerProperty TASK_UUID = new BigIntegerProperty(
Metadata.TABLE, Metadata.VALUE3.name); Metadata.TABLE, Metadata.VALUE3.name);
/** Pushed at time */ /** Pushed at time */
@ -37,11 +40,11 @@ public class TagMetadata {
* @param tagUuid * @param tagUuid
* @return * @return
*/ */
public static Metadata newTagMetadata(Task task, String tagName, long tagUuid) { public static Metadata newTagMetadata(Task task, String tagName, BigInteger tagUuid) {
return newTagMetadata(task.getId(), task.getValue(Task.REMOTE_ID), tagName, tagUuid); return newTagMetadata(task.getId(), task.getValue(Task.UUID), tagName, tagUuid);
} }
public static Metadata newTagMetadata(long taskId, long taskUuid, String tagName, long tagUuid) { public static Metadata newTagMetadata(long taskId, BigInteger taskUuid, String tagName, BigInteger tagUuid) {
Metadata link = new Metadata(); Metadata link = new Metadata();
link.setValue(Metadata.KEY, KEY); link.setValue(Metadata.KEY, KEY);
link.setValue(Metadata.TASK, taskId); link.setValue(Metadata.TASK, taskId);

@ -5,6 +5,7 @@
*/ */
package com.todoroo.astrid.tags; package com.todoroo.astrid.tags;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -104,13 +105,15 @@ public final class TagService {
public String tag; public String tag;
public int count; public int count;
public long id; public long id;
public long remoteId; public BigInteger uuid;
public String image; public String image;
public long userId; public long userId;
public long memberCount; public long memberCount;
public static Tag tagFromRemoteId(long remoteId) { @Deprecated public long remoteId;
TodorooCursor<TagData> tagData = PluginServices.getTagDataService().query(Query.select(TagData.PROPERTIES).where(TagData.REMOTE_ID.eq(remoteId)));
public static Tag tagFromUUID(BigInteger uuid) {
TodorooCursor<TagData> tagData = PluginServices.getTagDataService().query(Query.select(TagData.PROPERTIES).where(TagData.UUID.eq(uuid)));
try { try {
if (tagData.getCount() > 0) { if (tagData.getCount() > 0) {
tagData.moveToFirst(); tagData.moveToFirst();
@ -129,6 +132,7 @@ public final class TagService {
tag = tagData.getValue(TagData.NAME); tag = tagData.getValue(TagData.NAME);
count = tagData.getValue(TagData.TASK_COUNT); count = tagData.getValue(TagData.TASK_COUNT);
remoteId = tagData.getValue(TagData.REMOTE_ID); remoteId = tagData.getValue(TagData.REMOTE_ID);
uuid = tagData.getValue(TagData.UUID);
image = tagData.getValue(TagData.PICTURE); image = tagData.getValue(TagData.PICTURE);
userId = tagData.getValue(TagData.USER_ID); userId = tagData.getValue(TagData.USER_ID);
memberCount = tagData.getValue(TagData.MEMBER_COUNT); memberCount = tagData.getValue(TagData.MEMBER_COUNT);
@ -148,10 +152,10 @@ public final class TagService {
public QueryTemplate queryTemplate(Criterion criterion) { public QueryTemplate queryTemplate(Criterion criterion) {
Criterion fullCriterion = Criterion.and( Criterion fullCriterion = Criterion.and(
Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY), Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY),
Field.field("mtags." + TagMetadata.TAG_UUID.name).eq(remoteId), Field.field("mtags." + TagMetadata.TAG_UUID.name).eq(uuid),
Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0), Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0),
criterion); criterion);
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.REMOTE_ID.eq(Field.field("mtags." + TagMetadata.TASK_UUID.name)))) return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.UUID.eq(Field.field("mtags." + TagMetadata.TASK_UUID.name))))
.where(fullCriterion); .where(fullCriterion);
} }
@ -208,7 +212,7 @@ public final class TagService {
ArrayList<Tag> array = new ArrayList<Tag>(); ArrayList<Tag> array = new ArrayList<Tag>();
for (int i = 0; i < cursor.getCount(); i++) { for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext(); cursor.moveToNext();
Tag tag = Tag.tagFromRemoteId(cursor.get(TagMetadata.TAG_UUID)); Tag tag = Tag.tagFromUUID(cursor.get(TagMetadata.TAG_UUID));
if (tag != null) if (tag != null)
array.add(tag); array.add(tag);
} }
@ -236,7 +240,7 @@ public final class TagService {
} }
public void createLink(Task task, String tagName) { public void createLink(Task task, String tagName) {
TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.REMOTE_ID) TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.UUID)
.where(TagData.NAME.eqCaseInsensitive(tagName))); .where(TagData.NAME.eqCaseInsensitive(tagName)));
try { try {
TagData tagData; TagData tagData;
@ -247,16 +251,16 @@ public final class TagService {
} else { } else {
tagData = new TagData(existingTag); tagData = new TagData(existingTag);
} }
createLink(task, tagData.getValue(TagData.NAME), tagData.getValue(TagData.REMOTE_ID)); createLink(task, tagData.getValue(TagData.NAME), tagData.getValue(TagData.UUID));
} finally { } finally {
existingTag.close(); existingTag.close();
} }
} }
public void createLink(Task task, String tagName, long tagUuid) { public void createLink(Task task, String tagName, BigInteger tagUuid) {
TodorooCursor<Metadata> existing = metadataDao.query(Query.select(Metadata.PROPERTIES) TodorooCursor<Metadata> existing = metadataDao.query(Query.select(Metadata.PROPERTIES)
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY), .where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
TagMetadata.TASK_UUID.eq(task.getValue(Task.REMOTE_ID)), TagMetadata.TASK_UUID.eq(task.getValue(Task.UUID)),
TagMetadata.TAG_UUID.eq(tagUuid), TagMetadata.TAG_UUID.eq(tagUuid),
Metadata.DELETION_DATE.eq(0)))); Metadata.DELETION_DATE.eq(0))));
try { try {
@ -416,8 +420,8 @@ public final class TagService {
* @param taskId * @param taskId
* @param tags * @param tags
*/ */
public boolean synchronizeTags(long taskId, long taskUuid, Set<String> tags) { public boolean synchronizeTags(long taskId, BigInteger taskUuid, Set<String> tags) {
HashSet<Long> existingLinks = new HashSet<Long>(); HashSet<BigInteger> existingLinks = new HashSet<BigInteger>();
TodorooCursor<Metadata> links = metadataDao.query(Query.select(Metadata.PROPERTIES) TodorooCursor<Metadata> links = metadataDao.query(Query.select(Metadata.PROPERTIES)
.where(Criterion.and(TagMetadata.TASK_UUID.eq(taskUuid), Metadata.DELETION_DATE.eq(0)))); .where(Criterion.and(TagMetadata.TASK_UUID.eq(taskUuid), Metadata.DELETION_DATE.eq(0))));
try { try {
@ -430,16 +434,16 @@ public final class TagService {
} }
for (String tag : tags) { for (String tag : tags) {
TagData tagData = getTagDataWithCase(tag, TagData.NAME, TagData.REMOTE_ID); TagData tagData = getTagDataWithCase(tag, TagData.NAME, TagData.UUID);
if (tagData == null) { if (tagData == null) {
tagData = new TagData(); tagData = new TagData();
tagData.setValue(TagData.NAME, tag); tagData.setValue(TagData.NAME, tag);
tagDataService.save(tagData); tagDataService.save(tagData);
} }
if (existingLinks.contains(tagData.getValue(TagData.REMOTE_ID))) { if (existingLinks.contains(tagData.getValue(TagData.UUID))) {
existingLinks.remove(tagData.getValue(TagData.REMOTE_ID)); existingLinks.remove(tagData.getValue(TagData.UUID));
} else { } else {
Metadata newLink = TagMetadata.newTagMetadata(taskId, taskUuid, tag, tagData.getValue(TagData.REMOTE_ID)); Metadata newLink = TagMetadata.newTagMetadata(taskId, taskUuid, tag, tagData.getValue(TagData.UUID));
metadataDao.createNew(newLink); metadataDao.createNew(newLink);
} }
} }

@ -289,7 +289,7 @@ public final class TagsControlSet extends PopupControlSet {
LinkedHashSet<String> tags = getTagSet(); LinkedHashSet<String> tags = getTagSet();
if(TagService.getInstance().synchronizeTags(task.getId(), task.getValue(Task.REMOTE_ID), tags)) { if(TagService.getInstance().synchronizeTags(task.getId(), task.getValue(Task.UUID), tags)) {
Flags.set(Flags.TAGS_CHANGED); Flags.set(Flags.TAGS_CHANGED);
task.setValue(Task.MODIFICATION_DATE, DateUtilities.now()); task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
} }

@ -48,7 +48,7 @@ public class FeaturedListFilterExposer extends TagFilterExposer {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(Metadata.KEY.name, TagMetadata.KEY); contentValues.put(Metadata.KEY.name, TagMetadata.KEY);
contentValues.put(TagMetadata.TAG_NAME.name, tag.tag); contentValues.put(TagMetadata.TAG_NAME.name, tag.tag);
contentValues.put(TagMetadata.TAG_UUID.name, tag.remoteId); contentValues.put(TagMetadata.TAG_UUID.name, tag.uuid.toString());
FilterWithUpdate filter = new FilterWithUpdate(tag.tag, FilterWithUpdate filter = new FilterWithUpdate(tag.tag,
title, tagTemplate, title, tagTemplate,
@ -61,7 +61,7 @@ public class FeaturedListFilterExposer extends TagFilterExposer {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag); extras.putString(TagViewFragment.EXTRA_TAG_NAME, tag.tag);
extras.putLong(TagViewFragment.EXTRA_TAG_REMOTE_ID, tag.remoteId); extras.putString(TagViewFragment.EXTRA_TAG_UUID, tag.uuid.toString());
filter.customExtras = extras; filter.customExtras = extras;
return filter; return filter;

@ -146,7 +146,7 @@ public class FeaturedTaskListFragment extends TagViewFragment {
Task t = new Task(); Task t = new Task();
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
t.readFromCursor(tasks); t.readFromCursor(tasks);
taskService.cloneReusableTask(t, localName, finalTagData.getValue(TagData.REMOTE_ID)); taskService.cloneReusableTask(t, localName, finalTagData.getValue(TagData.UUID));
} }
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null) { if (activity != null) {

@ -1,5 +1,6 @@
package com.todoroo.astrid.tags.reusable; package com.todoroo.astrid.tags.reusable;
import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import android.content.Context; import android.content.Context;
@ -49,7 +50,7 @@ public class ReusableTaskAdapter extends TaskAdapter {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
ReusableTaskViewHolder holder = (ReusableTaskViewHolder) v.getTag(); ReusableTaskViewHolder holder = (ReusableTaskViewHolder) v.getTag();
taskService.cloneReusableTask(holder.task, null, 0L); taskService.cloneReusableTask(holder.task, null, BigInteger.ZERO);
Toast.makeText(fragment.getActivity(), R.string.actfm_feat_list_task_clone_success, Toast.LENGTH_LONG).show(); Toast.makeText(fragment.getActivity(), R.string.actfm_feat_list_task_clone_success, Toast.LENGTH_LONG).show();
Flags.set(Flags.REFRESH); Flags.set(Flags.REFRESH);
} }

@ -1163,7 +1163,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
@Override @Override
public void onPrepareOptionsMenu (Menu menu) { public void onPrepareOptionsMenu (Menu menu) {
if(actFmPreferenceService.isLoggedIn() && remoteId.compareTo(BigInteger.ZERO) != 0 && menu.findItem(MENU_COMMENTS_REFRESH_ID) == null) { if(actFmPreferenceService.isLoggedIn() && BigInteger.ZERO.compareTo(remoteId) != 0 && menu.findItem(MENU_COMMENTS_REFRESH_ID) == null) {
MenuItem item = menu.add(Menu.NONE, MENU_COMMENTS_REFRESH_ID, Menu.NONE, MenuItem item = menu.add(Menu.NONE, MENU_COMMENTS_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments); R.string.ENA_refresh_comments);
item.setIcon(R.drawable.icn_menu_refresh_dark); item.setIcon(R.drawable.icn_menu_refresh_dark);

@ -147,7 +147,7 @@ public class TagDataService {
return updateDao.query(Query.select(Update.PROPERTIES).where( return updateDao.query(Query.select(Update.PROPERTIES).where(
criterion). criterion).
orderBy(Order.desc(Update.CREATION_DATE))); orderBy(Order.desc(Update.CREATION_DATE)));
if(tagData.getValue(TagData.UUID).equals(BigInteger.ZERO)) if(BigInteger.ZERO.compareTo(tagData.getValue(TagData.UUID)) == 0)
return updateDao.query(Query.select(Update.PROPERTIES).where(Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%"))); return updateDao.query(Query.select(Update.PROPERTIES).where(Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")));
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.and(criterion, return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.and(criterion,
Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"), Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"),
@ -161,7 +161,7 @@ public class TagDataService {
* @return * @return
*/ */
public Update getLatestUpdate(TagData tagData) { public Update getLatestUpdate(TagData tagData) {
if(tagData.getValue(TagData.UUID).equals(BigInteger.ZERO)) if(BigInteger.ZERO.compareTo(tagData.getValue(TagData.UUID)) == 0)
return null; return null;
@SuppressWarnings("nls") @SuppressWarnings("nls")

@ -193,7 +193,7 @@ public class TaskService {
return newTask; return newTask;
} }
public Task cloneReusableTask(Task task, String tagName, long tagUuid) { public Task cloneReusableTask(Task task, String tagName, BigInteger tagUuid) {
Task newTask = fetchById(task.getId(), Task.PROPERTIES); Task newTask = fetchById(task.getId(), Task.PROPERTIES);
if (newTask == null) if (newTask == null)
return new Task(); return new Task();
@ -205,7 +205,7 @@ public class TaskService {
taskDao.save(newTask); taskDao.save(newTask);
if (tagUuid > 0) { if (BigInteger.ZERO.compareTo(tagUuid) != 0) {
TagService.getInstance().createLink(task, tagName, tagUuid); TagService.getInstance().createLink(task, tagName, tagUuid);
} }
return newTask; return newTask;
@ -535,7 +535,7 @@ public class TaskService {
metadata.setValue(Metadata.TASK, task.getId()); metadata.setValue(Metadata.TASK, task.getId());
metadata.mergeWith(forMetadata); metadata.mergeWith(forMetadata);
if (TagMetadata.KEY.equals(metadata.getValue(Metadata.KEY))) { if (TagMetadata.KEY.equals(metadata.getValue(Metadata.KEY))) {
if (metadata.containsNonNullValue(TagMetadata.TAG_UUID) && metadata.getValue(TagMetadata.TAG_UUID) != 0) { if (metadata.containsNonNullValue(TagMetadata.TAG_UUID) && BigInteger.ZERO.compareTo(metadata.getValue(TagMetadata.TAG_UUID)) != 0) {
// This is more efficient // This is more efficient
TagService.getInstance().createLink(task, metadata.getValue(TagMetadata.TAG_NAME), metadata.getValue(TagMetadata.TAG_UUID)); TagService.getInstance().createLink(task, metadata.getValue(TagMetadata.TAG_NAME), metadata.getValue(TagMetadata.TAG_UUID));
} else { } else {

Loading…
Cancel
Save