Delete rows that are unused when changes are synced down

This commit is contained in:
Marc Blank 2009-08-10 11:11:21 -07:00
parent cc402e42ab
commit 9d3f4abd97

View File

@ -104,6 +104,8 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
return p.parse();
}
// YomiFirstName, YomiLastName, and YomiCompanyName are the names of EAS fields
// Yomi is a shortened form of yomigana, which is a Japanese phonetic rendering.
public static final class Yomi {
private Yomi() {}
@ -494,6 +496,17 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
if (companyName != null) {
ops.addOrganization(entity, Organization.TYPE_WORK, companyName, title);
}
if (entity != null) {
// We've been removing rows from the list as they've been found in the xml
// Any that are left must have been deleted on the server
ArrayList<NamedContentValues> ncvList = entity.getSubValues();
for (NamedContentValues ncv: ncvList) {
// These rows need to be deleted...
Uri u = dataUriFromNamedContentValues(ncv);
ops.add(ContentProviderOperation.newDelete(u).build());
}
}
}
private void categoriesParser(ContactOperations ops, Entity entity) throws IOException {
@ -776,17 +789,6 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
}
}
/**
* Generate the uri for the data row associated with this NamedContentValues object
* @param ncv the NamedContentValues object
* @return a uri that can be used to refer to this row
*/
private Uri dataUriFromNamedContentValues(NamedContentValues ncv) {
long id = ncv.values.getAsLong(RawContacts._ID);
Uri dataUri = ContentUris.withAppendedId(ncv.uri, id);
return dataUri;
}
/**
* Given the list of NamedContentValues for an entity, a mime type, and a subtype,
* tries to find a match, returning it
@ -1116,6 +1118,17 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
}
}
/**
* Generate the uri for the data row associated with this NamedContentValues object
* @param ncv the NamedContentValues object
* @return a uri that can be used to refer to this row
*/
public Uri dataUriFromNamedContentValues(NamedContentValues ncv) {
long id = ncv.values.getAsLong(RawContacts._ID);
Uri dataUri = ContentUris.withAppendedId(ncv.uri, id);
return dataUri;
}
@Override
public void cleanup(EasSyncService service) {
// Mark the changed contacts dirty = 0