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

ExeptionHandle #434

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
39 changes: 21 additions & 18 deletions android/src/main/java/com/calendarevents/RNCalendarEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private WritableNativeMap findEventInstanceById(String eventID) {
return result;
}

private long addEvent(String title, ReadableMap details, ReadableMap options) throws ParseException {
private long addEvent(String title, ReadableMap details, ReadableMap options, final Promise promise) throws ParseException {
String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
boolean skipTimezone = false;
Expand Down Expand Up @@ -673,7 +673,7 @@ private long addEvent(String title, ReadableMap details, ReadableMap options) th
}

if (details.hasKey("alarms")) {
createRemindersForEvent(cr, Long.parseLong(details.getString("id")), details.getArray("alarms"));
createRemindersForEvent(cr, Long.parseLong(details.getString("id")), details.getArray("alarms"), promise);
}

if (details.hasKey("attendees")) {
Expand Down Expand Up @@ -715,7 +715,7 @@ private long addEvent(String title, ReadableMap details, ReadableMap options) th
eventID = Long.parseLong(rowId);

if (details.hasKey("alarms")) {
createRemindersForEvent(cr, eventID, details.getArray("alarms"));
createRemindersForEvent(cr, eventID, details.getArray("alarms"), promise);
}

if (details.hasKey("attendees")) {
Expand Down Expand Up @@ -842,7 +842,7 @@ private void createAttendeesForEvent(ContentResolver resolver, long eventID, Rea
//endregion

//region Reminders
private void createRemindersForEvent(ContentResolver resolver, long eventID, ReadableArray reminders) {
private void createRemindersForEvent(ContentResolver resolver, long eventID, ReadableArray reminders, final Promise promise) {
Cursor cursor = null;

if (resolver != null) {
Expand All @@ -865,20 +865,23 @@ private void createRemindersForEvent(ContentResolver resolver, long eventID, Rea
if (cursor != null) {
cursor.close();
}

for (int i = 0; i < reminders.size(); i++) {
ReadableMap reminder = reminders.getMap(i);
ReadableType type = reminder.getType("date");
if (type == ReadableType.Number) {
int minutes = reminder.getInt("date");
ContentValues reminderValues = new ContentValues();

reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventID);
reminderValues.put(CalendarContract.Reminders.MINUTES, minutes);
reminderValues.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);

resolver.insert(CalendarContract.Reminders.CONTENT_URI, reminderValues);
try {
for (int i = 0; i < reminders.size(); i++) {
ReadableMap reminder = reminders.getMap(i);
ReadableType type = reminder.getType("date");
if (type == ReadableType.Number) {
int minutes = reminder.getInt("date");
ContentValues reminderValues = new ContentValues();

reminderValues.put(CalendarContract.Reminders.EVENT_ID, eventID);
reminderValues.put(CalendarContract.Reminders.MINUTES, minutes);
reminderValues.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);

resolver.insert(CalendarContract.Reminders.CONTENT_URI, reminderValues);
}
}
} catch (Exception e){
promise.reject("add event error", "Unable to save event");
}
}

Expand Down Expand Up @@ -1349,7 +1352,7 @@ public void saveEvent(final String title, final ReadableMap details, final Reada
public void run() {
long eventId;
try {
eventId = addEvent(title, details, options);
eventId = addEvent(title, details, options, promise);
if (eventId > -1) {
promise.resolve(Long.toString(eventId));
} else {
Expand Down