Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24248] Android: Ti.Calendar Recurring Events are not clearly exposed #9412

Merged
merged 18 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ public class CalendarModule extends KrollModule
@Kroll.constant
public static final int STATE_SCHEDULED = AlertProxy.STATE_SCHEDULED;

//region recurrence frequency
@Kroll.constant
public static final int RECURRENCEFREQUENCY_DAILY = 0;
@Kroll.constant
public static final int RECURRENCEFREQUENCY_WEEKLY = 1;
@Kroll.constant
public static final int RECURRENCEFREQUENCY_MONTHLY = 2;
@Kroll.constant
public static final int RECURRENCEFREQUENCY_YEARLY = 3;
//endregion

//region attendee relationships
@Kroll.constant
public static final int RELATIONSHIP_ATTENDEE = CalendarContract.Attendees.RELATIONSHIP_ATTENDEE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import android.provider.CalendarContract.Instances;

// Columns and value constants taken from android.provider.Calendar in the android source base
@Kroll.proxy(parentModule = CalendarModule.class)
@Kroll.proxy(parentModule = CalendarModule.class, propertyAccessors = { TiC.PROPERTY_RECURRENCE_RULES })
public class EventProxy extends KrollProxy
{

public static final String TAG = "EventProxy";

public static final int STATUS_TENTATIVE = 0;
Expand All @@ -48,7 +49,7 @@ public class EventProxy extends KrollProxy
protected int status, visibility;
protected KrollDict extendedProperties = new KrollDict();

protected String recurrenceRule, recurrenceDate, recurrenceExceptionRule, recurrenceExceptionDate;
protected String recurrenceDate, recurrenceExceptionRule, recurrenceExceptionDate;
protected Date lastDate;

public EventProxy()
Expand Down Expand Up @@ -97,11 +98,11 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
visibility = "visibility";
}

Cursor eventCursor =
contentResolver.query(builder.build(),
new String[] { "event_id", "title", "description", "eventLocation", "begin", "end",
"allDay", "hasAlarm", "eventStatus", visibility },
query, queryArgs, "startDay ASC, startMinute ASC");
Cursor eventCursor = contentResolver.query(builder.build(),
new String[] { "event_id", "title", "description", "eventLocation",
"begin", "end", "allDay", "hasAlarm", "eventStatus",
visibility, Events.RRULE, Events.CALENDAR_ID },
query, queryArgs, "startDay ASC, startMinute ASC");

if (eventCursor == null) {
Log.w(TAG, "Unable to get any results when pulling events by date range");
Expand All @@ -121,7 +122,16 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
event.hasAlarm = !eventCursor.getString(7).equals("0");
event.status = eventCursor.getInt(8);
event.visibility = eventCursor.getInt(9);

// Guarding against Cursor implementations which would throw an exception
// instead of returning null if no recurrence rule is added to the event
String recurrenceRule = null;
try {
recurrenceRule = eventCursor.getString(10);
} catch (Exception e) {
Log.w(TAG, "Trying to get a recurrence rule for an event without one.");
e.printStackTrace();
}
event.setRecurrenceRules(recurrenceRule, eventCursor.getInt(11));
events.add(event);
}

Expand All @@ -130,6 +140,22 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
return events;
}

@Kroll.method
public void save()
{
// Currently only saving added recurrenceRules.
String ruleToSave =
((RecurrenceRuleProxy) ((Object[]) getProperty(TiC.PROPERTY_RECURRENCE_RULES))[0]).generateRRULEString();
ContentValues contentValues = new ContentValues();
contentValues.put(Events.RRULE, ruleToSave);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of the truncated constant name here: Events.RRULE versus something like Events.RECURRENCE_RULE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentResolver contentResolver = TiApplication.getInstance().getContentResolver();
try {
contentResolver.update(Events.CONTENT_URI, contentValues, Events._ID + "=?", new String[] { id });
} catch (IllegalArgumentException e) {
Log.e(TAG, "Invalid event recurrence rule.");
}
}

public static ArrayList<EventProxy> queryEvents(Uri uri, String query, String[] queryArgs, String orderBy)
{
ArrayList<EventProxy> events = new ArrayList<EventProxy>();
Expand Down Expand Up @@ -336,9 +362,15 @@ public ReminderProxy createReminder(KrollDict data)
return ReminderProxy.createReminder(this, minutes, method);
}

@Kroll.method
RecurrenceRuleProxy createRecurrenceRule(KrollDict data)
{
return new RecurrenceRuleProxy(data);
}

// clang-format off
@Kroll.method
@Kroll.getProperty
@Kroll.getProperty
public AlertProxy[] getAlerts()
// clang-format on
{
Expand Down Expand Up @@ -461,13 +493,13 @@ public int getVisibility()
return visibility;
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public String getRecurrenceRule()
// clang-format on
public void setRecurrenceRules(String rrule, int calendarID)
{
return recurrenceRule;
RecurrenceRuleProxy[] result = new RecurrenceRuleProxy[] {};
if (rrule != null) {
result = new RecurrenceRuleProxy[] { new RecurrenceRuleProxy(rrule, calendarID, begin) };
}
setProperty(TiC.PROPERTY_RECURRENCE_RULES, result);
}

// clang-format off
Expand Down