mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
/**
|
|
* Copyright (c) 2012 Todoroo Inc
|
|
*
|
|
* See the file "LICENSE" for the full license governing this code.
|
|
*/
|
|
package com.todoroo.astrid.timers;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
|
|
import com.todoroo.astrid.api.AstridApiConstants;
|
|
import com.todoroo.astrid.dao.TaskDao;
|
|
import com.todoroo.astrid.data.Task;
|
|
|
|
import org.tasks.injection.BroadcastComponent;
|
|
import org.tasks.injection.InjectingBroadcastReceiver;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
public class TimerTaskCompleteListener extends InjectingBroadcastReceiver {
|
|
|
|
public static void broadcast(Context context, long taskId) {
|
|
Intent intent = new Intent(context, TimerTaskCompleteListener.class);
|
|
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
|
|
context.sendBroadcast(intent);
|
|
}
|
|
|
|
@Inject TaskDao taskDao;
|
|
@Inject TimerPlugin timerPlugin;
|
|
|
|
@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 = taskDao.fetch(taskId, Task.ID, Task.ELAPSED_SECONDS,
|
|
Task.TIMER_START);
|
|
if(task == null || task.getTimerStart() == 0) {
|
|
return;
|
|
}
|
|
|
|
timerPlugin.stopTimer(task);
|
|
}
|
|
|
|
@Override
|
|
protected void inject(BroadcastComponent component) {
|
|
component.inject(this);
|
|
}
|
|
}
|