blob: 9b7ab313711b31e7c393e8ddffd38ea87746690c [file] [log] [blame]
Paul Soulos899aa212014-06-11 12:04:43 -07001package com.android.contacts.interactions;
2
Paul Soulos899aa212014-06-11 12:04:43 -07003import android.content.ContentUris;
Gary Mai0a49afa2016-12-05 15:53:58 -08004import android.content.ContentValues;
Paul Soulos899aa212014-06-11 12:04:43 -07005import android.content.Context;
6import android.content.Intent;
Paul Soulos899aa212014-06-11 12:04:43 -07007import android.graphics.drawable.Drawable;
Paul Soulos899aa212014-06-11 12:04:43 -07008import android.provider.CalendarContract.Attendees;
9import android.provider.CalendarContract.Events;
Walter Jang7ce53522014-10-29 13:26:43 -070010import android.text.Spannable;
Paul Soulos899aa212014-06-11 12:04:43 -070011import android.text.TextUtils;
12import android.text.format.Time;
Gary Mai0a49afa2016-12-05 15:53:58 -080013
14import com.android.contacts.R;
Paul Soulos899aa212014-06-11 12:04:43 -070015
16/**
17 * Represents a calendar event interaction, wrapping the columns in
18 * {@link android.provider.CalendarContract.Attendees}.
19 */
20public class CalendarInteraction implements ContactInteraction {
21 private static final String TAG = CalendarInteraction.class.getSimpleName();
22
John Shaobd9ef3c2016-12-15 12:42:03 -080023 private static final int CALENDAR_ICON_RES = R.drawable.quantum_ic_event_vd_theme_24;
Paul Soulos899aa212014-06-11 12:04:43 -070024
25 private ContentValues mValues;
26
27 public CalendarInteraction(ContentValues values) {
28 mValues = values;
29 }
30
31 @Override
32 public Intent getIntent() {
33 return new Intent(Intent.ACTION_VIEW).setData(
34 ContentUris.withAppendedId(Events.CONTENT_URI, getEventId()));
35 }
36
37 @Override
38 public long getInteractionDate() {
39 return getDtstart();
40 }
41
42 @Override
43 public String getViewHeader(Context context) {
44 String title = getTitle();
45 if (TextUtils.isEmpty(title)) {
46 return context.getResources().getString(R.string.untitled_event);
47 }
48 return title;
49 }
50
51 @Override
52 public String getViewBody(Context context) {
53 return null;
54 }
55
56 @Override
57 public String getViewFooter(Context context) {
58 // Pulled from com.android.calendar.EventInfoFragment.updateEvent(View view)
59 // TODO: build callback to update time zone if different than preferences
60 String localTimezone = Time.getCurrentTimezone();
61
Paul Soulos75d5a912014-06-24 11:22:37 -070062 Long dateEnd = getDtend();
63 Long dateStart = getDtstart();
64 if (dateStart == null && dateEnd == null) {
65 return null;
66 } else if (dateEnd == null) {
67 dateEnd = dateStart;
68 } else if (dateStart == null) {
69 dateStart = dateEnd;
70 }
71
Paul Soulos899aa212014-06-11 12:04:43 -070072 String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime(
Paul Soulosc1e7ecd2014-06-30 18:06:17 -040073 dateStart, dateEnd, System.currentTimeMillis(), localTimezone,
Paul Soulos899aa212014-06-11 12:04:43 -070074 getAllDay(), context);
75
76 return displayedDatetime;
77 }
78
79 @Override
80 public Drawable getIcon(Context context) {
81 return context.getResources().getDrawable(CALENDAR_ICON_RES);
82 }
83
84 @Override
85 public Drawable getBodyIcon(Context context) {
86 return null;
87 }
88
89 @Override
90 public Drawable getFooterIcon(Context context) {
91 return null;
92 }
93
94 public String getAttendeeEmail() {
95 return mValues.getAsString(Attendees.ATTENDEE_EMAIL);
96 }
97
98 public String getAttendeeIdentity() {
99 return mValues.getAsString(Attendees.ATTENDEE_IDENTITY);
100 }
101
102 public String getAttendeeIdNamespace() {
103 return mValues.getAsString(Attendees.ATTENDEE_ID_NAMESPACE);
104 }
105
106 public String getAttendeeName() {
107 return mValues.getAsString(Attendees.ATTENDEE_NAME);
108 }
109
Paul Soulos75d5a912014-06-24 11:22:37 -0700110 public Integer getAttendeeRelationship() {
Paul Soulos899aa212014-06-11 12:04:43 -0700111 return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP);
112 }
113
Paul Soulos75d5a912014-06-24 11:22:37 -0700114 public Integer getAttendeeStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700115 return mValues.getAsInteger(Attendees.ATTENDEE_STATUS);
116 }
117
Paul Soulos75d5a912014-06-24 11:22:37 -0700118 public Integer getAttendeeType() {
Paul Soulos899aa212014-06-11 12:04:43 -0700119 return mValues.getAsInteger(Attendees.ATTENDEE_TYPE);
120 }
121
Paul Soulos75d5a912014-06-24 11:22:37 -0700122 public Integer getEventId() {
Paul Soulos899aa212014-06-11 12:04:43 -0700123 return mValues.getAsInteger(Attendees.EVENT_ID);
124 }
125
Paul Soulos75d5a912014-06-24 11:22:37 -0700126 public Integer getAccessLevel() {
Paul Soulos899aa212014-06-11 12:04:43 -0700127 return mValues.getAsInteger(Attendees.ACCESS_LEVEL);
128 }
129
Paul Soulos75d5a912014-06-24 11:22:37 -0700130 public Boolean getAllDay() {
Paul Soulos1bbce642014-09-02 17:15:43 -0700131 return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false;
Paul Soulos899aa212014-06-11 12:04:43 -0700132 }
133
Paul Soulos75d5a912014-06-24 11:22:37 -0700134 public Integer getAvailability() {
Paul Soulos899aa212014-06-11 12:04:43 -0700135 return mValues.getAsInteger(Attendees.AVAILABILITY);
136 }
137
Paul Soulos75d5a912014-06-24 11:22:37 -0700138 public Integer getCalendarId() {
Paul Soulos899aa212014-06-11 12:04:43 -0700139 return mValues.getAsInteger(Attendees.CALENDAR_ID);
140 }
141
Paul Soulos75d5a912014-06-24 11:22:37 -0700142 public Boolean getCanInviteOthers() {
Paul Soulos899aa212014-06-11 12:04:43 -0700143 return mValues.getAsBoolean(Attendees.CAN_INVITE_OTHERS);
144 }
145
146 public String getCustomAppPackage() {
147 return mValues.getAsString(Attendees.CUSTOM_APP_PACKAGE);
148 }
149
150 public String getCustomAppUri() {
151 return mValues.getAsString(Attendees.CUSTOM_APP_URI);
152 }
153
154 public String getDescription() {
155 return mValues.getAsString(Attendees.DESCRIPTION);
156 }
157
Paul Soulos75d5a912014-06-24 11:22:37 -0700158 public Integer getDisplayColor() {
Paul Soulos899aa212014-06-11 12:04:43 -0700159 return mValues.getAsInteger(Attendees.DISPLAY_COLOR);
160 }
161
Paul Soulos75d5a912014-06-24 11:22:37 -0700162 public Long getDtend() {
Paul Soulos899aa212014-06-11 12:04:43 -0700163 return mValues.getAsLong(Attendees.DTEND);
164 }
165
Paul Soulos75d5a912014-06-24 11:22:37 -0700166 public Long getDtstart() {
Paul Soulos899aa212014-06-11 12:04:43 -0700167 return mValues.getAsLong(Attendees.DTSTART);
168 }
169
170 public String getDuration() {
171 return mValues.getAsString(Attendees.DURATION);
172 }
173
Paul Soulos75d5a912014-06-24 11:22:37 -0700174 public Integer getEventColor() {
Paul Soulos899aa212014-06-11 12:04:43 -0700175 return mValues.getAsInteger(Attendees.EVENT_COLOR);
176 }
177
178 public String getEventColorKey() {
179 return mValues.getAsString(Attendees.EVENT_COLOR_KEY);
180 }
181
182 public String getEventEndTimezone() {
183 return mValues.getAsString(Attendees.EVENT_END_TIMEZONE);
184 }
185
186 public String getEventLocation() {
187 return mValues.getAsString(Attendees.EVENT_LOCATION);
188 }
189
190 public String getExdate() {
191 return mValues.getAsString(Attendees.EXDATE);
192 }
193
194 public String getExrule() {
195 return mValues.getAsString(Attendees.EXRULE);
196 }
197
Paul Soulos75d5a912014-06-24 11:22:37 -0700198 public Boolean getGuestsCanInviteOthers() {
Paul Soulos899aa212014-06-11 12:04:43 -0700199 return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS);
200 }
201
Paul Soulos75d5a912014-06-24 11:22:37 -0700202 public Boolean getGuestsCanModify() {
Paul Soulos899aa212014-06-11 12:04:43 -0700203 return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY);
204 }
205
Paul Soulos75d5a912014-06-24 11:22:37 -0700206 public Boolean getGuestsCanSeeGuests() {
Paul Soulos899aa212014-06-11 12:04:43 -0700207 return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS);
208 }
209
Paul Soulos75d5a912014-06-24 11:22:37 -0700210 public Boolean getHasAlarm() {
Paul Soulos899aa212014-06-11 12:04:43 -0700211 return mValues.getAsBoolean(Attendees.HAS_ALARM);
212 }
213
Paul Soulos75d5a912014-06-24 11:22:37 -0700214 public Boolean getHasAttendeeData() {
Paul Soulos899aa212014-06-11 12:04:43 -0700215 return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA);
216 }
217
Paul Soulos75d5a912014-06-24 11:22:37 -0700218 public Boolean getHasExtendedProperties() {
Paul Soulos899aa212014-06-11 12:04:43 -0700219 return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES);
220 }
221
222 public String getIsOrganizer() {
223 return mValues.getAsString(Attendees.IS_ORGANIZER);
224 }
225
Paul Soulos75d5a912014-06-24 11:22:37 -0700226 public Long getLastDate() {
Paul Soulos899aa212014-06-11 12:04:43 -0700227 return mValues.getAsLong(Attendees.LAST_DATE);
228 }
229
Paul Soulos75d5a912014-06-24 11:22:37 -0700230 public Boolean getLastSynced() {
Paul Soulos899aa212014-06-11 12:04:43 -0700231 return mValues.getAsBoolean(Attendees.LAST_SYNCED);
232 }
233
234 public String getOrganizer() {
235 return mValues.getAsString(Attendees.ORGANIZER);
236 }
237
Paul Soulos75d5a912014-06-24 11:22:37 -0700238 public Boolean getOriginalAllDay() {
Paul Soulos899aa212014-06-11 12:04:43 -0700239 return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY);
240 }
241
242 public String getOriginalId() {
243 return mValues.getAsString(Attendees.ORIGINAL_ID);
244 }
245
Paul Soulos75d5a912014-06-24 11:22:37 -0700246 public Long getOriginalInstanceTime() {
Paul Soulos899aa212014-06-11 12:04:43 -0700247 return mValues.getAsLong(Attendees.ORIGINAL_INSTANCE_TIME);
248 }
249
250 public String getOriginalSyncId() {
251 return mValues.getAsString(Attendees.ORIGINAL_SYNC_ID);
252 }
253
254 public String getRdate() {
255 return mValues.getAsString(Attendees.RDATE);
256 }
257
258 public String getRrule() {
259 return mValues.getAsString(Attendees.RRULE);
260 }
261
Paul Soulos75d5a912014-06-24 11:22:37 -0700262 public Integer getSelfAttendeeStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700263 return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS);
264 }
265
Paul Soulos75d5a912014-06-24 11:22:37 -0700266 public Integer getStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700267 return mValues.getAsInteger(Attendees.STATUS);
268 }
269
270 public String getTitle() {
271 return mValues.getAsString(Attendees.TITLE);
272 }
273
274 public String getUid2445() {
275 return mValues.getAsString(Attendees.UID_2445);
276 }
Paul Soulos23e28362014-08-29 14:57:08 -0700277
278 @Override
Walter Jang7ce53522014-10-29 13:26:43 -0700279 public Spannable getContentDescription(Context context) {
Paul Soulos23e28362014-08-29 14:57:08 -0700280 // The default TalkBack is good
281 return null;
282 }
Paul Soulos48290be2014-09-08 13:44:51 -0700283
284 @Override
285 public int getIconResourceId() {
286 return CALENDAR_ICON_RES;
287 }
Paul Soulos899aa212014-06-11 12:04:43 -0700288}