示例#1
0
  public static ActFmSyncThread initializeSyncComponents(
      TaskDao taskDao,
      TagDataDao tagDataDao,
      UserActivityDao userActivityDao,
      TaskAttachmentDao taskAttachmentDao,
      TaskListMetadataDao taskListMetadataDao) {
    if (instance == null) {
      synchronized (ActFmSyncThread.class) {
        if (instance == null) {
          List<ClientToServerMessage<?>> syncQueue =
              Collections.synchronizedList(new LinkedList<ClientToServerMessage<?>>());
          ActFmSyncMonitor monitor = ActFmSyncMonitor.getInstance();
          ActFmSyncWaitingPool waitingPool = ActFmSyncWaitingPool.getInstance();

          instance = new ActFmSyncThread(syncQueue, monitor);

          taskDao.addListener(new SyncDatabaseListener<Task>(instance, ModelType.TYPE_TASK));
          tagDataDao.addListener(new SyncDatabaseListener<TagData>(instance, ModelType.TYPE_TAG));
          userActivityDao.addListener(
              new SyncDatabaseListener<UserActivity>(instance, ModelType.TYPE_ACTIVITY));
          taskAttachmentDao.addListener(
              new SyncDatabaseListener<TaskAttachment>(instance, ModelType.TYPE_ATTACHMENT));
          taskListMetadataDao.addListener(
              new TaskListMetadataSyncDatabaseListener(
                  instance, waitingPool, ModelType.TYPE_TASK_LIST_METADATA));

          instance.startSyncThread();
        }
      }
    }
    return instance;
  }
示例#2
0
  @SuppressWarnings("nls")
  public void initialize() {
    new Thread(
            new Runnable() {
              public void run() {
                while (true) {
                  SyncOnSaveOperation op;
                  try {
                    op = operationQueue.take();
                  } catch (InterruptedException e) {
                    continue;
                  }
                  try {
                    if (!gtasksPreferenceService.isOngoing()) {
                      GtasksInvoker invoker = new GtasksInvoker(gtasksPreferenceService.getToken());
                      if (op instanceof TaskPushOp) {
                        TaskPushOp taskPush = (TaskPushOp) op;
                        if (DateUtilities.now() - taskPush.creationDate < 1000)
                          AndroidUtilities.sleepDeep(
                              1000 - (DateUtilities.now() - taskPush.creationDate));
                        pushTaskOnSave(
                            taskPush.model, taskPush.model.getMergedValues(), invoker, false);
                      } else if (op instanceof MoveOp) {
                        MoveOp move = (MoveOp) op;
                        pushMetadataOnSave(move.metadata, invoker);
                      }
                    }
                  } catch (IOException e) {
                    Crittercism.logHandledException(e);
                    Log.w("gtasks-sync-error", "Sync on save failed", e);
                  }
                }
              }
            })
        .start();

    taskDao.addListener(
        new ModelUpdateListener<Task>() {
          public void onModelUpdated(final Task model) {
            if (model.checkAndClearTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC)) return;
            if (gtasksPreferenceService
                .isOngoing()) // Don't try and sync changes that occur during a normal sync
            return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null || !checkForToken()) return;
            if (!checkValuesForProperties(
                setValues, TASK_PROPERTIES)) // None of the properties we sync were updated
            return;

            Task toPush = taskDao.fetch(model.getId(), TASK_PROPERTIES);
            operationQueue.offer(new TaskPushOp(toPush));
          }
        });
  }
示例#3
0
  public void initialize() {
    taskDao.addListener(
        new ModelUpdateListener<Task>() {
          @Override
          public void onModelUpdated(final Task model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null
                || !checkForToken()
                || setValues.containsKey(RemoteModel.REMOTE_ID_PROPERTY_NAME)) return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        // sleep so metadata associated with task is saved
                        AndroidUtilities.sleepDeep(1000L);
                        pushTaskOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });

    updateDao.addListener(
        new ModelUpdateListener<Update>() {
          @Override
          public void onModelUpdated(final Update model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null || !checkForToken() || model.getValue(Update.REMOTE_ID) > 0)
              return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        pushUpdateOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });

    tagDataDao.addListener(
        new ModelUpdateListener<TagData>() {
          @Override
          public void onModelUpdated(final TagData model) {
            if (Flags.checkAndClear(Flags.SUPPRESS_SYNC)) return;
            final ContentValues setValues = model.getSetValues();
            if (setValues == null
                || !checkForToken()
                || setValues.containsKey(RemoteModel.REMOTE_ID_PROPERTY_NAME)) return;

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        pushTagDataOnSave(model, setValues);
                      }
                    })
                .start();
          }
        });
  }