Ejemplo n.º 1
0
  @Override
  public void synchronizeList(
      Object list, final boolean manual, final SyncResultCallback callback) {
    if (!(list instanceof StoreObject)) return;
    final StoreObject gtasksList = (StoreObject) list;
    if (!GtasksList.TYPE.equals(gtasksList.getValue(StoreObject.TYPE))) return;

    callback.started();
    callback.incrementMax(100);

    new Thread(
            new Runnable() {
              public void run() {
                callback.incrementProgress(50);
                try {
                  String authToken = getValidatedAuthToken();
                  callback.incrementProgress(12);
                  gtasksSyncService.waitUntilEmpty();
                  callback.incrementProgress(13);
                  final GtasksInvoker service = new GtasksInvoker(authToken);
                  synchronizeListHelper(gtasksList, service, manual, null, callback);
                } finally {
                  callback.incrementProgress(25);
                  callback.finished();
                }
              }
            })
        .start();
  }
Ejemplo n.º 2
0
  @Override
  public void synchronizeActiveTasks(final boolean manual, final SyncResultCallback callback) {
    callback.started();
    callback.incrementMax(100);

    gtasksPreferenceService.recordSyncStart();

    new Thread(
            new Runnable() {
              public void run() {
                callback.incrementProgress(50);
                String authToken = getValidatedAuthToken();
                final GtasksInvoker invoker = new GtasksInvoker(authToken);
                try {
                  gtasksListService.updateLists(invoker.allGtaskLists());
                } catch (GoogleTasksException e) {
                  handler.handleException("gtasks-sync=io", e, e.getType()); // $NON-NLS-1$
                } catch (IOException e) {
                  handler.handleException("gtasks-sync=io", e, e.toString()); // $NON-NLS-1$
                }

                StoreObject[] lists = gtasksListService.getLists();
                if (lists.length == 0) {
                  finishSync(callback);
                  return;
                }
                callback.incrementMax(25 * lists.length);
                final AtomicInteger finisher = new AtomicInteger(lists.length);

                for (final StoreObject list : lists) {
                  new Thread(
                          new Runnable() {
                            @Override
                            public void run() {
                              synchronizeListHelper(list, invoker, manual, handler, callback);
                              callback.incrementProgress(25);
                              if (finisher.decrementAndGet() == 0) {
                                pushUpdated(invoker, callback);
                                finishSync(callback);
                              }
                            }
                          })
                      .start();
                }
              }
            })
        .start();
  }