mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Add a way to count calendar events/contacts.
This commit is contained in:
parent
4a196102a1
commit
1b3a4bf318
@ -23,14 +23,14 @@ import android.provider.ContactsContract.Groups;
|
||||
import android.provider.ContactsContract.RawContacts;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
|
||||
import at.bitfire.vcard4android.AndroidAddressBook;
|
||||
import at.bitfire.vcard4android.AndroidContact;
|
||||
import at.bitfire.vcard4android.AndroidGroup;
|
||||
@ -158,6 +158,18 @@ public class LocalAddressBook extends AndroidAddressBook implements LocalCollect
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() throws ContactsStorageException {
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(syncAdapterURI(RawContacts.CONTENT_URI),
|
||||
null,
|
||||
null, null, null);
|
||||
|
||||
return cursor.getCount();
|
||||
} catch (RemoteException e) {
|
||||
throw new ContactsStorageException("Couldn't query contacts", e);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public LocalContact[] getDeletedContacts() throws ContactsStorageException {
|
||||
|
@ -23,6 +23,9 @@ import android.provider.CalendarContract.Reminders;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
|
||||
import net.fortuna.ical4j.model.component.VTimeZone;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -31,8 +34,6 @@ import java.io.FileNotFoundException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.etesync.syncadapter.App;
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
import at.bitfire.ical4android.AndroidCalendar;
|
||||
import at.bitfire.ical4android.AndroidCalendarFactory;
|
||||
import at.bitfire.ical4android.BatchOperation;
|
||||
@ -239,6 +240,21 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() throws CalendarStorageException {
|
||||
String where = Events.CALENDAR_ID + "=?";
|
||||
String whereArgs[] = {String.valueOf(id)};
|
||||
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.query(
|
||||
syncAdapterURI(Events.CONTENT_URI),
|
||||
null,
|
||||
where, whereArgs, null);
|
||||
return cursor.getCount();
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't query calendar events", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Factory implements AndroidCalendarFactory {
|
||||
public static final Factory INSTANCE = new Factory();
|
||||
|
@ -24,4 +24,6 @@ public interface LocalCollection {
|
||||
|
||||
String getCTag() throws CalendarStorageException, ContactsStorageException;
|
||||
void setCTag(String cTag) throws CalendarStorageException, ContactsStorageException;
|
||||
|
||||
long count() throws CalendarStorageException, ContactsStorageException;
|
||||
}
|
||||
|
@ -19,12 +19,13 @@ import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
|
||||
import org.dmfs.provider.tasks.TaskContract.TaskLists;
|
||||
import org.dmfs.provider.tasks.TaskContract.Tasks;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
import at.bitfire.ical4android.AndroidTaskList;
|
||||
import at.bitfire.ical4android.AndroidTaskListFactory;
|
||||
import at.bitfire.ical4android.CalendarStorageException;
|
||||
@ -109,6 +110,21 @@ public class LocalTaskList extends AndroidTaskList implements LocalCollection {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() throws CalendarStorageException {
|
||||
String where = Tasks.LIST_ID + "=?";
|
||||
String whereArgs[] = {String.valueOf(getId())};
|
||||
|
||||
try {
|
||||
@Cleanup Cursor cursor = provider.client.query(
|
||||
syncAdapterURI(provider.tasksUri()),
|
||||
null,
|
||||
where, whereArgs, null);
|
||||
return cursor.getCount();
|
||||
} catch (RemoteException e) {
|
||||
throw new CalendarStorageException("Couldn't query calendar events", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Recycle")
|
||||
|
Loading…
Reference in New Issue
Block a user