From 17e126f487e600f65486d10a87b5c58dbeede57c Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 1 Oct 2012 13:35:05 -0700 Subject: [PATCH] Updated all references to REMOTE_ID in astrid/src to refer to UUID instead --- .../astrid/activity/TaskEditFragment.java | 19 ++++++------ .../todoroo/astrid/adapter/UpdateAdapter.java | 3 +- .../src/com/todoroo/astrid/dao/Database.java | 2 +- .../src/com/todoroo/astrid/dao/TaskDao.java | 29 ++++++++++--------- .../astrid/service/TagDataService.java | 10 ++++--- .../todoroo/astrid/service/TaskService.java | 11 ++++--- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java index 377ea6757..cb43dd196 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java @@ -7,6 +7,7 @@ package com.todoroo.astrid.activity; import java.io.File; import java.io.FileOutputStream; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -143,7 +144,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { /** * Task remote id (during orientation change) */ - private static final String TASK_REMOTE_ID = "task_remote_id"; //$NON-NLS-1$ + private static final String TASK_UUID = "task_uuid"; //$NON-NLS-1$ /** * Token for saving a bitmap in the intent before it has been added with a comment @@ -258,7 +259,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { private boolean overrideFinishAnim; - private long remoteId = 0; + private BigInteger remoteId = BigInteger.ZERO; private WebServicesView webServices = null; @@ -301,8 +302,8 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { if (task != null) { model = task; } - if (savedInstanceState.containsKey(TASK_REMOTE_ID)) { - remoteId = savedInstanceState.getLong(TASK_REMOTE_ID); + if (savedInstanceState.containsKey(TASK_UUID)) { + remoteId = new BigInteger(savedInstanceState.getString(TASK_UUID)); } } @@ -731,8 +732,8 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { long idParam = intent.getLongExtra(TOKEN_ID, -1L); if (idParam > -1L) { model = taskService.fetchById(idParam, Task.PROPERTIES); - if (model != null && model.containsNonNullValue(Task.REMOTE_ID)) { - remoteId = model.getValue(Task.REMOTE_ID); + if (model != null && model.containsNonNullValue(Task.UUID)) { + remoteId = model.getValue(Task.UUID); } } @@ -789,7 +790,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { /** Convenience method to populate fields after setting model to null */ public void repopulateFromScratch(Intent intent) { model = null; - remoteId = 0; + remoteId = BigInteger.ZERO; populateFields(intent); if (webServices != null) { webServices.setTask(model); @@ -1162,7 +1163,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { @Override public void onPrepareOptionsMenu (Menu menu) { - if(actFmPreferenceService.isLoggedIn() && remoteId > 0 && menu.findItem(MENU_COMMENTS_REFRESH_ID) == null) { + if(actFmPreferenceService.isLoggedIn() && remoteId.compareTo(BigInteger.ZERO) != 0 && menu.findItem(MENU_COMMENTS_REFRESH_ID) == null) { MenuItem item = menu.add(Menu.NONE, MENU_COMMENTS_REFRESH_ID, Menu.NONE, R.string.ENA_refresh_comments); item.setIcon(R.drawable.icn_menu_refresh_dark); @@ -1231,7 +1232,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { // stick our task into the outState outState.putParcelable(TASK_IN_PROGRESS, model); - outState.putLong(TASK_REMOTE_ID, remoteId); + outState.putString(TASK_UUID, remoteId.toString()); } @Override diff --git a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java index 1b7ada820..aa8f40fee 100644 --- a/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/UpdateAdapter.java @@ -6,6 +6,7 @@ package com.todoroo.astrid.adapter; import java.io.IOException; +import java.math.BigInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -361,7 +362,7 @@ public class UpdateAdapter extends CursorAdapter { if (TASK_LINK_TYPE.equals(linkType)) { long taskId = update.getValue(Update.TASK_LOCAL); if (taskId <= 0) { - Task local = PluginServices.getTaskService().fetchByRemoteId(update.getValue(Update.TASK), Task.ID); + Task local = PluginServices.getTaskService().fetchByRemoteId(BigInteger.valueOf(update.getValue(Update.TASK)), Task.ID); if (local != null) taskId = local.getId(); } diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index e1bee13f0..dedcb32ca 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -156,7 +156,7 @@ public class Database extends AbstractDatabase { sql.append("CREATE UNIQUE INDEX IF NOT EXISTS t_rid ON "). append(Task.TABLE).append('('). - append(Task.REMOTE_ID.name). + append(Task.UUID.name). append(')'); database.execSQL(sql.toString()); sql.setLength(0); diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index feab58e9d..3119ae0f4 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -5,6 +5,8 @@ */ package com.todoroo.astrid.dao; +import java.math.BigInteger; + import android.content.ContentValues; import android.content.Context; import android.content.Intent; @@ -199,7 +201,7 @@ public class TaskDao extends RemoteModelDao { public boolean handleSQLiteConstraintException(Task task) { TodorooCursor cursor = query(Query.select(Task.ID).where( - Task.REMOTE_ID.eq(task.getValue(Task.REMOTE_ID)))); + Task.UUID.eq(task.getValue(Task.UUID)))); if (cursor.getCount() > 0) { cursor.moveToFirst(); task.setId(cursor.get(Task.ID)); @@ -304,7 +306,7 @@ public class TaskDao extends RemoteModelDao { private static final Property[] SQL_CONSTRAINT_MERGE_PROPERTIES = new Property[] { Task.ID, - Task.REMOTE_ID, + Task.UUID, Task.TITLE, Task.IMPORTANCE, Task.DUE_DATE, @@ -336,31 +338,31 @@ public class TaskDao extends RemoteModelDao { try { saveExisting(item); } catch (SQLiteConstraintException e) { - Long remoteId = item.getValue(Task.REMOTE_ID); - TodorooCursor tasksWithRemoteId = query(Query.select( + BigInteger uuid = item.getValue(Task.UUID); + TodorooCursor tasksWithUUID = query(Query.select( SQL_CONSTRAINT_MERGE_PROPERTIES).where( - Task.REMOTE_ID.eq(remoteId))); + Task.UUID.eq(uuid))); try { - if (tasksWithRemoteId.getCount() > 0) { + if (tasksWithUUID.getCount() > 0) { Task curr = new Task(); - for (tasksWithRemoteId.moveToFirst(); - !tasksWithRemoteId.isAfterLast(); tasksWithRemoteId.moveToNext()) { - curr.readFromCursor(tasksWithRemoteId); + for (tasksWithUUID.moveToFirst(); + !tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) { + curr.readFromCursor(tasksWithUUID); if (curr.getId() == item.getId()) continue; compareAndMergeAfterConflict(curr, fetch(item.getId(), - tasksWithRemoteId.getProperties())); + tasksWithUUID.getProperties())); return; } } else { // We probably want to know about this case, because // it means that the constraint error isn't caused by - // REMOTE_ID + // UUID throw e; } } finally { - tasksWithRemoteId.close(); + tasksWithUUID.close(); } } } @@ -379,7 +381,8 @@ public class TaskDao extends RemoteModelDao { if (!match) { if (existing.getValue(Task.CREATION_DATE).equals(newConflict.getValue(Task.CREATION_DATE))) newConflict.setValue(Task.CREATION_DATE, newConflict.getValue(Task.CREATION_DATE) + 1000L); - newConflict.clearValue(Task.REMOTE_ID); + newConflict.clearValue(Task.UUID); + newConflict.clearValue(Task.PROOF_TEXT); saveExisting(newConflict); } else { delete(newConflict.getId()); diff --git a/astrid/src/com/todoroo/astrid/service/TagDataService.java b/astrid/src/com/todoroo/astrid/service/TagDataService.java index f97777b26..51451cd82 100644 --- a/astrid/src/com/todoroo/astrid/service/TagDataService.java +++ b/astrid/src/com/todoroo/astrid/service/TagDataService.java @@ -5,6 +5,8 @@ */ package com.todoroo.astrid.service; +import java.math.BigInteger; + import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; @@ -145,10 +147,10 @@ public class TagDataService { return updateDao.query(Query.select(Update.PROPERTIES).where( criterion). orderBy(Order.desc(Update.CREATION_DATE))); - if(tagData.getValue(TagData.REMOTE_ID) == 0) + if(tagData.getValue(TagData.UUID).equals(BigInteger.ZERO)) 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, - Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.REMOTE_ID) + ",%"), + Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"), Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))). orderBy(Order.desc(Update.CREATION_DATE))); } @@ -159,12 +161,12 @@ public class TagDataService { * @return */ public Update getLatestUpdate(TagData tagData) { - if(tagData.getValue(TagData.REMOTE_ID) == 0) + if(tagData.getValue(TagData.UUID).equals(BigInteger.ZERO)) return null; @SuppressWarnings("nls") TodorooCursor updates = updateDao.query(Query.select(Update.PROPERTIES).where( - Update.TAGS.like("%," + tagData.getValue(TagData.REMOTE_ID) + ",%")). + Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%")). orderBy(Order.desc(Update.CREATION_DATE)).limit(1)); try { if(updates.getCount() == 0) diff --git a/astrid/src/com/todoroo/astrid/service/TaskService.java b/astrid/src/com/todoroo/astrid/service/TaskService.java index bfeafafbe..7f77eadce 100644 --- a/astrid/src/com/todoroo/astrid/service/TaskService.java +++ b/astrid/src/com/todoroo/astrid/service/TaskService.java @@ -5,6 +5,7 @@ */ package com.todoroo.astrid.service; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -104,8 +105,8 @@ public class TaskService { * @param properties * @return item, or null if it doesn't exist */ - public Task fetchByRemoteId(long remoteId, Property... properties) { - TodorooCursor task = query(Query.select(properties).where(Task.REMOTE_ID.eq(remoteId))); + public Task fetchByRemoteId(BigInteger uuid, Property... properties) { + TodorooCursor task = query(Query.select(properties).where(Task.UUID.eq(uuid))); try { if (task.getCount() > 0) { task.moveToFirst(); @@ -153,7 +154,8 @@ public class TaskService { if(newTask == null) return new Task(); newTask.clearValue(Task.ID); - newTask.clearValue(Task.REMOTE_ID); + newTask.clearValue(Task.UUID); + newTask.clearValue(Task.PROOF_TEXT); TodorooCursor cursor = metadataDao.query( Query.select(Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId()))); try { @@ -196,7 +198,8 @@ public class TaskService { if (newTask == null) return new Task(); newTask.clearValue(Task.ID); - newTask.clearValue(Task.REMOTE_ID); + newTask.clearValue(Task.UUID); + newTask.clearValue(Task.PROOF_TEXT); newTask.clearValue(Task.USER); newTask.clearValue(Task.USER_ID);