mirror of https://github.com/tasks/tasks
Add CalendarEventAttendeeProvider
parent
e97fb0b8cf
commit
7411ecb0d7
@ -0,0 +1,28 @@
|
|||||||
|
package org.tasks.calendars;
|
||||||
|
|
||||||
|
public class AndroidCalendarEventAttendee {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final String email;
|
||||||
|
|
||||||
|
public AndroidCalendarEventAttendee(String name, String email) {
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AndroidCalendarEventAttendee{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package org.tasks.calendars;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.provider.CalendarContract;
|
||||||
|
|
||||||
|
import org.tasks.injection.ForApplication;
|
||||||
|
import org.tasks.preferences.PermissionChecker;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
public class CalendarEventAttendeeProvider {
|
||||||
|
|
||||||
|
private static final String[] COLUMNS = {
|
||||||
|
CalendarContract.Attendees.ATTENDEE_NAME,
|
||||||
|
CalendarContract.Attendees.ATTENDEE_EMAIL,
|
||||||
|
};
|
||||||
|
|
||||||
|
private final PermissionChecker permissionChecker;
|
||||||
|
private final ContentResolver contentResolver;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public CalendarEventAttendeeProvider(@ForApplication Context context, PermissionChecker permissionChecker) {
|
||||||
|
this.permissionChecker = permissionChecker;
|
||||||
|
contentResolver = context.getContentResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AndroidCalendarEventAttendee> getAttendees(long id) {
|
||||||
|
if (!permissionChecker.canAccessCalendars()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AndroidCalendarEventAttendee> attendees = new ArrayList<>();
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
//noinspection ResourceType
|
||||||
|
cursor = contentResolver.query(
|
||||||
|
CalendarContract.Attendees.CONTENT_URI,
|
||||||
|
COLUMNS,
|
||||||
|
CalendarContract.Attendees.EVENT_ID + " = ? ",
|
||||||
|
new String[] { Long.toString(id) }, null);
|
||||||
|
if (cursor != null && cursor.getCount() > 0) {
|
||||||
|
int emailIndex = cursor.getColumnIndexOrThrow(CalendarContract.Attendees.ATTENDEE_EMAIL);
|
||||||
|
int nameIndex = cursor.getColumnIndexOrThrow(CalendarContract.Attendees.ATTENDEE_NAME);
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
attendees.add(new AndroidCalendarEventAttendee(
|
||||||
|
cursor.getString(nameIndex),
|
||||||
|
cursor.getString(emailIndex)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Timber.e(e, e.getMessage());
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attendees;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue