Calendar helper: refactoring

pull/212/head
M66B 2 years ago
parent f2159ef9c3
commit 69ded38d17

@ -70,7 +70,7 @@ public class CalendarHelper {
return Helper.getTimeInstance(context, SimpleDateFormat.SHORT).format(cal.getTime()); return Helper.getTimeInstance(context, SimpleDateFormat.SHORT).format(cal.getTime());
} }
static void insert(Context context, ICalendar icalendar, VEvent event, static void insert(Context context, ICalendar icalendar, VEvent event, int status,
String selectedAccount, String selectedName, EntityMessage message) { String selectedAccount, String selectedName, EntityMessage message) {
String organizer = (event.getOrganizer() == null ? null : event.getOrganizer().getEmail()); String organizer = (event.getOrganizer() == null ? null : event.getOrganizer().getEmail());
@ -133,7 +133,7 @@ public class CalendarHelper {
values.put(CalendarContract.Events.DESCRIPTION, description); values.put(CalendarContract.Events.DESCRIPTION, description);
if (!TextUtils.isEmpty(location)) if (!TextUtils.isEmpty(location))
values.put(CalendarContract.Events.EVENT_LOCATION, location); values.put(CalendarContract.Events.EVENT_LOCATION, location);
values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_TENTATIVE); values.put(CalendarContract.Events.STATUS, status);
Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values); Uri uri = resolver.insert(CalendarContract.Events.CONTENT_URI, values);
long eventId = Long.parseLong(uri.getLastPathSegment()); long eventId = Long.parseLong(uri.getLastPathSegment());
@ -146,7 +146,8 @@ public class CalendarHelper {
" end=" + new Date(end.getTime()) + " end=" + new Date(end.getTime()) +
" rrule=" + rrule + " rrule=" + rrule +
" summary=" + summary + " summary=" + summary +
" location=" + location); " location=" + location +
" status=" + status);
for (Attendee a : event.getAttendees()) for (Attendee a : event.getAttendees())
try { try {
@ -155,7 +156,7 @@ public class CalendarHelper {
String role = (a.getRole() == null ? null : a.getRole().getValue()); String role = (a.getRole() == null ? null : a.getRole().getValue());
String level = (a.getParticipationLevel() == null ? null String level = (a.getParticipationLevel() == null ? null
: a.getParticipationLevel().getValue(icalendar.getVersion())); : a.getParticipationLevel().getValue(icalendar.getVersion()));
String status = (a.getParticipationStatus() == null ? null : a.getParticipationStatus().getValue()); String pstatus = (a.getParticipationStatus() == null ? null : a.getParticipationStatus().getValue());
ContentValues avalues = new ContentValues(); ContentValues avalues = new ContentValues();
@ -175,13 +176,13 @@ public class CalendarHelper {
else if ("REQUEST".equals(level) || "OPT-PARTICIPANT".equals(level)) else if ("REQUEST".equals(level) || "OPT-PARTICIPANT".equals(level))
avalues.put(CalendarContract.Attendees.ATTENDEE_TYPE, CalendarContract.Attendees.TYPE_OPTIONAL); avalues.put(CalendarContract.Attendees.ATTENDEE_TYPE, CalendarContract.Attendees.TYPE_OPTIONAL);
if ("ACCEPTED".equals(status) || "CONFIRMED".equals(status)) if ("ACCEPTED".equals(pstatus) || "CONFIRMED".equals(pstatus))
avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED); avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED);
else if ("DECLINED".equals(status)) else if ("DECLINED".equals(pstatus))
avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED); avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED);
else if ("TENTATIVE".equals(status)) else if ("TENTATIVE".equals(pstatus))
avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE); avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_TENTATIVE);
else if ("NEEDS-ACTION".equals(status)) else if ("NEEDS-ACTION".equals(pstatus))
avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_NONE); avalues.put(CalendarContract.Attendees.ATTENDEE_STATUS, CalendarContract.Attendees.ATTENDEE_STATUS_NONE);
avalues.put(CalendarContract.Attendees.EVENT_ID, eventId); avalues.put(CalendarContract.Attendees.EVENT_ID, eventId);
@ -194,7 +195,7 @@ public class CalendarHelper {
" name=" + name + " name=" + name +
" role=" + role + " role=" + role +
" level=" + level + " level=" + level +
" status=" + status); " status=" + pstatus);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} }

@ -27,6 +27,7 @@ import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.provider.CalendarContract;
import android.system.ErrnoException; import android.system.ErrnoException;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
@ -4091,6 +4092,7 @@ public class MessageHelper {
} }
CalendarHelper.insert(context, icalendar, event, CalendarHelper.insert(context, icalendar, event,
CalendarContract.Events.STATUS_TENTATIVE,
selectedAccount, selectedName, message); selectedAccount, selectedName, message);
} }
} catch (Throwable ex) { } catch (Throwable ex) {

Loading…
Cancel
Save