Example #1
0
  public void refreshData() {
    if (!task.containsNonNullValue(Task.UUID)) {
      return;
    }

    ActFmSyncThread.getInstance()
        .enqueueMessage(
            new BriefMe<UserActivity>(
                UserActivity.class,
                null,
                task.getValue(Task.USER_ACTIVITIES_PUSHED_AT),
                BriefMe.TASK_ID_KEY,
                task.getUuid()),
            callback);
    ActFmSyncThread.getInstance()
        .enqueueMessage(
            new BriefMe<TaskAttachment>(
                TaskAttachment.class,
                null,
                task.getValue(Task.ATTACHMENTS_PUSHED_AT),
                BriefMe.TASK_ID_KEY,
                task.getUuid()),
            new SyncMessageCallback() {
              @Override
              public void runOnSuccess() {
                if (activity != null) {
                  activity.runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          TaskEditFragment tef = activity.getTaskEditFragment();
                          if (tef != null) {
                            tef.refreshFilesDisplay();
                          }
                        }
                      });
                }
              }

              @Override
              public void runOnErrors(List<JSONArray> errors) {
                /**/
              }
            });
    new FetchHistory<Task>(
            taskDao,
            Task.HISTORY_FETCH_DATE,
            Task.HISTORY_HAS_MORE,
            NameMaps.TABLE_ID_TASKS,
            task.getUuid(),
            task.getValue(Task.TITLE),
            task.getValue(Task.HISTORY_FETCH_DATE),
            0,
            callback)
        .execute();
  }
Example #2
0
 @Override
 public void onReceive(Context context, Intent intent) {
   lastSyncFromNetworkChange = Preferences.getLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, 0L);
   if (DateUtilities.now() - lastSyncFromNetworkChange > DateUtilities.ONE_MINUTE * 10) {
     NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
     if (info != null
         && NetworkInfo.State.CONNECTED.equals(info.getState())
         && PluginServices.getActFmPreferenceService().isLoggedIn()) {
       ActFmSyncThread syncThread = ActFmSyncThread.getInstance();
       syncThread.repopulateQueueFromOutstandingTables();
       Preferences.setLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, DateUtilities.now());
     }
   }
 }
Example #3
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;
  }
Example #4
0
 protected void enqueueMessage(MTYPE model, ClientToServerMessage<?> message) {
   actFmSyncThread.enqueueMessage(message, null);
 }