Use real token in actfm sync thread

pull/14/head
Sam Bosley 13 years ago
parent d8da952cc7
commit d4b02c174b

@ -8,6 +8,8 @@ import java.util.Queue;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import android.util.Log;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.Pair; import com.todoroo.andlib.utility.Pair;
@ -46,6 +48,11 @@ public class ActFmSyncThread {
@Autowired @Autowired
private ActFmInvoker actFmInvoker; private ActFmInvoker actFmInvoker;
@Autowired
private ActFmPreferenceService actFmPreferenceService;
private String token;
public static enum ModelType { public static enum ModelType {
TYPE_TASK, TYPE_TASK,
TYPE_TAG TYPE_TAG
@ -100,7 +107,7 @@ public class ActFmSyncThread {
messages.add(getBriefMe(TagData.class)); messages.add(getBriefMe(TagData.class));
} }
if (!messages.isEmpty()) { if (!messages.isEmpty() && checkForToken()) {
JSONArray payload = new JSONArray(); JSONArray payload = new JSONArray();
for (ClientToServerMessage<?> message : messages) { for (ClientToServerMessage<?> message : messages) {
JSONObject serialized = message.serializeToJSON(); JSONObject serialized = message.serializeToJSON();
@ -109,7 +116,7 @@ public class ActFmSyncThread {
} }
try { try {
JSONObject response = actFmInvoker.invoke("sync", "data", payload, "token", ""); JSONObject response = actFmInvoker.invoke("sync", "data", payload, "token", token);
// process responses // process responses
JSONArray serverMessagesJson = response.optJSONArray("messages"); JSONArray serverMessagesJson = response.optJSONArray("messages");
if (serverMessagesJson != null) { if (serverMessagesJson != null) {
@ -132,6 +139,7 @@ public class ActFmSyncThread {
} }
} catch (Exception e) { } catch (Exception e) {
// In the worst case, restart thread if something goes wrong // In the worst case, restart thread if something goes wrong
Log.e("actfm-sync", "Unexpected sync thread exception", e);
thread = null; thread = null;
startSyncThread(); startSyncThread();
} }
@ -160,4 +168,11 @@ public class ActFmSyncThread {
return true; return true;
} }
private boolean checkForToken() {
if(!actFmPreferenceService.isLoggedIn())
return false;
token = actFmPreferenceService.getToken();
return true;
}
} }

Loading…
Cancel
Save