Don't enqueue messages when we shouldn't

pull/14/head
Sam Bosley 12 years ago
parent 1826417c77
commit 008c1b2184

@ -59,9 +59,9 @@ public class ActFmPreferenceService extends SyncProviderUtilities {
public void setToken(String setting) {
super.setToken(setting);
if (TextUtils.isEmpty(setting))
RemoteModelDao.outstandingEntryFlag = -1;
RemoteModelDao.setOutstandingEntryFlags(RemoteModelDao.OUTSTANDING_FLAG_UNINITIALIZED);
else
RemoteModelDao.outstandingEntryFlag = 1;
RemoteModelDao.setOutstandingEntryFlags(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_ENQUEUE_MESSAGES | RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
/**

@ -196,6 +196,8 @@ public class ActFmSyncThread {
};
public synchronized void enqueueMessage(ClientToServerMessage<?> message, Runnable callback) {
if (!RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_ENQUEUE_MESSAGES))
return;
if (!pendingMessages.contains(message)) {
pendingMessages.add(message);
if (callback != null)

@ -147,7 +147,7 @@ public class AstridNewSyncMigrator {
@Override
public boolean shouldCreateOutstandingEntries(TagData instance) {
boolean result = lastFetchTime == 0 || (instance.containsNonNullValue(TagData.MODIFICATION_DATE) && instance.getValue(TagData.MODIFICATION_DATE) > lastFetchTime);
return result && RemoteModelDao.getOutstandingEntryFlag();
return result && RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
@Override
@ -186,9 +186,9 @@ public class AstridNewSyncMigrator {
@Override
public boolean shouldCreateOutstandingEntries(Task instance) {
if (!instance.containsNonNullValue(Task.MODIFICATION_DATE) || instance.getValue(Task.LAST_SYNC) == 0)
return RemoteModelDao.getOutstandingEntryFlag();
return RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
return (instance.getValue(Task.LAST_SYNC) < instance.getValue(Task.MODIFICATION_DATE)) && RemoteModelDao.getOutstandingEntryFlag();
return (instance.getValue(Task.LAST_SYNC) < instance.getValue(Task.MODIFICATION_DATE)) && RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
@Override

@ -5,6 +5,7 @@ import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener;
import com.todoroo.astrid.actfm.sync.ActFmSyncThread.ModelType;
import com.todoroo.astrid.actfm.sync.messages.ChangesHappened;
import com.todoroo.astrid.actfm.sync.messages.ClientToServerMessage;
import com.todoroo.astrid.dao.RemoteModelDao;
public class SyncDatabaseListener<MTYPE extends AbstractModel> implements ModelUpdateListener<MTYPE> {
@ -17,7 +18,7 @@ public class SyncDatabaseListener<MTYPE extends AbstractModel> implements ModelU
@Override
public void onModelUpdated(MTYPE model, boolean outstandingEntries) {
if (outstandingEntries) {
if (outstandingEntries && RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_ENQUEUE_MESSAGES)) {
ChangesHappened<?, ?> ch = ChangesHappened.instantiateChangesHappened(model.getId(), modelType);
enqueueMessage(model, ch);
}

@ -87,7 +87,7 @@ public class MetadataDao extends DatabaseDao<Metadata> {
TaskToTagMetadata.KEY.equals(item.getValue(Metadata.KEY))) ||
(cv.containsKey(Metadata.DELETION_DATE.name) &&
item.getValue(Metadata.DELETION_DATE) > 0)) &&
RemoteModelDao.getOutstandingEntryFlag();
RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
@Override

@ -32,23 +32,36 @@ public class RemoteModelDao<RTYPE extends RemoteModel> extends DatabaseDao<RTYPE
return super.createNew(item);
}
public static int outstandingEntryFlag = -1;
private static int outstandingEntryFlag = -1;
public static boolean getOutstandingEntryFlag() {
public static final int OUTSTANDING_FLAG_UNINITIALIZED = -1;
public static final int OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING = 1 << 0;
public static final int OUTSTANDING_ENTRY_FLAG_ENQUEUE_MESSAGES = 1 << 1;
public static void setOutstandingEntryFlags(int newValue) {
synchronized (RemoteModelDao.class) {
outstandingEntryFlag = newValue;
}
}
public static boolean getOutstandingEntryFlag(int flag) {
if (outstandingEntryFlag == -1) {
synchronized (RemoteModelDao.class) {
if (PluginServices.getActFmPreferenceService().wasLoggedIn())
outstandingEntryFlag = 1;
else
outstandingEntryFlag = 0;
int newValue = 0;
if (PluginServices.getActFmPreferenceService().isLoggedIn())
newValue = OUTSTANDING_ENTRY_FLAG_ENQUEUE_MESSAGES | OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING;
else if (PluginServices.getActFmPreferenceService().wasLoggedIn())
newValue = OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING;
outstandingEntryFlag = newValue;
}
}
return outstandingEntryFlag > 0;
return (outstandingEntryFlag & flag) > 0;
}
@Override
protected boolean shouldRecordOutstanding(RTYPE item) {
return super.shouldRecordOutstanding(item) && getOutstandingEntryFlag();
return super.shouldRecordOutstanding(item) && getOutstandingEntryFlag(OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
/**

@ -78,7 +78,7 @@ public class TagMetadataDao extends DatabaseDao<TagMetadata> {
TagMemberMetadata.KEY.equals(item.getValue(TagMetadata.KEY))) ||
(cv.containsKey(TagMetadata.DELETION_DATE.name) &&
item.getValue(TagMetadata.DELETION_DATE) > 0)) &&
RemoteModelDao.getOutstandingEntryFlag();
RemoteModelDao.getOutstandingEntryFlag(RemoteModelDao.OUTSTANDING_ENTRY_FLAG_RECORD_OUTSTANDING);
}
@Override

Loading…
Cancel
Save