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-17450] Android: Ti.Calendar.Event should expose the Attendees (Parity with iOS) #9325

Merged
merged 6 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,27 @@
package ti.modules.titanium.calendar;

import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;

@Kroll.proxy(propertyAccessors = {
TiC.PROPERTY_EMAIL,
TiC.PROPERTY_NAME,
TiC.PROPERTY_STATUS,
TiC.PROPERTY_TYPE,
TiC.PROPERTY_RELATIONSHIP
})
public class AttendeeProxy extends KrollProxy {

public AttendeeProxy() {
super();
}

public AttendeeProxy(String email, String name, int status, int type, int relationship) {
setProperty(TiC.PROPERTY_EMAIL, email);
setProperty(TiC.PROPERTY_NAME, name);
setProperty(TiC.PROPERTY_STATUS, status);
setProperty(TiC.PROPERTY_TYPE, type);
setProperty(TiC.PROPERTY_RELATIONSHIP, relationship);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;

import android.provider.CalendarContract;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
Expand Down Expand Up @@ -41,6 +42,32 @@ 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 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;
@Kroll.constant public static final int RELATIONSHIP_ORGANIZER = CalendarContract.Attendees.RELATIONSHIP_ORGANIZER;
@Kroll.constant public static final int RELATIONSHIP_PERFORMER = CalendarContract.Attendees.RELATIONSHIP_PERFORMER;
@Kroll.constant public static final int RELATIONSHIP_SPEAKER = CalendarContract.Attendees.RELATIONSHIP_SPEAKER;
@Kroll.constant public static final int RELATIONSHIP_UNKNOWN = 11001;
//endregion

//region attendee status
@Kroll.constant public static final int ATTENDEE_STATUS_ACCEPTED = CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED;
@Kroll.constant public static final int ATTENDEE_STATUS_DECLINED = CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED;
@Kroll.constant public static final int ATTENDEE_STATUS_INVITED = CalendarContract.Attendees.ATTENDEE_STATUS_INVITED;
@Kroll.constant public static final int ATTENDEE_STATUS_NONE = CalendarContract.Attendees.ATTENDEE_STATUS_NONE;
@Kroll.constant public static final int ATTENDEE_STATUS_TENTATIVE = CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE;
@Kroll.constant public static final int ATTENDEE_STATUS_UNKNOWN = 11001;
//endregion

//region attendee type
@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_REQUIRED = CalendarContract.Attendees.TYPE_REQUIRED;
@Kroll.constant public static final int ATTENDEE_TYPE_UNKNOWN = 11001;
//endregion

public static final String EVENT_LOCATION = "eventLocation";

public CalendarModule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Date;

import android.provider.CalendarContract;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
Expand Down Expand Up @@ -243,6 +244,62 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
}
}

private Object setValueFromCursorForColumn(Cursor cursor, String columnName, Object defaultValue) {
int columnIndex = cursor.getColumnIndex(columnName);
if (columnIndex < 0) {
//there is no such column
Log.w(TAG, "No column with name '" + columnName + "' found. Setting a default value.");
} else {
try {
if (defaultValue instanceof String) {
return cursor.getString(columnIndex);
} else if (defaultValue instanceof Integer) {
return cursor.getInt(columnIndex);
}
} catch (Exception e) {
Log.w(TAG, "Value of column '" + columnName + "' type does not match required type. Setting a default value.");
e.printStackTrace();
}
}
return defaultValue;
}

private AttendeeProxy[] getAttendeeProxies() {
AttendeeProxy[] result;
final String[] attendeeProjection = new String[]{
CalendarContract.Attendees._ID,
CalendarContract.Attendees.EVENT_ID,
CalendarContract.Attendees.ATTENDEE_NAME,
CalendarContract.Attendees.ATTENDEE_EMAIL,
CalendarContract.Attendees.ATTENDEE_TYPE,
CalendarContract.Attendees.ATTENDEE_RELATIONSHIP,
CalendarContract.Attendees.ATTENDEE_STATUS
};
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);
Copy link
Contributor

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.

int index = 0;
if (cursor != null) {
result = new AttendeeProxy[cursor.getCount()];
while (cursor.moveToNext()) {
//safely create parameters for Attendee
String attendeeEmail = setValueFromCursorForColumn(cursor, CalendarContract.Attendees.ATTENDEE_EMAIL, "").toString();
String attendeeName = setValueFromCursorForColumn(cursor, CalendarContract.Attendees.ATTENDEE_NAME, "").toString();
int attendeeType = (Integer) setValueFromCursorForColumn(cursor, CalendarContract.Attendees.ATTENDEE_TYPE, CalendarModule.ATTENDEE_STATUS_NONE);
int attendeeStatus = (Integer) setValueFromCursorForColumn(cursor, CalendarContract.Attendees.ATTENDEE_STATUS, CalendarModule.ATTENDEE_STATUS_NONE);
int attendeeRelationship = (Integer) setValueFromCursorForColumn(cursor, CalendarContract.Attendees.ATTENDEE_RELATIONSHIP, CalendarModule.RELATIONSHIP_NONE);
//create a proxy instance
AttendeeProxy proxyForRow = new AttendeeProxy(attendeeEmail, attendeeName, attendeeType, attendeeStatus, attendeeRelationship);
//add the proxy to the result array
result[index++] = proxyForRow;
}
} else {
result = new AttendeeProxy[0];
}
return result;
}

@Kroll.method @Kroll.getProperty
public ReminderProxy[] getReminders()
{
Expand Down Expand Up @@ -318,6 +375,11 @@ public boolean getAllDay()
return allDay;
}

@Kroll.getProperty @Kroll.method
public AttendeeProxy[] getAttendees() {
return getAttendeeProxies();
}

@Kroll.getProperty @Kroll.method
public boolean getHasAlarm()
{
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,11 @@ public class TiC
*/
public static final String PROPERTY_RELATED_NAMES = "relatedNames";

/**
* @module.api
*/
public static final String PROPERTY_RELATIONSHIP = "relationship";

/**
* @module.api
*/
Expand Down