Fix for AST-363

Specifically, what this fixes is the case where a task has multiple alarms
in the future. Previously, only one of the alarms would run, but now they
are all scheduled as separate alarms and should all fire.

If there are other bugs not covered by this, please file another bug.
pull/14/head
Tim Su 14 years ago
parent 25ba0e3b5f
commit 7ec45dd242

@ -92,7 +92,7 @@ public class AlarmService {
* @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
*/
private TodorooCursor<Metadata> getActiveAlarms() {
return PluginServices.getMetadataService().query(Query.select(AlarmFields.TIME).
return PluginServices.getMetadataService().query(Query.select(Metadata.ID, Metadata.TASK, AlarmFields.TIME).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(Criterion.and(TaskCriteria.isActive(), MetadataCriteria.withKey(AlarmFields.METADATA_KEY))));
}
@ -102,8 +102,8 @@ public class AlarmService {
* @param properties
* @return todoroo cursor. PLEASE CLOSE THIS CURSOR!
*/
private TodorooCursor<Metadata> getAlarmsForTask(long taskId) {
return PluginServices.getMetadataService().query(Query.select(Metadata.TASK, AlarmFields.TIME).
private TodorooCursor<Metadata> getActiveAlarmsForTask(long taskId) {
return PluginServices.getMetadataService().query(Query.select(Metadata.ID, Metadata.TASK, AlarmFields.TIME).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(Criterion.and(TaskCriteria.isActive(),
MetadataCriteria.byTaskAndwithKey(taskId, AlarmFields.METADATA_KEY))));
@ -134,7 +134,7 @@ public class AlarmService {
* @param task
*/
public void scheduleAlarms(long taskId) {
TodorooCursor<Metadata> cursor = getAlarmsForTask(taskId);
TodorooCursor<Metadata> cursor = getActiveAlarmsForTask(taskId);
try {
Metadata alarm = new Metadata();
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
@ -164,14 +164,13 @@ public class AlarmService {
Context context = ContextManager.getContext();
Intent intent = new Intent(context, Notifications.class);
intent.setType("ALARM" + Long.toString(taskId)); //$NON-NLS-1$
intent.setAction(Integer.toString(type));
intent.setAction("ALARM" + alarm.getId()); //$NON-NLS-1$
intent.putExtra(Notifications.ID_KEY, taskId);
intent.putExtra(Notifications.TYPE_KEY, type);
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
intent, 0);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, (int)alarm.getId(),
intent, PendingIntent.FLAG_UPDATE_CURRENT);
long time = alarm.getValue(AlarmFields.TIME);
if(time == 0 || time == NO_ALARM)
@ -179,7 +178,7 @@ public class AlarmService {
else if(time > DateUtilities.now()) {
if(Constants.DEBUG)
Log.e("Astrid", "Alarm (" + taskId + ", " + type +
") set for " + new Date(time));
", " + alarm.getId() + ") set for " + new Date(time));
am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
}

@ -96,7 +96,7 @@ public class Notifications extends BroadcastReceiver {
if(!showTaskNotification(id, type, reminder)) {
notificationManager.cancel((int)id);
}
// shutdown the VoiceOutputAssistant for now
try {
VoiceOutputService.getVoiceOutputInstance().onDestroy();
} catch (VerifyError e) {
@ -151,8 +151,9 @@ public class Notifications extends BroadcastReceiver {
String text = reminder + " " + taskTitle; //$NON-NLS-1$
Intent notifyIntent = new Intent(context, NotificationActivity.class);
notifyIntent.setAction("NOTIFY" + id); //$NON-NLS-1$
notifyIntent.putExtra(NotificationActivity.TOKEN_ID, id);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
showNotification((int)id, notifyIntent, type, title, text, nonstopMode);
return true;
@ -184,7 +185,7 @@ public class Notifications extends BroadcastReceiver {
}
PendingIntent pendingIntent = PendingIntent.getActivity(context,
notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// set up properties (name and icon) for the notification
int icon;

Loading…
Cancel
Save