Added option to postpone creation of list for cal event

pull/14/head
Sam Bosley 12 years ago
parent fe3988b200
commit 39596a6dc9

@ -25,6 +25,7 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
private static final String[] EVENTS_PROJECTION = {
Calendars.EVENTS_DTSTART_COL,
Calendars.EVENTS_DTEND_COL,
Calendars.EVENTS_NAME_COL,
};
@ -40,6 +41,7 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
try {
ContentResolver cr = context.getContentResolver();
long eventId = intent.getLongExtra(TOKEN_EVENT_ID, -1);
boolean fromPostpone = intent.getBooleanExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, false);
if (eventId > 0) {
Uri eventUri = Calendars.getCalendarContentUri(Calendars.CALENDAR_CONTENT_EVENTS);
@ -51,11 +53,14 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
null);
try {
if (event.moveToFirst()) {
int timeIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
int dtstartIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
int dtendIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_DTEND_COL);
int titleIndex = event.getColumnIndexOrThrow(Calendars.EVENTS_NAME_COL);
String title = event.getString(titleIndex);
long startTime = event.getLong(timeIndex);
long startTime = event.getLong(dtstartIndex);
long endTime = event.getLong(dtendIndex);
long timeUntil = startTime - DateUtilities.now();
if (timeUntil > 0 && timeUntil < DateUtilities.ONE_MINUTE * 20) {
@ -89,7 +94,9 @@ public class CalendarAlarmReceiver extends BroadcastReceiver {
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_NAMES, names);
reminderActivity.putStringArrayListExtra(CalendarReminderActivity.TOKEN_EMAILS, emails);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_NAME, title);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_TIME, startTime);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_START_TIME, startTime);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_EVENT_END_TIME, endTime);
reminderActivity.putExtra(CalendarReminderActivity.TOKEN_FROM_POSTPONE, true);
reminderActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(reminderActivity);
}

@ -37,13 +37,13 @@ public class CalendarAlarmScheduler {
try {
if (events.getCount() > 0) {
int idIndex = events.getColumnIndex(Calendars.ID_COLUMN_NAME);
int timeIndex = events.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
Intent eventAlarm = new Intent(context, CalendarAlarmReceiver.class);
eventAlarm.setAction(CalendarAlarmReceiver.BROADCAST_CALENDAR_REMINDER);
int dtstartIndex = events.getColumnIndexOrThrow(Calendars.EVENTS_DTSTART_COL);
for (events.moveToFirst(); !events.isAfterLast(); events.moveToNext()) {
long start = events.getLong(timeIndex);
Intent eventAlarm = new Intent(context, CalendarAlarmReceiver.class);
eventAlarm.setAction(CalendarAlarmReceiver.BROADCAST_CALENDAR_REMINDER);
long start = events.getLong(dtstartIndex);
long id = events.getLong(idIndex);
eventAlarm.putExtra(CalendarAlarmReceiver.TOKEN_EVENT_ID, id);

@ -3,6 +3,9 @@ package com.todoroo.astrid.gcal;
import java.util.Date;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@ -32,8 +35,12 @@ public class CalendarReminderActivity extends Activity {
public static final String TOKEN_NAMES = "names";
public static final String TOKEN_EMAILS = "emails";
public static final String TOKEN_EVENT_ID = "eventId";
public static final String TOKEN_EVENT_NAME = "eventName";
public static final String TOKEN_EVENT_TIME = "eventTime";
public static final String TOKEN_EVENT_START_TIME = "eventStartTime";
public static final String TOKEN_EVENT_END_TIME = "eventEndTime";
public static final String TOKEN_FROM_POSTPONE = "fromPostpone";
private static final String PREF_IGNORE_PRESSES = "calEventsIgnored";
@ -44,10 +51,15 @@ public class CalendarReminderActivity extends Activity {
private TagDataService tagDataService;
private String eventName;
private long eventTime;
private long startTime;
private long endTime;
private long eventId;
private boolean fromPostpone;
private TextView ignoreButton;
private TextView createListButton;
private TextView postponeButton;
private View dismissButton;
private View ignoreSettingsButton;
@ -102,10 +114,14 @@ public class CalendarReminderActivity extends Activity {
Intent intent = getIntent();
fromPostpone = intent.getBooleanExtra(TOKEN_FROM_POSTPONE, false);
eventId = intent.getLongExtra(TOKEN_EVENT_ID, -1);
eventName = intent.getStringExtra(TOKEN_EVENT_NAME);
eventTime = intent.getLongExtra(TOKEN_EVENT_TIME, DateUtilities.now());
startTime = intent.getLongExtra(TOKEN_EVENT_START_TIME, DateUtilities.now());
endTime = intent.getLongExtra(TOKEN_EVENT_END_TIME, DateUtilities.now() + DateUtilities.ONE_HOUR);
createListButton = (TextView) findViewById(R.id.create_list);
postponeButton = (TextView) findViewById(R.id.postpone);
ignoreButton = (TextView) findViewById(R.id.ignore);
ignoreSettingsButton = findViewById(R.id.ignore_settings);
dismissButton = findViewById(R.id.dismiss);
@ -117,12 +133,21 @@ public class CalendarReminderActivity extends Activity {
private void setupUi() {
((TextView) findViewById(R.id.reminder_title))
.setText(getString(R.string.CRA_title, eventName));
.setText(getString(R.string.CRA_title));
TextView dialogView = (TextView) findViewById(R.id.reminder_message);
dialogView.setText(getString(R.string.CRA_speech_bubble));
String speechText;
if (fromPostpone)
speechText = getString(R.string.CRA_speech_bubble_end, eventName);
else
speechText = getString(R.string.CRA_speech_bubble_start, eventName);
dialogView.setText(speechText);
createListButton.setBackgroundColor(getResources().getColor(ThemeService.getThemeColor()));
if (fromPostpone)
postponeButton.setVisibility(View.GONE);
}
private void addListeners() {
@ -138,6 +163,14 @@ public class CalendarReminderActivity extends Activity {
}
});
if (!fromPostpone)
postponeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
postpone();
}
});
createListButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -162,7 +195,7 @@ public class CalendarReminderActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
createNewList(tag.getValue(TagData.NAME) + " "
+ DateUtilities.getDateStringHideYear(CalendarReminderActivity.this, new Date(eventTime)));
+ DateUtilities.getDateStringHideYear(CalendarReminderActivity.this, new Date(startTime)));
}
},
new DialogInterface.OnClickListener() {
@ -190,4 +223,23 @@ public class CalendarReminderActivity extends Activity {
dismissButton.performClick(); // finish with animation
}
private void postpone() {
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
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);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
CalendarAlarmReceiver.REQUEST_CODE_CAL_REMINDER, eventAlarm, 0);
am.cancel(pendingIntent);
long alarmTime = endTime + DateUtilities.ONE_MINUTE * 5;
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pendingIntent);
finish();
}
}

