More efficient sync callback execution

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

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

@ -37,16 +37,6 @@ public class ProgressBarSyncResultCallback extends SyncResultCallbackAdapter {
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
public void finished() {
if(providers.decrementAndGet() == 0) {

Loading…
Cancel
Save