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; }
protected void initializeTaskListMetadata() { TagData td = getActiveTagData(); String tdId; if (td == null) { String filterId = null; String prefId = null; if (isInbox) { filterId = TaskListMetadata.FILTER_ID_ALL; prefId = SubtasksUpdater.ACTIVE_TASKS_ORDER; } else if (isTodayFilter) { filterId = TaskListMetadata.FILTER_ID_TODAY; prefId = SubtasksUpdater.TODAY_TASKS_ORDER; } if (!TextUtils.isEmpty(filterId)) { taskListMetadata = taskListMetadataDao.fetchByTagId(filterId, TaskListMetadata.PROPERTIES); if (taskListMetadata == null) { String defaultOrder = preferences.getStringValue(prefId); if (TextUtils.isEmpty(defaultOrder)) { defaultOrder = "[]"; // $NON-NLS-1$ } defaultOrder = SubtasksHelper.convertTreeToRemoteIds(taskService, defaultOrder); taskListMetadata = new TaskListMetadata(); taskListMetadata.setFilter(filterId); taskListMetadata.setTaskIDs(defaultOrder); taskListMetadataDao.createNew(taskListMetadata); } } } else { tdId = td.getUuid(); taskListMetadata = taskListMetadataDao.fetchByTagId(td.getUuid(), TaskListMetadata.PROPERTIES); if (taskListMetadata == null && !RemoteModel.isUuidEmpty(tdId)) { taskListMetadata = new TaskListMetadata(); taskListMetadata.setTagUUID(tdId); taskListMetadataDao.createNew(taskListMetadata); } } postLoadTaskListMetadata(); }