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-17450] Android: Ti.Calendar.Event should expose the Attendees (Parity with iOS) #9325
Conversation
@Kroll.constant public static final int ATTENDEE_TYPE_NONE = CalendarContract.Attendees.TYPE_NONE; | ||
@Kroll.constant public static final int ATTENDEE_TYPE_OPTIONAL = CalendarContract.Attendees.TYPE_OPTIONAL; | ||
@Kroll.constant public static final int ATTENDEE_TYPE_RESOURCE = CalendarContract.Attendees.TYPE_RESOURCE; | ||
@Kroll.constant public static final int ATTENDEE_TYPE_REQUIERED = CalendarContract.Attendees.TYPE_REQUIRED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo...
Change "ATTENDEE_TYPE_REQUIERED" to "ATTENDEE_TYPE_REQUIRED".
//add the proxy to the result array | ||
result[index++] = proxyForRow; | ||
} | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return result;
line is indented 1 tab too far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need to return an empty array if we've failed to find any attendees or if an error occurs. This is to match iOS' behavior as documented here...
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Calendar.Event-property-attendees
final String query = "(" + CalendarContract.Attendees.EVENT_ID + " = ?)"; | ||
final String[] args = new String[]{id}; | ||
ContentResolver contentResolver = TiApplication.getInstance().getContentResolver(); | ||
final Cursor cursor = contentResolver.query(CalendarContract.Attendees.CONTENT_URI, attendeeProjection, query, args, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ContentResolver.query()
method can return null. We need to do a null check on cursor
before using it below.
cursor.getString(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_NAME)), | ||
cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_TYPE)), | ||
cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_STATUS)), | ||
cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursor.getColumnIndex()
call can return -1
which would trigger an out-of-bounds exception when passed through to the cursor getter methods. Also, the cursor getter methods can throw an exception if the column type does not match the type requested (ie: it stores a string when we're requesting an int).
To be safe, we should make sure the column index is valid before using it. And wrap each cursor getter in separate try/catch blocks. We can default fields not found to constants such as NONE.
Also, should we define our own "UNKNOWN" constant? The idea is to future-proof this code for when Google adds new constants that our internal code doesn't support yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked up our docs. We do define UNKNOWN types in iOS. We need to do the same on Android for types we don't recognize as well. Perhaps that should be determined in the AttendeeProxy
? I'll leave that up to you.
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Calendar
Guard the fetching of the attendees.
@jquick-axway Updated. |
@ypbnv, you would have to use a 3rd party contacts app instead of Google's, because they don't have to follow the rules. This is something we have to worry about if a Titanium app is distributed via a different Android app store such as Amazon. For example, an Amazon device will have an Amazon made contacts app instead of the one made by Google. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: Pass
FR Passed. The attendees info for the event can be successfully fetched like Studio Ver: 4.9.1.201707200100 |
JIRA: https://jira.appcelerator.org/browse/TIMOB-17450
Description:
Add AttendeesProxy and add it as a result for getAttendees() method.
Test case:
Note: Device should have a valid calendar with an event with at least one attendee.
Also these permissions need to be added in tiapp.xml: