Updated all references to REMOTE_ID in astrid/src to refer to UUID instead

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

@ -7,6 +7,7 @@ package com.todoroo.astrid.activity;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
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;
@ -143,7 +144,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
/** /**
* Task remote id (during orientation change) * 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 * 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 boolean overrideFinishAnim;
private long remoteId = 0; private BigInteger remoteId = BigInteger.ZERO;
private WebServicesView webServices = null; private WebServicesView webServices = null;
@ -301,8 +302,8 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
if (task != null) { if (task != null) {
model = task; model = task;
} }
if (savedInstanceState.containsKey(TASK_REMOTE_ID)) { if (savedInstanceState.containsKey(TASK_UUID)) {
remoteId = savedInstanceState.getLong(TASK_REMOTE_ID); remoteId = new BigInteger(savedInstanceState.getString(TASK_UUID));
} }
} }
@ -731,8 +732,8 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
long idParam = intent.getLongExtra(TOKEN_ID, -1L); long idParam = intent.getLongExtra(TOKEN_ID, -1L);
if (idParam > -1L) { if (idParam > -1L) {
model = taskService.fetchById(idParam, Task.PROPERTIES); model = taskService.fetchById(idParam, Task.PROPERTIES);
if (model != null && model.containsNonNullValue(Task.REMOTE_ID)) { if (model != null && model.containsNonNullValue(Task.UUID)) {
remoteId = model.getValue(Task.REMOTE_ID); remoteId = model.getValue(Task.UUID);
} }
} }
@ -789,7 +790,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
/** Convenience method to populate fields after setting model to null */ /** Convenience method to populate fields after setting model to null */
public void repopulateFromScratch(Intent intent) { public void repopulateFromScratch(Intent intent) {
model = null; model = null;
remoteId = 0; remoteId = BigInteger.ZERO;
populateFields(intent); populateFields(intent);
if (webServices != null) { if (webServices != null) {
webServices.setTask(model); webServices.setTask(model);
@ -1162,7 +1163,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
@Override @Override
public void onPrepareOptionsMenu (Menu menu) { 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, 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);
@ -1231,7 +1232,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// stick our task into the outState // stick our task into the outState
outState.putParcelable(TASK_IN_PROGRESS, model); outState.putParcelable(TASK_IN_PROGRESS, model);
outState.putLong(TASK_REMOTE_ID, remoteId); outState.putString(TASK_UUID, remoteId.toString());
} }
@Override @Override

@ -6,6 +6,7 @@
package com.todoroo.astrid.adapter; package com.todoroo.astrid.adapter;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -361,7 +362,7 @@ public class UpdateAdapter extends CursorAdapter {
if (TASK_LINK_TYPE.equals(linkType)) { if (TASK_LINK_TYPE.equals(linkType)) {
long taskId = update.getValue(Update.TASK_LOCAL); long taskId = update.getValue(Update.TASK_LOCAL);
if (taskId <= 0) { 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) if (local != null)
taskId = local.getId(); taskId = local.getId();
} }

@ -156,7 +156,7 @@ public class Database extends AbstractDatabase {
sql.append("CREATE UNIQUE INDEX IF NOT EXISTS t_rid ON "). sql.append("CREATE UNIQUE INDEX IF NOT EXISTS t_rid ON ").
append(Task.TABLE).append('('). append(Task.TABLE).append('(').
append(Task.REMOTE_ID.name). append(Task.UUID.name).
append(')'); append(')');
database.execSQL(sql.toString()); database.execSQL(sql.toString());
sql.setLength(0); sql.setLength(0);

@ -5,6 +5,8 @@
*/ */
package com.todoroo.astrid.dao; package com.todoroo.astrid.dao;
import java.math.BigInteger;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -199,7 +201,7 @@ public class TaskDao extends RemoteModelDao<Task> {
public boolean handleSQLiteConstraintException(Task task) { public boolean handleSQLiteConstraintException(Task task) {
TodorooCursor<Task> cursor = query(Query.select(Task.ID).where( TodorooCursor<Task> 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) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();
task.setId(cursor.get(Task.ID)); task.setId(cursor.get(Task.ID));
@ -304,7 +306,7 @@ public class TaskDao extends RemoteModelDao<Task> {
private static final Property<?>[] SQL_CONSTRAINT_MERGE_PROPERTIES = new Property<?>[] { private static final Property<?>[] SQL_CONSTRAINT_MERGE_PROPERTIES = new Property<?>[] {
Task.ID, Task.ID,
Task.REMOTE_ID, Task.UUID,
Task.TITLE, Task.TITLE,
Task.IMPORTANCE, Task.IMPORTANCE,
Task.DUE_DATE, Task.DUE_DATE,
@ -336,31 +338,31 @@ public class TaskDao extends RemoteModelDao<Task> {
try { try {
saveExisting(item); saveExisting(item);
} catch (SQLiteConstraintException e) { } catch (SQLiteConstraintException e) {
Long remoteId = item.getValue(Task.REMOTE_ID); BigInteger uuid = item.getValue(Task.UUID);
TodorooCursor<Task> tasksWithRemoteId = query(Query.select( TodorooCursor<Task> tasksWithUUID = query(Query.select(
SQL_CONSTRAINT_MERGE_PROPERTIES).where( SQL_CONSTRAINT_MERGE_PROPERTIES).where(
Task.REMOTE_ID.eq(remoteId))); Task.UUID.eq(uuid)));
try { try {
if (tasksWithRemoteId.getCount() > 0) { if (tasksWithUUID.getCount() > 0) {
Task curr = new Task(); Task curr = new Task();
for (tasksWithRemoteId.moveToFirst(); for (tasksWithUUID.moveToFirst();
!tasksWithRemoteId.isAfterLast(); tasksWithRemoteId.moveToNext()) { !tasksWithUUID.isAfterLast(); tasksWithUUID.moveToNext()) {
curr.readFromCursor(tasksWithRemoteId); curr.readFromCursor(tasksWithUUID);
if (curr.getId() == item.getId()) if (curr.getId() == item.getId())
continue; continue;
compareAndMergeAfterConflict(curr, fetch(item.getId(), compareAndMergeAfterConflict(curr, fetch(item.getId(),
tasksWithRemoteId.getProperties())); tasksWithUUID.getProperties()));
return; return;
} }
} else { } else {
// We probably want to know about this case, because // We probably want to know about this case, because
// it means that the constraint error isn't caused by // it means that the constraint error isn't caused by
// REMOTE_ID // UUID
throw e; throw e;
} }
} finally { } finally {
tasksWithRemoteId.close(); tasksWithUUID.close();
} }
} }
} }
@ -379,7 +381,8 @@ public class TaskDao extends RemoteModelDao<Task> {
if (!match) { if (!match) {
if (existing.getValue(Task.CREATION_DATE).equals(newConflict.getValue(Task.CREATION_DATE))) if (existing.getValue(Task.CREATION_DATE).equals(newConflict.getValue(Task.CREATION_DATE)))
newConflict.setValue(Task.CREATION_DATE, newConflict.getValue(Task.CREATION_DATE) + 1000L); 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); saveExisting(newConflict);
} else { } else {
delete(newConflict.getId()); delete(newConflict.getId());

@ -5,6 +5,8 @@
*/ */
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.math.BigInteger;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
@ -145,10 +147,10 @@ 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.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(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.REMOTE_ID) + ",%"), Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.UUID) + ",%"),
Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))). Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))).
orderBy(Order.desc(Update.CREATION_DATE))); orderBy(Order.desc(Update.CREATION_DATE)));
} }
@ -159,12 +161,12 @@ public class TagDataService {
* @return * @return
*/ */
public Update getLatestUpdate(TagData tagData) { public Update getLatestUpdate(TagData tagData) {
if(tagData.getValue(TagData.REMOTE_ID) == 0) if(tagData.getValue(TagData.UUID).equals(BigInteger.ZERO))
return null; return null;
@SuppressWarnings("nls") @SuppressWarnings("nls")
TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where( TodorooCursor<Update> 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)); orderBy(Order.desc(Update.CREATION_DATE)).limit(1));
try { try {
if(updates.getCount() == 0) if(updates.getCount() == 0)

@ -5,6 +5,7 @@
*/ */
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -104,8 +105,8 @@ public class TaskService {
* @param properties * @param properties
* @return item, or null if it doesn't exist * @return item, or null if it doesn't exist
*/ */
public Task fetchByRemoteId(long remoteId, Property<?>... properties) { public Task fetchByRemoteId(BigInteger uuid, Property<?>... properties) {
TodorooCursor<Task> task = query(Query.select(properties).where(Task.REMOTE_ID.eq(remoteId))); TodorooCursor<Task> task = query(Query.select(properties).where(Task.UUID.eq(uuid)));
try { try {
if (task.getCount() > 0) { if (task.getCount() > 0) {
task.moveToFirst(); task.moveToFirst();
@ -153,7 +154,8 @@ public class TaskService {
if(newTask == null) if(newTask == null)
return new Task(); return new Task();
newTask.clearValue(Task.ID); newTask.clearValue(Task.ID);
newTask.clearValue(Task.REMOTE_ID); newTask.clearValue(Task.UUID);
newTask.clearValue(Task.PROOF_TEXT);
TodorooCursor<Metadata> cursor = metadataDao.query( TodorooCursor<Metadata> cursor = metadataDao.query(
Query.select(Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId()))); Query.select(Metadata.PROPERTIES).where(MetadataCriteria.byTask(task.getId())));
try { try {
@ -196,7 +198,8 @@ public class TaskService {
if (newTask == null) if (newTask == null)
return new Task(); return new Task();
newTask.clearValue(Task.ID); 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);
newTask.clearValue(Task.USER_ID); newTask.clearValue(Task.USER_ID);

Loading…
Cancel
Save