diff --git a/api/src/com/todoroo/andlib/data/AbstractDatabase.java b/api/src/com/todoroo/andlib/data/AbstractDatabase.java index 1e5479736..fa01b77d0 100644 --- a/api/src/com/todoroo/andlib/data/AbstractDatabase.java +++ b/api/src/com/todoroo/andlib/data/AbstractDatabase.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; +import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; @@ -230,7 +231,15 @@ abstract public class AbstractDatabase { * @see android.database.sqlite.SQLiteDatabase#insert(String table, String nullColumnHack, ContentValues values) */ public synchronized long insert(String table, String nullColumnHack, ContentValues values) { - long result = getDatabase().insert(table, nullColumnHack, values); + long result = -1; + try { + getDatabase().insertOrThrow(table, nullColumnHack, values); + } catch (SQLiteConstraintException e) { // Throw these exceptions + throw e; + } catch (Exception e) { // Suppress others + Log.e("SQLiteDatabase", "Error inserting " + values, e); + result = -1; + } onDatabaseUpdated(); return result; } diff --git a/api/src/com/todoroo/andlib/data/TodorooCursor.java b/api/src/com/todoroo/andlib/data/TodorooCursor.java index 4ef2c8ccc..af0be8034 100644 --- a/api/src/com/todoroo/andlib/data/TodorooCursor.java +++ b/api/src/com/todoroo/andlib/data/TodorooCursor.java @@ -96,7 +96,10 @@ public class TodorooCursor extends CursorWrapper { } public Object visitLong(Property property, TodorooCursor cursor) { - return cursor.getLong(cursor.getColumnIndexFromCache(property.name)); + int column = columnIndex(property, cursor); + if(cursor.isNull(column)) + return null; + return cursor.getLong(column); } public Object visitString(Property property, @@ -104,6 +107,9 @@ public class TodorooCursor extends CursorWrapper { return cursor.getString(cursor.getColumnIndexFromCache(property.name)); } + private int columnIndex(Property property, TodorooCursor cursor) { + return cursor.getColumnIndexFromCache(property.name); + } } } diff --git a/api/src/com/todoroo/astrid/data/Task.java b/api/src/com/todoroo/astrid/data/Task.java index cc20dfa10..76009812a 100644 --- a/api/src/com/todoroo/astrid/data/Task.java +++ b/api/src/com/todoroo/astrid/data/Task.java @@ -252,7 +252,7 @@ public final class Task extends RemoteModel { defaultValues.put(DETAILS_DATE.name, 0); defaultValues.put(LAST_SYNC.name, 0); - defaultValues.put(REMOTE_ID.name, 0); + defaultValues.putNull(REMOTE_ID.name); defaultValues.put(USER_ID.name, 0); defaultValues.put(CREATOR_ID.name, 0); defaultValues.put(USER.name, "{}"); diff --git a/astrid/.classpath b/astrid/.classpath index ecbf95127..195a13a14 100644 --- a/astrid/.classpath +++ b/astrid/.classpath @@ -3,7 +3,7 @@ - + diff --git a/astrid/common-src/com/localytics/android/ExceptionHandler.java b/astrid/common-src/com/localytics/android/ExceptionHandler.java index 1a55ecd4e..7fb8c9eed 100644 --- a/astrid/common-src/com/localytics/android/ExceptionHandler.java +++ b/astrid/common-src/com/localytics/android/ExceptionHandler.java @@ -33,4 +33,4 @@ import android.util.Log; } } } -} \ No newline at end of file +} diff --git a/astrid/common-src/com/localytics/android/ReflectionUtils.java b/astrid/common-src/com/localytics/android/ReflectionUtils.java index d98d2a7f9..dc4d608c3 100644 --- a/astrid/common-src/com/localytics/android/ReflectionUtils.java +++ b/astrid/common-src/com/localytics/android/ReflectionUtils.java @@ -106,4 +106,4 @@ public final class ReflectionUtils throw new RuntimeException(e); } } -} \ No newline at end of file +} diff --git a/astrid/common-src/com/todoroo/andlib/widget/Api4GestureDetector.java b/astrid/common-src/com/todoroo/andlib/widget/Api4GestureDetector.java index 9c52756bf..966820468 100644 --- a/astrid/common-src/com/todoroo/andlib/widget/Api4GestureDetector.java +++ b/astrid/common-src/com/todoroo/andlib/widget/Api4GestureDetector.java @@ -40,4 +40,4 @@ public class Api4GestureDetector implements OnGesturePerformedListener { } } } -} \ No newline at end of file +} diff --git a/astrid/common-src/com/todoroo/andlib/widget/DateControlSet.java b/astrid/common-src/com/todoroo/andlib/widget/DateControlSet.java index 4a8dabf7a..1eea3ed8b 100644 --- a/astrid/common-src/com/todoroo/andlib/widget/DateControlSet.java +++ b/astrid/common-src/com/todoroo/andlib/widget/DateControlSet.java @@ -138,4 +138,4 @@ public class DateControlSet implements OnTimeSetListener, }); } } -} \ No newline at end of file +} diff --git a/astrid/common-src/com/todoroo/andlib/widget/DateWithNullControlSet.java b/astrid/common-src/com/todoroo/andlib/widget/DateWithNullControlSet.java index 3cd1a1d34..d8ba506c9 100644 --- a/astrid/common-src/com/todoroo/andlib/widget/DateWithNullControlSet.java +++ b/astrid/common-src/com/todoroo/andlib/widget/DateWithNullControlSet.java @@ -66,4 +66,4 @@ public class DateWithNullControlSet extends DateControlSet { super.setDate(newDate); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java index 365ec3656..51d9d2c0c 100644 --- a/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java +++ b/astrid/plugin-src/com/timsu/astrid/C2DMReceiver.java @@ -132,7 +132,7 @@ public class C2DMReceiver extends BroadcastReceiver { try { TagData tagData = new TagData(); if(cursor.getCount() == 0) { - tagData.setValue(Task.REMOTE_ID, Long.parseLong(intent.getStringExtra("tag_id"))); + tagData.setValue(TagData.REMOTE_ID, Long.parseLong(intent.getStringExtra("tag_id"))); Flags.set(Flags.ACTFM_SUPPRESS_SYNC); tagDataService.save(tagData); } else { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java index a63c57838..fd5e61571 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmGoogleAuthActivity.java @@ -191,4 +191,4 @@ public class ActFmGoogleAuthActivity extends ListActivity { } } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java index 27834e7eb..63460c1cc 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmPreferences.java @@ -76,4 +76,4 @@ public class ActFmPreferences extends SyncProviderPreferences { } } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java index 838b0728d..17d8690bf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/EditPeopleControlSet.java @@ -695,9 +695,12 @@ public class EditPeopleControlSet extends PopupControlSet { @SuppressWarnings("nls") protected Object[] buildSharingArgs(JSONArray emails) throws JSONException { ArrayList values = new ArrayList(); - long currentTaskID = task.getValue(Task.REMOTE_ID); - values.add("id"); - values.add(currentTaskID); + + if(task.containsNonNullValue(Task.REMOTE_ID)) { + long currentTaskID = task.getValue(Task.REMOTE_ID); + values.add("id"); + values.add(currentTaskID); + } if(emails != null) { for(int i = 0; i < emails.length(); i++) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java index b0ce99f7c..d6dc4ec99 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java @@ -126,4 +126,4 @@ public class OAuthLoginActivity extends FragmentActivity { webView.loadUrl(urlParam); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java index 90f50073d..1752b5445 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java @@ -41,7 +41,6 @@ import com.todoroo.astrid.activity.TaskListActivity; import com.todoroo.astrid.adapter.UpdateAdapter; import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.data.TagData; -import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; import com.todoroo.astrid.helper.ImageDiskCache; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; @@ -205,7 +204,7 @@ public class TagUpdatesFragment extends ListFragment { } public void setLastViewed() { - if(tagData != null && tagData.getValue(Task.REMOTE_ID) > 0) { + if(tagData != null && tagData.getValue(TagData.REMOTE_ID) > 0) { Preferences.setLong(UPDATES_LAST_VIEWED + tagData.getValue(TagData.REMOTE_ID), DateUtilities.now()); Activity activity = getActivity(); if (activity instanceof TaskListActivity) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java index 190dfe6e9..49b9168b8 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java @@ -64,7 +64,7 @@ public final class ActFmDataService { */ public void clearMetadata() { ContentValues values = new ContentValues(); - values.put(Task.REMOTE_ID.name, 0); + values.putNull(Task.REMOTE_ID.name); taskDao.updateMultiple(values, Criterion.all); } @@ -75,7 +75,7 @@ public final class ActFmDataService { */ public TodorooCursor getLocallyCreated(Property[] properties) { return taskDao.query(Query.select(properties).where(Criterion.and(TaskCriteria.isActive(), - Task.REMOTE_ID.eq(0)))); + Task.REMOTE_ID.isNull()))); } /** @@ -89,7 +89,7 @@ public final class ActFmDataService { return taskDao.query(Query.select(properties).where(Criterion.none)); return taskDao.query(Query.select(properties). - where(Criterion.and(Task.REMOTE_ID.gt(0), + where(Criterion.and(Task.REMOTE_ID.isNotNull(), Task.MODIFICATION_DATE.gt(lastSyncDate), Task.MODIFICATION_DATE.gt(Task.LAST_SYNC))).groupBy(Task.ID)); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmPreferenceService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmPreferenceService.java index 3cb407732..b0fbb38cf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmPreferenceService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmPreferenceService.java @@ -123,4 +123,4 @@ public class ActFmPreferenceService extends SyncProviderUtilities { return Preferences.getStringValue(PREF_NAME); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java deleted file mode 100644 index 89bfc7b88..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncProvider.java +++ /dev/null @@ -1,363 +0,0 @@ -/** - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.actfm.sync; - -import java.io.IOException; -import java.util.ArrayList; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import android.app.Activity; -import android.app.Notification; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.text.TextUtils; - -import com.timsu.astrid.C2DMReceiver; -import com.timsu.astrid.R; -import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.Autowired; -import com.todoroo.andlib.service.ContextManager; -import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Query; -import com.todoroo.andlib.utility.DateUtilities; -import com.todoroo.andlib.utility.Preferences; -import com.todoroo.astrid.actfm.ActFmBackgroundService; -import com.todoroo.astrid.actfm.ActFmLoginActivity; -import com.todoroo.astrid.actfm.ActFmPreferences; -import com.todoroo.astrid.actfm.sync.ActFmSyncService.JsonHelper; -import com.todoroo.astrid.api.AstridApiConstants; -import com.todoroo.astrid.core.PluginServices; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TaskDao; -import com.todoroo.astrid.data.Metadata; -import com.todoroo.astrid.data.TagData; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.notes.NoteMetadata; -import com.todoroo.astrid.service.AstridDependencyInjector; -import com.todoroo.astrid.service.StatisticsConstants; -import com.todoroo.astrid.service.StatisticsService; -import com.todoroo.astrid.sync.SyncProvider; -import com.todoroo.astrid.sync.SyncProviderUtilities; -import com.todoroo.astrid.utility.Constants; - -@SuppressWarnings("nls") -public class ActFmSyncProvider extends SyncProvider { - - private ActFmInvoker invoker = null; - - @Autowired ActFmDataService actFmDataService; - @Autowired ActFmSyncService actFmSyncService; - @Autowired ActFmPreferenceService actFmPreferenceService; - @Autowired TagDataDao tagDataDao; - - static { - AstridDependencyInjector.initialize(); - } - - // ---------------------------------------------------------------------- - // ------------------------------------------------------ utility methods - // ---------------------------------------------------------------------- - - @Override - protected SyncProviderUtilities getUtilities() { - return actFmPreferenceService; - } - - /** - * Sign out of service, deleting all synchronization metadata - */ - public void signOut() { - actFmPreferenceService.setToken(null); - actFmPreferenceService.clearLastSyncDate(); - C2DMReceiver.unregister(); - } - - // ---------------------------------------------------------------------- - // ------------------------------------------------------ initiating sync - // ---------------------------------------------------------------------- - - /** - * initiate sync in background - */ - @Override - protected void initiateBackground() { - try { - C2DMReceiver.register(); - String authToken = actFmPreferenceService.getToken(); - invoker = new ActFmInvoker(authToken); - - // check if we have a token & it works - if(authToken != null) { - performSync(); - } - } catch (IllegalStateException e) { - // occurs when application was closed - } catch (Exception e) { - handleException("actfm-authenticate", e, false); - } finally { - actFmPreferenceService.stopOngoing(); - } - } - - /** - * If user isn't already signed in, show sign in dialog. Else perform sync. - */ - @Override - protected void initiateManual(Activity activity) { - String authToken = actFmPreferenceService.getToken(); - actFmPreferenceService.stopOngoing(); - - // check if we have a token & it works - if(authToken == null) { - // display login-activity - Intent intent = new Intent(activity, ActFmLoginActivity.class); - activity.startActivityForResult(intent, 0); - } else { - activity.startService(new Intent(null, null, - activity, ActFmBackgroundService.class)); - } - } - - // ---------------------------------------------------------------------- - // ----------------------------------------------------- synchronization! - // ---------------------------------------------------------------------- - - protected void performSync() { - actFmPreferenceService.recordSyncStart(); - String syncSuccess = "failed"; - - try { - int serverTime = Preferences.getInt(ActFmPreferenceService.PREF_SERVER_TIME, 0); - - ArrayList remoteTasks = new ArrayList(); - - // int newServerTime = fetchRemoteTasks(serverTime, remoteTasks); - if (serverTime == 0) { // If we've never synced, we may lose some empty tags - pushUnsavedTagData(); - } - // fetchRemoteTagData(serverTime); - - /* SyncData syncData = populateSyncData(remoteTasks); - - try { - synchronizeTasks(syncData); - } finally { - syncData.localCreated.close(); - syncData.localUpdated.close(); - } - - Preferences.setInt(ActFmPreferenceService.PREF_SERVER_TIME, newServerTime); */ - - actFmPreferenceService.recordSuccessfulSync(); - - syncSuccess = getFinalSyncStatus(); - Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH); - ContextManager.getContext().sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); - - } catch (IllegalStateException e) { - // occurs when application was closed - } catch (Exception e) { - handleException("actfm-sync", e, false); //$NON-NLS-1$ - } finally { - StatisticsService.reportEvent(StatisticsConstants.ACTFM_SYNC_FINISHED, - "success", syncSuccess); //$NON-NLS-1$ - } - } - - //Pushes unsaved, empty tag data, which will otherwise be deleted by the fetch tags call - private void pushUnsavedTagData() { - TodorooCursor unsavedTagData = tagDataDao.query(Query.select(TagData.ID, TagData.TASK_COUNT).where(Criterion.and(TagData.TASK_COUNT.eq(0), TagData.REMOTE_ID.eq(0)))); - TagData data = new TagData(); - for (unsavedTagData.moveToFirst(); !unsavedTagData.isAfterLast(); unsavedTagData.moveToNext()) { - data.readFromCursor(unsavedTagData); - actFmSyncService.pushTag(data.getId()); - } - } - - /** - * Read remote tag data and merge with local - * @param serverTime last sync time - */ - private void fetchRemoteTagData(int serverTime) throws ActFmServiceException, IOException, JSONException { - actFmSyncService.fetchTags(serverTime); - } - - /** - * Read remote task data into remote task array - * @param serverTime last sync time - */ - private int fetchRemoteTasks(int serverTime, - ArrayList remoteTasks) throws IOException, - ActFmServiceException, JSONException { - JSONObject result; - if(serverTime == 0) - result = invoker.invoke("task_list", "active", 1); - else - result = invoker.invoke("task_list", "modified_after", serverTime); - - JSONArray taskList = result.getJSONArray("list"); - for(int i = 0; i < taskList.length(); i++) { - ActFmTaskContainer remote = parseRemoteTask(taskList.getJSONObject(i)); - - // update reminder flags for incoming remote tasks to prevent annoying - if(remote.task.hasDueDate() && remote.task.getValue(Task.DUE_DATE) < DateUtilities.now()) - remote.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false); - - actFmDataService.findLocalMatch(remote); - - remoteTasks.add(remote); - } - return result.optInt("time", 0); - } - - // ---------------------------------------------------------------------- - // ------------------------------------------------------------ sync data - // ---------------------------------------------------------------------- - - /** - * Populate SyncData data structure - * @throws JSONException - */ - private SyncData populateSyncData(ArrayList remoteTasks) throws JSONException { - // fetch locally created tasks - TodorooCursor localCreated = actFmDataService.getLocallyCreated(Task.PROPERTIES); - - // fetch locally updated tasks - TodorooCursor localUpdated = actFmDataService.getLocallyUpdated(Task.PROPERTIES); - - return new SyncData(remoteTasks, localCreated, localUpdated); - } - - // ---------------------------------------------------------------------- - // ------------------------------------------------- create / push / pull - // ---------------------------------------------------------------------- - - @Override - protected ActFmTaskContainer create(ActFmTaskContainer local) throws IOException { - return push(local, null); - } - - /** Create a task container for the given remote task - * @throws JSONException */ - private ActFmTaskContainer parseRemoteTask(JSONObject remoteTask) throws JSONException { - Task task = new Task(); - - ArrayList metadata = new ArrayList(); - - JsonHelper.taskFromJson(remoteTask, task, metadata); - ActFmTaskContainer container = new ActFmTaskContainer(task, metadata, remoteTask); - - return container; - } - - @Override - protected ActFmTaskContainer pull(ActFmTaskContainer task) throws IOException { - if(task.task.getValue(Task.REMOTE_ID) == 0) - throw new ActFmServiceException("Tried to read an invalid task"); //$NON-NLS-1$ - - JSONObject remote = invoker.invoke("task_show", "id", task.task.getValue(Task.REMOTE_ID)); - try { - return parseRemoteTask(remote); - } catch (JSONException e) { - throw new ActFmServiceException(e); - } - } - - /** - * Send changes for the given Task across the wire. - */ - @Override - protected ActFmTaskContainer push(ActFmTaskContainer local, ActFmTaskContainer remote) throws IOException { - long id = local.task.getValue(Task.REMOTE_ID); - - actFmSyncService.pushTaskOnSave(local.task, local.task.getDatabaseValues()); - - // push unsaved comments - for(Metadata item : local.metadata) { - if(NoteMetadata.METADATA_KEY.equals(item.getValue(Metadata.KEY))) - if(TextUtils.isEmpty(item.getValue(NoteMetadata.EXT_ID))) { - JSONObject comment = invoker.invoke("comment_add", - "task_id", id, - "message", item.getValue(NoteMetadata.BODY)); - item.setValue(NoteMetadata.EXT_ID, comment.optString("id")); - } - } - - return local; - } - - @Override - protected void readRemotelyUpdated(SyncData data) throws IOException { - int serverTime = Preferences.getInt(ActFmPreferenceService.PREF_SERVER_TIME, 0); - ArrayList remoteTasks = new ArrayList(); - - try { - fetchRemoteTasks(serverTime, remoteTasks); - data.remoteUpdated = remoteTasks; - } catch (JSONException e) { - // Ingnored - } - super.readRemotelyUpdated(data); - } - - // ---------------------------------------------------------------------- - // --------------------------------------------------------- read / write - // ---------------------------------------------------------------------- - - @Override - protected ActFmTaskContainer read(TodorooCursor cursor) throws IOException { - return actFmDataService.readTaskAndMetadata(cursor); - } - - @Override - protected void write(ActFmTaskContainer task) throws IOException { - if(task.task.isSaved()) { - Task local = PluginServices.getTaskService().fetchById(task.task.getId(), Task.COMPLETION_DATE); - if(task.task.isCompleted() && !local.isCompleted()) - StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMPLETED); - } else { // Set default reminders for remotely created tasks - TaskDao.setDefaultReminders(task.task); - } - task.task.setValue(Task.LAST_SYNC, DateUtilities.now() + 1000); - actFmDataService.saveTaskAndMetadata(task); - } - - // ---------------------------------------------------------------------- - // --------------------------------------------------------- misc helpers - // ---------------------------------------------------------------------- - - @Override - protected int matchTask(ArrayList tasks, ActFmTaskContainer target) { - int length = tasks.size(); - for(int i = 0; i < length; i++) { - ActFmTaskContainer task = tasks.get(i); - if (task.task.getValue(Task.REMOTE_ID) == target.task.getValue(Task.REMOTE_ID)) - return i; - } - return -1; - } - - @Override - protected int updateNotification(Context context, Notification notification) { - String notificationTitle = context.getString(R.string.actfm_notification_title); - Intent intent = new Intent(context, ActFmPreferences.class); - PendingIntent notificationIntent = PendingIntent.getActivity(context, 0, - intent, 0); - notification.setLatestEventInfo(context, - notificationTitle, context.getString(R.string.SyP_progress), - notificationIntent); - return Constants.NOTIFICATION_SYNC; - } - - @Override - protected void transferIdentifiers(ActFmTaskContainer source, - ActFmTaskContainer destination) { - destination.task.setValue(Task.REMOTE_ID, source.task.getValue(Task.REMOTE_ID)); - } - -} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 55616b6fa..f58173faa 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -298,13 +298,14 @@ public final class ActFmSyncService { public void pushTaskOnSave(Task task, ContentValues values) { Task taskForRemote = taskService.fetchById(task.getId(), Task.REMOTE_ID, Task.CREATION_DATE); - long remoteId; - if(task.containsValue(Task.REMOTE_ID)) { + long remoteId = 0; + if(task.containsNonNullValue(Task.REMOTE_ID)) { remoteId = task.getValue(Task.REMOTE_ID); } else { if(taskForRemote == null) return; - remoteId = taskForRemote.getValue(Task.REMOTE_ID); + if(taskForRemote.containsNonNullValue(Task.REMOTE_ID)) + remoteId = taskForRemote.getValue(Task.REMOTE_ID); } long creationDate; @@ -876,22 +877,15 @@ public final class ActFmSyncService { TodorooCursor cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion)); pushQueuedUpdates(cursor); - Log.d("ActFmSyncService", "Push queued updates for tag"); - } private void pushQueuedUpdates(Task task) { - - Criterion criterion = null; - if (task.getValue(Task.REMOTE_ID) < 1) { - criterion = Criterion.and(Update.REMOTE_ID.eq(0), - Update.TASK_LOCAL.eq(task.getId())); - } - else { + if (task.containsNonNullValue(Task.REMOTE_ID)) { criterion = Criterion.and(Update.REMOTE_ID.eq(0), Criterion.or(Update.TASK.eq(task.getValue(Task.REMOTE_ID)), Update.TASK_LOCAL.eq(task.getId()))); - } + } else + return; Update template = new Update(); template.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); //$NON-NLS-1$ @@ -899,8 +893,6 @@ public final class ActFmSyncService { TodorooCursor cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion)); pushQueuedUpdates(cursor); - Log.d("ActFmSyncService", "Push queued updates for task"); - } private void pushQueuedUpdates( TodorooCursor cursor) { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java index 969e277e9..bfdf1776e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncV2Provider.java @@ -213,8 +213,8 @@ public class ActFmSyncV2Provider extends SyncV2Provider { TodorooCursor taskCursor = taskService.query(Query.select(Task.PROPERTIES). where(Criterion.or( Criterion.and(TaskCriteria.isActive(), - Task.REMOTE_ID.eq(0)), - Criterion.and(Task.REMOTE_ID.gt(0), + Task.REMOTE_ID.isNull()), + Criterion.and(Task.REMOTE_ID.isNotNull(), Task.MODIFICATION_DATE.gt(Task.LAST_SYNC))))); pushQueued(callback, finisher, taskCursor, false, taskPusher); diff --git a/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java b/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java index 3345dfe63..a3df9ef49 100644 --- a/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java @@ -128,4 +128,4 @@ public class BackupPreferences extends TodorooPreferenceActivity { } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/core/DefaultsPreferences.java b/astrid/plugin-src/com/todoroo/astrid/core/DefaultsPreferences.java index 67aa5bdb6..8e9e24c65 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/DefaultsPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/DefaultsPreferences.java @@ -103,4 +103,4 @@ public class DefaultsPreferences extends TodorooPreferenceActivity { } } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/core/OldTaskPreferences.java b/astrid/plugin-src/com/todoroo/astrid/core/OldTaskPreferences.java index cb1b75fe0..412e32c81 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/OldTaskPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/OldTaskPreferences.java @@ -291,4 +291,4 @@ public class OldTaskPreferences extends TodorooPreferenceActivity { // :) } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/gcal/Calendars.java b/astrid/plugin-src/com/todoroo/astrid/gcal/Calendars.java index b2e2b02be..c8a556c5a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gcal/Calendars.java +++ b/astrid/plugin-src/com/todoroo/astrid/gcal/Calendars.java @@ -233,4 +233,4 @@ public class Calendars { return Preferences.getStringValue(R.string.gcal_p_default); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java index 456d180c8..79d8be4cd 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java @@ -71,4 +71,4 @@ public class GtasksPreferences extends SyncProviderPreferences { super.onPause(); new GtasksBackgroundService().scheduleService(); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java index c98f877a4..c532d9c3f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/auth/GtasksLoginActivity.java @@ -233,4 +233,4 @@ public class GtasksLoginActivity extends ListActivity { } } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java index 3450188bf..d8c556c26 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksTaskContainer.java @@ -53,4 +53,4 @@ public class GtasksTaskContainer extends SyncContainer { super.prepareForSaving(); metadata.add(gtaskMetadata); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/locale/LocaleEditAlerts.java b/astrid/plugin-src/com/todoroo/astrid/locale/LocaleEditAlerts.java index 249f21e49..8712e3903 100644 --- a/astrid/plugin-src/com/todoroo/astrid/locale/LocaleEditAlerts.java +++ b/astrid/plugin-src/com/todoroo/astrid/locale/LocaleEditAlerts.java @@ -337,4 +337,4 @@ public final class LocaleEditAlerts extends ListActivity { return super.onOptionsItemSelected(item); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index 81ae8e8dd..a283fc700 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -121,7 +121,6 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene } public void loadViewForTaskID(long t){ - task = PluginServices.getTaskService().fetchById(t, Task.NOTES, Task.ID, Task.REMOTE_ID, Task.TITLE); if(task == null) { return; @@ -130,7 +129,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene setUpListAdapter(); if(actFmPreferenceService.isLoggedIn()) { - if(task.getValue(Task.REMOTE_ID) == 0) + if(!task.containsNonNullValue(Task.REMOTE_ID)) refreshData(true, null); else { String fetchKey = LAST_FETCH_KEY + task.getId(); @@ -257,7 +256,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene TodorooCursor updates; - if (task.getValue(Task.REMOTE_ID) < 1) { + if (!task.containsNonNullValue(Task.REMOTE_ID)) { updates = updateDao.query(Query.select(Update.PROPERTIES).where(Update.TASK_LOCAL.eq(task.getId()))); } else { @@ -406,7 +405,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene } // push task if it hasn't been pushed - if(task.getValue(Task.REMOTE_ID) == 0 && !TextUtils.isEmpty(task.getValue(Task.TITLE))) { + if(!task.containsNonNullValue(Task.REMOTE_ID) && !TextUtils.isEmpty(task.getValue(Task.TITLE))) { new Thread(new Runnable() { @Override public void run() { @@ -446,7 +445,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene update.setValue(Update.MESSAGE, message); update.setValue(Update.ACTION_CODE, actionCode); update.setValue(Update.USER_ID, 0L); - update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); + if(task.containsNonNullValue(Task.REMOTE_ID)) + update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); update.setValue(Update.TASK_LOCAL, task.getId()); update.setValue(Update.CREATION_DATE, DateUtilities.now()); diff --git a/astrid/plugin-src/com/todoroo/astrid/opencrx/OpencrxControlSet.java b/astrid/plugin-src/com/todoroo/astrid/opencrx/OpencrxControlSet.java index 6dc93b9a5..4f802ac9f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/opencrx/OpencrxControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/opencrx/OpencrxControlSet.java @@ -405,4 +405,4 @@ public class OpencrxControlSet extends PopupControlSet { // Nothing to do } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java index acd637d75..60c24457b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevControlSet.java @@ -277,4 +277,4 @@ public class ProducteevControlSet extends PopupControlSet { // TODO Auto-generated method stub } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevPreferences.java b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevPreferences.java index a08a1cd25..04987352f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevPreferences.java @@ -94,4 +94,4 @@ public class ProducteevPreferences extends SyncProviderPreferences { ((ListPreference)preference).getEntries()[index])); } } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevUtilities.java b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevUtilities.java index d0bbfd1be..dbc2fb699 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevUtilities.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/ProducteevUtilities.java @@ -76,4 +76,4 @@ public class ProducteevUtilities extends SyncProviderUtilities { return Preferences.getStringValue(R.string.producteev_PPr_email); } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java index 3f3780cfd..99a8f8d3f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderPreferences.java @@ -101,4 +101,4 @@ public class ReminderPreferences extends TodorooPreferenceActivity { } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java index c25204e3f..148d98a45 100644 --- a/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/repeats/RepeatControlSet.java @@ -420,4 +420,4 @@ public class RepeatControlSet extends PopupControlSet { return d; } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitTaskContainer.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitTaskContainer.java index 0b59c1e2f..93c8446ab 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitTaskContainer.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitTaskContainer.java @@ -81,4 +81,4 @@ public class TaskRabbitTaskContainer extends SyncContainer { public boolean isTaskRabbit() { return getTaskID() > 0; } -} \ No newline at end of file +} diff --git a/astrid/plugin-src/com/todoroo/astrid/timers/TimerControlSet.java b/astrid/plugin-src/com/todoroo/astrid/timers/TimerControlSet.java index 1a62aa555..991a34b3c 100644 --- a/astrid/plugin-src/com/todoroo/astrid/timers/TimerControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/timers/TimerControlSet.java @@ -104,4 +104,4 @@ public class TimerControlSet extends PopupControlSet implements TimerActionListe return; } -} \ No newline at end of file +} diff --git a/astrid/rmilk-src/org/weloveastrid/rmilk/MilkPreferences.java b/astrid/rmilk-src/org/weloveastrid/rmilk/MilkPreferences.java index 89b3ab780..23f3dad6c 100644 --- a/astrid/rmilk-src/org/weloveastrid/rmilk/MilkPreferences.java +++ b/astrid/rmilk-src/org/weloveastrid/rmilk/MilkPreferences.java @@ -36,4 +36,4 @@ public class MilkPreferences extends SyncProviderPreferences { return MilkUtilities.INSTANCE; } -} \ No newline at end of file +} diff --git a/astrid/rmilk-src/org/weloveastrid/rmilk/sync/MilkTaskContainer.java b/astrid/rmilk-src/org/weloveastrid/rmilk/sync/MilkTaskContainer.java index 997c47158..64dae133c 100644 --- a/astrid/rmilk-src/org/weloveastrid/rmilk/sync/MilkTaskContainer.java +++ b/astrid/rmilk-src/org/weloveastrid/rmilk/sync/MilkTaskContainer.java @@ -65,4 +65,4 @@ public class MilkTaskContainer extends SyncContainer { metadata.add(MilkTaskFields.create(this)); } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/activity/AboutActivity.java b/astrid/src/com/todoroo/astrid/activity/AboutActivity.java index b3aa726b3..5994e01a0 100644 --- a/astrid/src/com/todoroo/astrid/activity/AboutActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/AboutActivity.java @@ -65,4 +65,4 @@ class About { private About() { // don't construct me } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index d2303b89b..434bc4bda 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -465,4 +465,4 @@ public class EditPreferences extends TodorooPreferenceActivity { super.onStop(); } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/activity/ExpandableListFragment.java b/astrid/src/com/todoroo/astrid/activity/ExpandableListFragment.java index c8b823c99..dc296bd71 100644 --- a/astrid/src/com/todoroo/astrid/activity/ExpandableListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/ExpandableListFragment.java @@ -351,4 +351,4 @@ public class ExpandableListFragment extends Fragment int groupPosition, int childPosition, long id) { return false; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java index b82721cce..ca52a8c6e 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java @@ -719,10 +719,9 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { if (idParam > -1L) { model = taskService.fetchById(idParam, Task.PROPERTIES); - if (model != null) { + if (model != null && model.containsNonNullValue(Task.REMOTE_ID)) { remoteId = model.getValue(Task.REMOTE_ID); - model.clearValue(Task.REMOTE_ID); // Having this can screw up - // autosync + model.clearValue(Task.REMOTE_ID); // Having this can screw up autosync } } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditViewPager.java b/astrid/src/com/todoroo/astrid/activity/TaskEditViewPager.java index 80b6ec5ef..61fe75b78 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditViewPager.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditViewPager.java @@ -74,4 +74,4 @@ public class TaskEditViewPager extends PagerAdapter implements TitleProvider { return null; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index c13669494..188fda7db 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -9,6 +9,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.SearchManager; import android.content.BroadcastReceiver; +import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -260,6 +261,11 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, // We have a menu item to show in action bar. setHasOptionsMenu(true); + ContentValues values = new ContentValues(); + values.put(Task.REMOTE_ID.name, 1); + TaskService.createWithValues(values, "task 1", taskService, metadataService); + TaskService.createWithValues(values, "task 2", taskService, metadataService); + setUpUiComponents(); onNewIntent(getActivity().getIntent()); diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index fc9288d12..f88e9cef6 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -150,13 +150,6 @@ public class Database extends AbstractDatabase { append(')'); database.execSQL(sql.toString()); sql.setLength(0); - - sql.append("CREATE UNIQUE INDEX IF NOT EXISTS tg_rid ON "). - append(TagData.TABLE).append('('). - append(TagData.REMOTE_ID.name). - append(')'); - database.execSQL(sql.toString()); - sql.setLength(0); } @Override @@ -281,9 +274,9 @@ public class Database extends AbstractDatabase { Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e); } case 20: try { - String[] tables = new String[] { Task.TABLE.name, TagData.TABLE.name }; - String [] ids = new String[] { Task.ID.name, TagData.ID.name }; - String[] remoteIds = new String[] { Task.REMOTE_ID.name, TagData.REMOTE_ID.name }; + String[] tables = new String[] { Task.TABLE.name }; + String [] ids = new String[] { Task.ID.name }; + String[] remoteIds = new String[] { Task.REMOTE_ID.name }; for (int i = 0; i < tables.length; i++) { String table = tables[i]; diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index bf604d4ab..27326645e 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -6,13 +6,16 @@ package com.todoroo.astrid.dao; import android.content.ContentValues; +import android.database.sqlite.SQLiteConstraintException; import com.timsu.astrid.R; import com.todoroo.andlib.data.DatabaseDao; +import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Functions; +import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; @@ -166,7 +169,17 @@ public class TaskDao extends DatabaseDao { public boolean save(Task task) { boolean saveSuccessful; if (task.getId() == Task.NO_ID) { - saveSuccessful = createNew(task); + try { + saveSuccessful = createNew(task); + } catch (SQLiteConstraintException e) { // Tried to create task with remote id that already exists + saveSuccessful = false; + TodorooCursor cursor = query(Query.select(Task.ID).where(Task.REMOTE_ID.eq(task.getValue(Task.REMOTE_ID)))); + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + task.setId(cursor.get(Task.ID)); + saveSuccessful = saveExisting(task); + } + } } else { saveSuccessful = saveExisting(task); } diff --git a/astrid/src/com/todoroo/astrid/helper/TaskAdapterAddOnManager.java b/astrid/src/com/todoroo/astrid/helper/TaskAdapterAddOnManager.java index 4675cb1ba..3b454c34d 100644 --- a/astrid/src/com/todoroo/astrid/helper/TaskAdapterAddOnManager.java +++ b/astrid/src/com/todoroo/astrid/helper/TaskAdapterAddOnManager.java @@ -144,4 +144,4 @@ abstract public class TaskAdapterAddOnManager { return cache.get(taskId).values(); } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/helper/TaskEditControlSet.java b/astrid/src/com/todoroo/astrid/helper/TaskEditControlSet.java index fe214c70b..5b3fd1e6a 100644 --- a/astrid/src/com/todoroo/astrid/helper/TaskEditControlSet.java +++ b/astrid/src/com/todoroo/astrid/helper/TaskEditControlSet.java @@ -79,4 +79,4 @@ public abstract class TaskEditControlSet { * Called when views need to be inflated */ protected abstract void afterInflate(); -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/helper/TaskListContextMenuExtensionLoader.java b/astrid/src/com/todoroo/astrid/helper/TaskListContextMenuExtensionLoader.java index 7abc7cdc5..153461b22 100644 --- a/astrid/src/com/todoroo/astrid/helper/TaskListContextMenuExtensionLoader.java +++ b/astrid/src/com/todoroo/astrid/helper/TaskListContextMenuExtensionLoader.java @@ -52,4 +52,4 @@ public class TaskListContextMenuExtensionLoader { } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/legacy/LegacyAlertModel.java b/astrid/src/com/todoroo/astrid/legacy/LegacyAlertModel.java index 97bb5373f..de6da13f3 100644 --- a/astrid/src/com/todoroo/astrid/legacy/LegacyAlertModel.java +++ b/astrid/src/com/todoroo/astrid/legacy/LegacyAlertModel.java @@ -7,4 +7,4 @@ abstract public class LegacyAlertModel { public static final String TASK = "task"; public static final String DATE = "date"; -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/legacy/LegacyRepeatInfo.java b/astrid/src/com/todoroo/astrid/legacy/LegacyRepeatInfo.java index 355746c17..211afdc84 100644 --- a/astrid/src/com/todoroo/astrid/legacy/LegacyRepeatInfo.java +++ b/astrid/src/com/todoroo/astrid/legacy/LegacyRepeatInfo.java @@ -60,4 +60,4 @@ public class LegacyRepeatInfo { return rrule; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/service/TagDataService.java b/astrid/src/com/todoroo/astrid/service/TagDataService.java index 3a11a6753..ece7bb52e 100644 --- a/astrid/src/com/todoroo/astrid/service/TagDataService.java +++ b/astrid/src/com/todoroo/astrid/service/TagDataService.java @@ -13,7 +13,6 @@ import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.data.TagData; -import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; /** @@ -141,10 +140,10 @@ public class TagDataService { return updateDao.query(Query.select(Update.PROPERTIES).where( criterion). orderBy(Order.desc(Update.CREATION_DATE))); - if(tagData.getValue(Task.REMOTE_ID) < 1) + if(tagData.getValue(TagData.REMOTE_ID) == 0) 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(Task.REMOTE_ID) + ",%"), + Criterion.or(Update.TAGS.like("%," + tagData.getValue(TagData.REMOTE_ID) + ",%"), Update.TAGS_LOCAL.like("%," + tagData.getId() + ",%")))). orderBy(Order.desc(Update.CREATION_DATE))); } @@ -155,12 +154,12 @@ public class TagDataService { * @return */ public Update getLatestUpdate(TagData tagData) { - if(tagData.getValue(Task.REMOTE_ID) < 1) + if(tagData.getValue(TagData.REMOTE_ID) == 0) return null; @SuppressWarnings("nls") TodorooCursor updates = updateDao.query(Query.select(Update.PROPERTIES).where( - Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%")). + Update.TAGS.like("%," + tagData.getValue(TagData.REMOTE_ID) + ",%")). orderBy(Order.desc(Update.CREATION_DATE)).limit(1)); try { if(updates.getCount() == 0) diff --git a/astrid/src/com/todoroo/astrid/ui/CalendarDialog.java b/astrid/src/com/todoroo/astrid/ui/CalendarDialog.java index db999cd36..eb2104df6 100644 --- a/astrid/src/com/todoroo/astrid/ui/CalendarDialog.java +++ b/astrid/src/com/todoroo/astrid/ui/CalendarDialog.java @@ -62,4 +62,4 @@ public class CalendarDialog extends Dialog implements OnClickListener, OnSelecte public void setCalendarDate(Date calendarDate) { this.calendarDate = calendarDate; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/ContactListAdapter.java b/astrid/src/com/todoroo/astrid/ui/ContactListAdapter.java index 3fa9a4ee2..32ee2817a 100644 --- a/astrid/src/com/todoroo/astrid/ui/ContactListAdapter.java +++ b/astrid/src/com/todoroo/astrid/ui/ContactListAdapter.java @@ -189,4 +189,4 @@ public class ContactListAdapter extends CursorAdapter { } } } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java b/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java index b13d7bc15..8281362f8 100644 --- a/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/EditTextControlSet.java @@ -69,4 +69,4 @@ public class EditTextControlSet extends TaskEditControlSet { return null; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/ErrorCatchingEditText.java b/astrid/src/com/todoroo/astrid/ui/ErrorCatchingEditText.java index 3851be854..e0bbb126c 100644 --- a/astrid/src/com/todoroo/astrid/ui/ErrorCatchingEditText.java +++ b/astrid/src/com/todoroo/astrid/ui/ErrorCatchingEditText.java @@ -40,4 +40,4 @@ public class ErrorCatchingEditText extends EditText { } } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java b/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java index 7921903c9..b20e4d7c0 100644 --- a/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/HideUntilControlSet.java @@ -258,4 +258,4 @@ public class HideUntilControlSet extends PopupControlSet implements OnItemSelect return null; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/NestedListView.java b/astrid/src/com/todoroo/astrid/ui/NestedListView.java index dc195ce8b..bb3aae9b7 100644 --- a/astrid/src/com/todoroo/astrid/ui/NestedListView.java +++ b/astrid/src/com/todoroo/astrid/ui/NestedListView.java @@ -44,4 +44,4 @@ public class NestedListView extends ListView { setMeasuredDimension(getMeasuredWidth(), newHeight); } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/NumberPicker.java b/astrid/src/com/todoroo/astrid/ui/NumberPicker.java index 826af6317..13a4cec89 100644 --- a/astrid/src/com/todoroo/astrid/ui/NumberPicker.java +++ b/astrid/src/com/todoroo/astrid/ui/NumberPicker.java @@ -489,4 +489,4 @@ public class NumberPicker extends LinearLayout implements OnClickListener, validateCurrentView(str, true); return mCurrent; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/NumberPickerButton.java b/astrid/src/com/todoroo/astrid/ui/NumberPickerButton.java index 54c6cf9bd..f3f858631 100644 --- a/astrid/src/com/todoroo/astrid/ui/NumberPickerButton.java +++ b/astrid/src/com/todoroo/astrid/ui/NumberPickerButton.java @@ -86,4 +86,4 @@ public class NumberPickerButton extends ImageButton { mNumberPicker.cancelDecrement(); } } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/RandomReminderControlSet.java b/astrid/src/com/todoroo/astrid/ui/RandomReminderControlSet.java index 283d3fa35..25ced0bdb 100644 --- a/astrid/src/com/todoroo/astrid/ui/RandomReminderControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/RandomReminderControlSet.java @@ -95,4 +95,4 @@ public class RandomReminderControlSet extends TaskEditControlSet { task.setValue(Task.REMINDER_PERIOD, 0L); return null; } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/ReminderControlSet.java b/astrid/src/com/todoroo/astrid/ui/ReminderControlSet.java index f95ed8f00..11322e28d 100644 --- a/astrid/src/com/todoroo/astrid/ui/ReminderControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/ReminderControlSet.java @@ -127,4 +127,4 @@ public class ReminderControlSet extends PopupControlSet { protected void refreshDisplayView() { // Nothing to do here } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java b/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java index 919065a80..6ccab9231 100644 --- a/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java +++ b/astrid/src/com/todoroo/astrid/ui/TimeDurationControlSet.java @@ -122,4 +122,4 @@ public class TimeDurationControlSet implements OnNNumberPickedListener, } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java index ec705d355..9ee75e8b7 100644 --- a/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java +++ b/astrid/src/com/todoroo/astrid/voice/VoiceInputAssistant.java @@ -325,4 +325,4 @@ public class VoiceInputAssistant { } } } -} \ No newline at end of file +} diff --git a/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java b/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java index 888d4d106..1ed122fab 100644 --- a/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/welcome/tutorial/WelcomePagerAdapter.java @@ -142,4 +142,4 @@ public class WelcomePagerAdapter extends PagerAdapter implements TitleProvider return context.getString(title[position]); } -} \ No newline at end of file +}