@Override public void run() { // // Drill into the JSON response to find the content body // JSONObject resp = (JSONObject) new JSONTokener(content.toString()) // .nextValue(); // // JSONObject query = resp.getJSONObject("uuid"); // // JSONObject pages = query.getJSONObject("pages"); // // JSONObject page = pages.getJSONObject((String) // // pages.keys().next()); // // JSONArray revisions = page.getJSONArray("revisions"); // // JSONObject revision = revisions.getJSONObject(0); // String uuid = resp.getString("uuid"); // inform(uuid, Events.FINISHED); // } catch (IOException e) { // Log.e(TAG, e.toString()); // inform("Error on syncing" + e.toString(), Events.FINISHED); // e.printStackTrace(); try { dbAccessor.beginTransaction(); Long now = Long.valueOf(System.currentTimeMillis()); Log.d(TAG, "Sync started at " + now.toString()); // Get remote Uuid and it's lastUpdated time Pair<String, Long> remoteInfo = getRemoteInfo(); inform(remoteInfo.getFirst(), Events.TEXT); Long lastUpdated = dbAccessor.getLastUpdated(remoteInfo.getFirst()); inform(lastUpdated.toString(), Events.TEXT); // TODO Upload local updates // Download remote updates processRemoteUpdates(lastUpdated); dbAccessor.setTransactionSuccessful(); inform("Finished", Events.FINISHED); } catch (Exception e) { Log.e(TAG, e.toString()); inform("Error on syncing " + e.toString(), Events.ERROR); e.printStackTrace(); } finally { dbAccessor.endTransaction(); } }