diff --git a/api/src/com/todoroo/astrid/data/TagData.java b/api/src/com/todoroo/astrid/data/TagData.java index 240d41db0..8a07ccf65 100644 --- a/api/src/com/todoroo/astrid/data/TagData.java +++ b/api/src/com/todoroo/astrid/data/TagData.java @@ -146,6 +146,10 @@ public final class TagData extends RemoteModel { public static final IntegerProperty HISTORY_HAS_MORE = new IntegerProperty( TABLE, "historyHasMore"); + /** Last autosync */ + public static final LongProperty LAST_AUTOSYNC = new LongProperty( + TABLE, "lastAutosync"); + /** List of all properties for this model */ public static final Property[] PROPERTIES = generateProperties(TagData.class); @@ -180,6 +184,7 @@ public final class TagData extends RemoteModel { defaultValues.put(DELETION_DATE.name, 0); defaultValues.put(HISTORY_FETCH_DATE.name, 0); defaultValues.put(HISTORY_HAS_MORE.name, 0); + defaultValues.put(LAST_AUTOSYNC.name, 0); defaultValues.put(THUMB.name, ""); defaultValues.put(LAST_ACTIVITY_DATE.name, 0); diff --git a/api/src/com/todoroo/astrid/data/User.java b/api/src/com/todoroo/astrid/data/User.java index e12cd9ca7..ae3a56ff4 100644 --- a/api/src/com/todoroo/astrid/data/User.java +++ b/api/src/com/todoroo/astrid/data/User.java @@ -78,6 +78,10 @@ public final class User extends RemoteModel { public static final StringProperty STATUS = new StringProperty( TABLE, "status"); + /** Last autosync */ + public static final LongProperty LAST_AUTOSYNC = new LongProperty( + TABLE, "lastAutosync"); + /** Friendship tatus that needs to be reported to the server. * One of the PENDING constants below */ @Deprecated public static final StringProperty PENDING_STATUS = new StringProperty( @@ -101,6 +105,7 @@ public final class User extends RemoteModel { defaultValues.put(TASKS_PUSHED_AT.name, 0L); defaultValues.put(UUID.name, NO_UUID); defaultValues.put(STATUS.name, ""); + defaultValues.put(LAST_AUTOSYNC.name, 0L); } @Override diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index a77752466..9a2846fac 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -339,9 +339,12 @@ public class TagViewFragment extends TaskListFragment { if (!isCurrentTaskListFragment()) return; if (tagData != null) { - long pushedAt = tagData.getValue(TagData.TASKS_PUSHED_AT); - if(DateUtilities.now() - pushedAt > AUTOSYNC_INTERVAL) + long lastAutosync = tagData.getValue(TagData.LAST_AUTOSYNC); + if(DateUtilities.now() - lastAutosync > AUTOSYNC_INTERVAL) { + tagData.setValue(TagData.LAST_AUTOSYNC, DateUtilities.now()); + tagDataDao.saveExisting(tagData); refreshData(); + } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java index 368796b6d..b0d90c4ab 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PersonViewFragment.java @@ -190,12 +190,13 @@ public class PersonViewFragment extends TaskListFragment { if (!isCurrentTaskListFragment()) return; if (user != null) { - long pushedAt = user.getValue(User.PUSHED_AT); - long tasksPushedAt = user.getValue(User.TASKS_PUSHED_AT); + long lastAutosync = user.getValue(User.LAST_AUTOSYNC); - if((DateUtilities.now() - pushedAt > AUTOSYNC_INTERVAL) || - (DateUtilities.now() - tasksPushedAt > AUTOSYNC_INTERVAL)) + if(DateUtilities.now() - lastAutosync > AUTOSYNC_INTERVAL) { refreshData(); + user.setValue(User.LAST_AUTOSYNC, DateUtilities.now()); + userDao.saveExisting(user); + } } } diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index 040b8b72f..af8c19544 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -53,7 +53,7 @@ public class Database extends AbstractDatabase { * Database version number. This variable must be updated when database * tables are updated, as it determines whether a database needs updating. */ - public static final int VERSION = 33; + public static final int VERSION = 34; /** * Database name (must be unique) @@ -395,6 +395,9 @@ public class Database extends AbstractDatabase { tryExecSQL("DROP TABLE " + History.TABLE.name); tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES)); tryExecSQL(addColumnSql(User.TABLE, User.TASKS_PUSHED_AT, visitor, null)); + case 33: + tryExecSQL(addColumnSql(TagData.TABLE, TagData.LAST_AUTOSYNC, visitor, null)); + tryExecSQL(addColumnSql(User.TABLE, User.LAST_AUTOSYNC, visitor, null)); return true; } diff --git a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java index 59aebd067..1583f257d 100644 --- a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java +++ b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java @@ -30,7 +30,6 @@ import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; -import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.SyncAction; @@ -88,7 +87,7 @@ public class SyncActionHelper { // --- automatic sync logic public void initiateAutomaticSync() { - long tasksPushedAt = Preferences.getLong(NameMaps.PUSHED_AT_TASKS, 0); + long tasksPushedAt = Preferences.getLong(PREF_LAST_AUTO_SYNC, 0); if (DateUtilities.now() - tasksPushedAt > TaskListFragment.AUTOSYNC_INTERVAL) { performSyncServiceV2Sync(false); }