Fixed bugs with postponing the calendar dialogs

pull/14/head
Sam Bosley 12 years ago
parent 575cd73adb
commit 54de0bddda

@ -21,7 +21,6 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
public static final int REQUEST_CODE_CAL_REMINDER = 100;
public static final String BROADCAST_CALENDAR_REMINDER = Constants.PACKAGE + ".CALENDAR_EVENT";
public static final String TOKEN_EVENT_ID = "eventId";
private static final String[] EVENTS_PROJECTION = {
Calendars.EVENTS_DTSTART_COL,
@ -40,8 +39,17 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
return;
try {
ContentResolver cr = context.getContentResolver();
long eventId = intent.getLongExtra(TOKEN_EVENT_ID, -1);
boolean fromPostpone = intent.getBooleanExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, false);
Uri data = intent.getData();
if (data == null)
return;
String uriString = data.toString();
int pathIndex = uriString.indexOf("://");
if (pathIndex > 0)
pathIndex += 3;
else return;
long eventId = Long.parseLong(uriString.substring(pathIndex));
boolean fromPostpone = CalendarAlarmScheduler.URI_PREFIX_POSTPONE.equals(data.getScheme());
if (eventId > 0) {
Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
@ -61,9 +69,17 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
long startTime = event.getLong(dtstartIndex);
long endTime = event.getLong(dtendIndex);
boolean shouldShowReminder;
if (fromPostpone) {
long timeAfter = DateUtilities.now() - endTime;
shouldShowReminder = (timeAfter > DateUtilities.ONE_MINUTE * 2);
} else {
long timeUntil = startTime - DateUtilities.now();
shouldShowReminder = (timeUntil > 0 && timeUntil < DateUtilities.ONE_MINUTE * 20);
}
if (timeUntil > 0 && timeUntil < DateUtilities.ONE_MINUTE * 20) {
if (shouldShowReminder) {
// Get attendees
Cursor attendees = cr.query(Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_ATTENDEES),
ATTENDEES_PROJECTION,
@ -93,10 +109,11 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
Intent reminderActivity = new Intent(context, CalendarReminderActivity.class);
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES, names);
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_EMAILS, emails);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_ID, eventId);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_NAME, title);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_START_TIME, startTime);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_END_TIME, endTime);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, true);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, fromPostpone);
reminderActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(reminderActivity);
}
@ -109,7 +126,7 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
event.close();
}
}
} catch (IllegalArgumentException e) { // Some cursor read failed
} catch (IllegalArgumentException e) { // Some cursor read failed, or badly formed uri
e.printStackTrace();
}
}

@ -8,6 +8,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.timsu.astrid.R;
@ -20,6 +21,9 @@ public class CalendarAlarmScheduler {
public static final String TAG = "calendar-alarm";
public static final String URI_PREFIX = "cal-reminder";
public static final String URI_PREFIX_POSTPONE = "cal-postpone";
public static void scheduleAllCalendarAlarms(Context context) {
if (!Preferences.getBoolean(R.string.p_calendar_reminders, true))
return;
@ -46,7 +50,7 @@ public class CalendarAlarmScheduler {
long start = events.getLong(dtstartIndex);
long id = events.getLong(idIndex);
eventAlarm.putExtra(CalendarAlarmReceiver.TOKEN_EVENT_ID, id);
eventAlarm.setData(Uri.parse(URI_PREFIX + "://" + id));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, eventAlarm, 0);

@ -8,7 +8,9 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
@ -29,6 +31,7 @@ import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.utility.Constants;
@SuppressWarnings("nls")
public class CalendarReminderActivity extends Activity {
@ -229,9 +232,7 @@ public class CalendarReminderActivity extends Activity {
Intent eventAlarm = new Intent(this, CalendarAlarmReceiver.class);
eventAlarm.setAction(CalendarAlarmReceiver.BROADCAST_CALENDAR_REMINDER);
eventAlarm.putExtra(CalendarAlarmReceiver.TOKEN_EVENT_ID, eventId);
eventAlarm.putExtra(TOKEN_FROM_POSTPONE, true);
eventAlarm.setData(Uri.parse(CalendarAlarmScheduler.URI_PREFIX_POSTPONE + "://" + eventId));
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, eventAlarm, 0);
@ -239,6 +240,8 @@ public class CalendarReminderActivity extends Activity {
am.cancel(pendingIntent);
long alarmTime = endTime + DateUtilities.ONE_MINUTE * 5;
if (Constants.DEBUG)
Log.w(CalendarAlarmScheduler.TAG, "Scheduling calendar alarm for " + new Date(alarmTime));
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingIntent);
finish();
}

Loading…
Cancel
Save