@ -35,6 +35,7 @@ public class Calendars {
public static final String CALENDARS_DISPLAY_COL = (USE_ICS_NAMES ? CalendarContract.Calendars.CALENDAR_DISPLAY_NAME : "displayName");
public static final String CALENDARS_ACCESS_LEVEL_COL = (USE_ICS_NAMES ? CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL : "access_level");
public static final String EVENTS_DTSTART_COL = (USE_ICS_NAMES ? CalendarContract.Events.DTSTART : "dtstart");
public static final String EVENTS_DTEND_COL = (USE_ICS_NAMES ? CalendarContract.Events.DTEND : "dtend");
public static final String EVENTS_NAME_COL = (USE_ICS_NAMES ? CalendarContract.Events.TITLE : "title");
public static final String ATTENDEES_EVENT_ID_COL = (USE_ICS_NAMES ? CalendarContract.Attendees.EVENT_ID : "event_id");
public static final String ATTENDEES_NAME_COL = (USE_ICS_NAMES ? CalendarContract.Attendees.ATTENDEE_NAME : "attendeeName");

@ -58,6 +58,19 @@
android:textSize="24sp"
android:gravity="center"
android:text="@string/CRA_create_list"/>
<TextView
android:id="@+id/postpone"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textColor="@android:color/white"
android:textSize="24sp"
android:gravity="center"
android:background="#707070"
android:text="@string/CRA_postpone"/>
<RelativeLayout
android:layout_width="fill_parent"
@ -81,6 +94,7 @@
android:layout_alignParentRight="true"
android:layout_width="35dip"
android:layout_height="35dip"
android:padding="4dip"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/single_gear"/>

@ -95,6 +95,7 @@
android:layout_alignParentRight="true"
android:layout_width="35dip"
android:layout_height="35dip"
android:padding="4dip"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/single_gear"/>

@ -14,7 +14,7 @@
<ListView
android:id="@+id/members_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<LinearLayout

@ -525,8 +525,8 @@
<!-- Calendar remindeer ignore button -->
<string name="CRA_ignore">Ignore</string>
<!-- Calendar event (%s -> event name)-->
<string name="CRA_title">Calendar event: %s</string>
<!-- Calendar event -->
<string name="CRA_title">Need a meeting list?</string>
<!-- Calendar reminder: dialog to ignore all missed calls title -->
<string name="CRA_ignore_title">Ignore all calendar events?</string>
@ -540,11 +540,17 @@
<!-- Calendar reminder: dialog to ignore all missed calls ignore just this button -->
<string name="CRA_ignore_this">Ignore this event only</string>
<!-- Calendar reminder: astrid speech bubble -->
<string name="CRA_speech_bubble">Looks like you\'ve got a meeting coming up! Want to create a list for taking note of action items?</string>
<!-- Calendar reminder: astrid speech bubble when event starting (%s -> event name) -->
<string name="CRA_speech_bubble_start">Looks like %s is starting soon. Want to create a list for action items?</string>
<!-- Calendar reminder: astrid speech bubble when event ending (%s -> event name) -->
<string name="CRA_speech_bubble_end">Looks like you just finished with %s. Want to create a list for action items?</string>
<!-- Calendar reminder: create list button -->
<string name="CRA_create_list">Create list</string>
<!-- Calendar reminder: postpone button -->
<string name="CRA_postpone">Maybe afterwards</string>
<!-- Calendar reminder: list exists dialog title -->
<string name="CRA_list_exists_title">List already exists</string>

Loading…
Cancel
Save