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 5 commits
Commits
File filter

Filter by extension

Filter by extension

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

//region recurrence frequency
@Kroll.constant public static final int RECURRENCEFREQUENCY_DAILY = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I'd prefer RECURRENCE_FREQUENCY_DAILY to RECURRENCEFREQUENCY_DAILY (same goes for the rest)

Copy link
Contributor Author

@ypbnv ypbnv Nov 28, 2017

Choose a reason for hiding this comment

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

This is the way we currently have them for iOS:
https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Calendar-property-RECURRENCEFREQUENCY_DAILY

We can change them in there too - now would be the time because that would be a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd want to "fix" them to match our naming conventions. We'd have to retain the existing definitions and mark them as deprecated for this release, then in 8.0 or later we can remove the ones missing the underscores. So not really a breaking change, but an important deprecation to get in before GA.

@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;
@Kroll.constant public static final int RELATIONSHIP_NONE = CalendarContract.Attendees.RELATIONSHIP_NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
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";

Expand All @@ -47,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 @@ -96,7 +98,8 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
}

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

if (eventCursor == null) {
Expand All @@ -117,7 +120,7 @@ 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);

event.setRecurrenceRules(eventCursor.getString(10), eventCursor.getInt(11));
Copy link
Contributor

Choose a reason for hiding this comment

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

could this break when pulling up existing events with no recurrence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently it could. I did not get any exception, but it is documented as "implementation-defined"
https://developer.android.com/reference/android/database/Cursor.html#getString(int)
I will add an exception handling.

events.add(event);
}

Expand All @@ -126,6 +129,16 @@ 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();
contentResolver.update(Events.CONTENT_URI, contentValues, Events._ID+"=?", new String[]{id});
}

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

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

@Kroll.method @Kroll.getProperty
public AlertProxy[] getAlerts()
{
Expand Down Expand Up @@ -404,10 +421,16 @@ public int getVisibility()
return visibility;
}

@Kroll.getProperty @Kroll.method
public String getRecurrenceRule()
public void setRecurrenceRules(String rrule, int calendarID)
{
return recurrenceRule;
RecurrenceRuleProxy[] result;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe something a little more compact?

RecurrenceRuleProxy[] result = new RecurrenceRuleProxy[]{};
if (rrule != null) {
  result = new RecurrenceRuleProxy[] { new RecurrenceRuleProxy(rrule, calendarID, begin) };
} 
setProperty(TiC.PROPERTY_RECURRENCE_RULES, result);

if (rrule != null) {
result = new RecurrenceRuleProxy[1];
result[0] = new RecurrenceRuleProxy(rrule, calendarID, begin);;
} else {
result = new RecurrenceRuleProxy[]{};
}
setProperty(TiC.PROPERTY_RECURRENCE_RULES, result);
}

@Kroll.getProperty @Kroll.method
Expand Down
Loading