Suppress widget updates during sync

pull/14/head
Sam Bosley 13 years ago
parent bba063739f
commit 97c3480732

@ -14,6 +14,7 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -25,6 +26,7 @@ import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.messages.BriefMe; import com.todoroo.astrid.actfm.sync.messages.BriefMe;
import com.todoroo.astrid.actfm.sync.messages.ChangesHappened; import com.todoroo.astrid.actfm.sync.messages.ChangesHappened;
@ -58,6 +60,7 @@ import com.todoroo.astrid.data.TaskListMetadataOutstanding;
import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.data.TaskOutstanding;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
import com.todoroo.astrid.data.UserActivity; import com.todoroo.astrid.data.UserActivity;
import com.todoroo.astrid.widget.TasksWidget;
public class ActFmSyncThread { public class ActFmSyncThread {
@ -316,6 +319,7 @@ public class ActFmSyncThread {
String time = response.optString("time"); String time = response.optString("time");
JSONArray serverMessagesJson = response.optJSONArray("messages"); JSONArray serverMessagesJson = response.optJSONArray("messages");
if (serverMessagesJson != null) { if (serverMessagesJson != null) {
setWidgetSuppression(true);
for (int i = 0; i < serverMessagesJson.length(); i++) { for (int i = 0; i < serverMessagesJson.length(); i++) {
JSONObject serverMessageJson = serverMessagesJson.optJSONObject(i); JSONObject serverMessageJson = serverMessagesJson.optJSONObject(i);
if (serverMessageJson != null) { if (serverMessageJson != null) {
@ -331,6 +335,7 @@ public class ActFmSyncThread {
JSONArray errors = response.optJSONArray("errors"); JSONArray errors = response.optJSONArray("errors");
boolean errorsExist = (errors != null && errors.length() > 0); boolean errorsExist = (errors != null && errors.length() > 0);
replayOutstandingChanges(errorsExist); replayOutstandingChanges(errorsExist);
setWidgetSuppression(false);
} }
batchSize = Math.min(batchSize, messageBatch.size()) * 2; batchSize = Math.min(batchSize, messageBatch.size()) * 2;
@ -378,6 +383,18 @@ public class ActFmSyncThread {
return isTimeForBackgroundSync; return isTimeForBackgroundSync;
} }
private void setWidgetSuppression(boolean suppress) {
long date = suppress ? DateUtilities.now() : 0;
TasksWidget.suppressUpdateFlag = date;
if (date == 0) {
Context context = ContextManager.getContext();
if (context != null) {
TasksWidget.updateWidgets(context);
}
}
}
public void repopulateQueueFromOutstandingTables() { public void repopulateQueueFromOutstandingTables() {
syncLog("Constructing queue from outstanding tables"); //$NON-NLS-1$ syncLog("Constructing queue from outstanding tables"); //$NON-NLS-1$
constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao); constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao);

Loading…
Cancel
Save