From 4247b89ed099a4ca9b33c8b8db42288b95bf991a Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 5 Feb 2013 10:58:15 -0800 Subject: [PATCH] Use a flag to indicate that sync migration is ongoing --- .../com/todoroo/astrid/actfm/sync/ActFmSyncThread.java | 3 ++- .../todoroo/astrid/actfm/sync/AstridNewSyncMigrator.java | 3 +++ astrid/src/com/todoroo/astrid/utility/Flags.java | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java index 953186c0a..f3d507a27 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -41,6 +41,7 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivityOutstanding; +import com.todoroo.astrid.utility.Flags; public class ActFmSyncThread { @@ -256,7 +257,7 @@ public class ActFmSyncThread { } private boolean timeForBackgroundSync() { - return false; + return !Flags.check(Flags.SYNC_MIGRATION_ONGOING); } private void repopulateQueueFromOutstandingTables() { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/AstridNewSyncMigrator.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/AstridNewSyncMigrator.java index 8247ebc30..d7a25e16d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/AstridNewSyncMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/AstridNewSyncMigrator.java @@ -36,6 +36,7 @@ import com.todoroo.astrid.helper.UUIDHelper; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.tags.TaskToTagMetadata; +import com.todoroo.astrid.utility.Flags; @SuppressWarnings("nls") public class AstridNewSyncMigrator { @@ -59,6 +60,7 @@ public class AstridNewSyncMigrator { @SuppressWarnings("deprecation") public void performMigration() { + Flags.set(Flags.SYNC_MIGRATION_ONGOING); // -------------- // First ensure that a TagData object exists for each tag metadata // -------------- @@ -223,6 +225,7 @@ public class AstridNewSyncMigrator { } catch (Exception e) { Log.e(LOG_TAG, "Error validating task to tag metadata", e); } + Flags.checkAndClear(Flags.SYNC_MIGRATION_ONGOING); } private interface UUIDAssertionExtras { diff --git a/astrid/src/com/todoroo/astrid/utility/Flags.java b/astrid/src/com/todoroo/astrid/utility/Flags.java index 1d3a0d0e4..e164f1b22 100644 --- a/astrid/src/com/todoroo/astrid/utility/Flags.java +++ b/astrid/src/com/todoroo/astrid/utility/Flags.java @@ -36,6 +36,12 @@ public class Flags { */ public static final int TLFP_NO_INTERCEPT_TOUCH = 1 << 7; + /** + * If set, indicates that the new sync migration is ongoing and the sync thread should block until it is finished + * Only set once. + */ + public static final int SYNC_MIGRATION_ONGOING = 1 << 8; + public static boolean checkAndClear(int flag) { boolean set = (state & flag) > 0; state &= ~flag;