More efficient sync callback execution

pull/14/head
Sam Bosley 12 years ago
parent 6a1a0edc46
commit 3eb4414389

@ -3,9 +3,11 @@ package com.todoroo.astrid.actfm.sync;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -267,17 +269,13 @@ public class ActFmSyncThread {
batchSize = Math.max(batchSize / 2, 1); batchSize = Math.max(batchSize / 2, 1);
} }
boolean didDefaultRefreshThisLoop = false; Set<Runnable> callbacksExecutedThisLoop = new HashSet<Runnable>();
for (ClientToServerMessage<?> message : messageBatch) { for (ClientToServerMessage<?> message : messageBatch) {
try { try {
Runnable r = pendingCallbacks.remove(message); Runnable r = pendingCallbacks.remove(message);
if (r != null) { if (r != null && !callbacksExecutedThisLoop.contains(r)) {
if (r == DEFAULT_REFRESH_RUNNABLE) {
if (didDefaultRefreshThisLoop)
continue;
didDefaultRefreshThisLoop = true;
}
r.run(); r.run();
callbacksExecutedThisLoop.add(r);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(ERROR_TAG, "Unexpected exception executing sync callback", e); Log.e(ERROR_TAG, "Unexpected exception executing sync callback", e);

@ -37,16 +37,6 @@ public class ProgressBarSyncResultCallback extends SyncResultCallbackAdapter {
progressBar.setMax(0); progressBar.setMax(0);
} }
public ProgressBarSyncResultCallback(Activity activity, ProgressBar pBar,
Runnable onFinished) {
this.progressBar = pBar;
this.activity = activity;
this.onFinished = onFinished;
progressBar.setProgress(0);
progressBar.setMax(0);
}
@Override @Override
public void finished() { public void finished() {
if(providers.decrementAndGet() == 0) { if(providers.decrementAndGet() == 0) {

Loading…
Cancel
Save