@Override public void onReceive(Context context, Intent intent) { ContextManager.setContext(context); DependencyInjectionService.getInstance().inject(this); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if (taskId == -1) return; Task task = PluginServices.getTaskService().fetchById(taskId, Task.PROPERTIES); if (task == null || !task.isCompleted()) return; String recurrence = task.getValue(Task.RECURRENCE); if (recurrence != null && recurrence.length() > 0) { long newDueDate; try { newDueDate = computeNextDueDate(task, recurrence); if (newDueDate == -1) return; } catch (ParseException e) { PluginServices.getExceptionService().reportError("repeat-parse", e); // $NON-NLS-1$ return; } StatisticsService.reportEvent(StatisticsConstants.V2_TASK_REPEAT); long oldDueDate = task.getValue(Task.DUE_DATE); long repeatUntil = task.getValue(Task.REPEAT_UNTIL); boolean repeatFinished = repeatUntil > 0 && newDueDate >= repeatUntil; if (repeatFinished) { Intent repeatFinishedIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEAT_FINISHED); repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId()); repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate); repeatFinishedIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate); context.sendOrderedBroadcast(repeatFinishedIntent, null); return; } rescheduleTask(task, newDueDate); // send a broadcast Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId()); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate); context.sendOrderedBroadcast(broadcastIntent, null); Flags.set(Flags.REFRESH); return; } }
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); long taskId = intent.getLongExtra(AstridApiConstants.EXTRAS_TASK_ID, -1); if (taskId == -1) { return; } Task task = taskService.fetchById(taskId, Task.PROPERTIES); if (task == null || !task.isCompleted()) { return; } String recurrence = task.sanitizedRecurrence(); boolean repeatAfterCompletion = task.repeatAfterCompletion(); if (recurrence != null && recurrence.length() > 0) { long newDueDate; try { newDueDate = computeNextDueDate(task, recurrence, repeatAfterCompletion); if (newDueDate == -1) { return; } } catch (ParseException e) { log.error(e.getMessage(), e); return; } long oldDueDate = task.getDueDate(); long repeatUntil = task.getRepeatUntil(); if (repeatFinished(newDueDate, repeatUntil)) { return; } rescheduleTask(context, gcalHelper, taskService, task, newDueDate); // send a broadcast Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId()); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_OLD_DUE_DATE, oldDueDate); broadcastIntent.putExtra(AstridApiConstants.EXTRAS_NEW_DUE_DATE, newDueDate); context.sendOrderedBroadcast(broadcastIntent, null); Flags.set(Flags.REFRESH); } }