<!-- For ContactsListActivity -->
<item type="id" name="dialog_delete_contact_confirmation" />
- <item type="id" name="dialog_cannot_delete_readonly_contact" />
+ <item type="id" name="dialog_readonly_contact_hide_confirmation" />
<item type="id" name="dialog_multiple_contact_delete_confirmation" />
<item type="id" name="dialog_readonly_contact_delete_confirmation" />
<string name="deleteConfirmation_title">Delete</string>
<!-- Warning dialog contents after users selects to delete a ReadOnly contact. -->
- <string name="readOnlyContactWarning">You cannot delete contacts from read-only accounts.</string>
+ <string name="readOnlyContactWarning">You cannot delete contacts from read-only accounts, but you can hide them in your contacts lists.</string>
<!-- Warning dialog contents after users selects to delete a contact with ReadOnly and Writable sources. -->
- <string name="readOnlyContactDeleteConfirmation">This contact contains information from multiple accounts. The information from read-only accounts will not be deleted.</string>
+ <string name="readOnlyContactDeleteConfirmation">This contact contains information from multiple accounts. Information from read-only accounts will be hidden in your contacts lists, not deleted.</string>
<!-- Warning dialog contents after users selects to delete a contact with multiple Writable sources. -->
<string name="multipleContactDeleteConfirmation">Deleting this contact will delete information from multiple accounts.</string>
}
public void onClick(DialogInterface dialog, int which) {
- if (mReadOnlySourcesCnt > 0) {
- for (long rawContactIdToDelete: mWritableRawContactIds) {
- final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
- rawContactIdToDelete);
- getContentResolver().delete(rawContactUri, null, null);
- }
- } else {
- getContentResolver().delete(mUri, null, null);
- }
+ getContentResolver().delete(mUri, null, null);
}
}
.setPositiveButton(android.R.string.ok,
new DeleteClickListener(mSelectedContactUri)).create();
}
- case R.id.dialog_cannot_delete_readonly_contact: {
+ case R.id.dialog_readonly_contact_hide_confirmation: {
return new AlertDialog.Builder(this)
.setTitle(R.string.deleteConfirmation_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(R.string.readOnlyContactWarning)
- .setPositiveButton(android.R.string.ok, null).create();
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(android.R.string.ok,
+ new DeleteClickListener(mSelectedContactUri)).create();
}
case R.id.dialog_readonly_contact_delete_confirmation: {
return new AlertDialog.Builder(this)
.setTitle(R.string.deleteConfirmation_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(R.string.readOnlyContactDeleteConfirmation)
+ .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok,
new DeleteClickListener(mSelectedContactUri)).create();
}
.setTitle(R.string.deleteConfirmation_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(R.string.multipleContactDeleteConfirmation)
+ .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok,
new DeleteClickListener(mSelectedContactUri)).create();
}
if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt > 0) {
showDialog(R.id.dialog_readonly_contact_delete_confirmation);
} else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
- showDialog(R.id.dialog_cannot_delete_readonly_contact);
+ showDialog(R.id.dialog_readonly_contact_hide_confirmation);
} else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
showDialog(R.id.dialog_multiple_contact_delete_confirmation);
} else {
private static final int DIALOG_CONFIRM_DELETE = 1;
private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
+ private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
private static final int REQUEST_JOIN_CONTACT = 1;
private static final int REQUEST_EDIT_CONTACT = 2;
public void onClick(DialogInterface dialog, int which) {
closeCursor();
- if (mReadOnlySourcesCnt > 0) {
- for (long rawContactIdToDelete: mWritableRawContactIds) {
- final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
- rawContactIdToDelete);
- getContentResolver().delete(rawContactUri, null, null);
- }
- } else {
- getContentResolver().delete(mLookupUri, null, null);
- }
+ getContentResolver().delete(mLookupUri, null, null);
finish();
}
.setPositiveButton(android.R.string.ok, this)
.setCancelable(false)
.create();
+ case DIALOG_CONFIRM_READONLY_HIDE: {
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.deleteConfirmation_title)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(R.string.readOnlyContactWarning)
+ .setPositiveButton(android.R.string.ok, this)
+ .create();
+ }
+
}
return null;
}
final boolean hasRawContact = (mRawContactIds.size() > 0);
menu.findItem(R.id.menu_edit).setEnabled(hasRawContact);
- // Disable delete for readonly contact
- if (mWritableSourcesCnt == 0) {
- menu.findItem(R.id.menu_delete).setEnabled(false);
- }
return true;
}
// Get confirmation
if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
showDialog(DIALOG_CONFIRM_READONLY_DELETE);
- } else if (mWritableSourcesCnt > 1) {
+ } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
+ showDialog(DIALOG_CONFIRM_READONLY_HIDE);
+ } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
} else {
showDialog(DIALOG_CONFIRM_DELETE);
case KeyEvent.KEYCODE_DEL: {
if (mReadOnlySourcesCnt > 0 & mWritableSourcesCnt > 0) {
showDialog(DIALOG_CONFIRM_READONLY_DELETE);
- } else if (mWritableSourcesCnt > 1) {
+ } else if (mReadOnlySourcesCnt > 0 && mWritableSourcesCnt == 0) {
+ showDialog(DIALOG_CONFIRM_READONLY_HIDE);
+ } else if (mReadOnlySourcesCnt == 0 && mWritableSourcesCnt > 1) {
showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
} else {
showDialog(DIALOG_CONFIRM_DELETE);
if (!mRawContactIds.contains(rawContactId)) {
mRawContactIds.add(rawContactId);
}
+ ContactsSource contactsSource = sources.getInflatedSource(accountType,
+ ContactsSource.LEVEL_SUMMARY);
+ if (contactsSource != null && contactsSource.readOnly) {
+ mReadOnlySourcesCnt += 1;
+ } else {
+ mWritableSourcesCnt += 1;
+ mWritableRawContactIds.add(rawContactId);
+ }
+
for (NamedContentValues subValue : entity.getSubValues()) {
ViewEntry entry = new ViewEntry();
private long mRawContactIdRequestingPhoto = -1;
+ private static final int DIALOG_CONFIRM_DELETE = 1;
+ private static final int DIALOG_CONFIRM_READONLY_DELETE = 2;
+ private static final int DIALOG_CONFIRM_MULTIPLE_DELETE = 3;
+ private static final int DIALOG_CONFIRM_READONLY_HIDE = 4;
String mQuerySelection;
}
}
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_CONFIRM_DELETE:
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.deleteConfirmation_title)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(R.string.deleteConfirmation)
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(android.R.string.ok, new DeleteClickListener())
+ .setCancelable(false)
+ .create();
+ case DIALOG_CONFIRM_READONLY_DELETE:
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.deleteConfirmation_title)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(R.string.readOnlyContactDeleteConfirmation)
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(android.R.string.ok, new DeleteClickListener())
+ .setCancelable(false)
+ .create();
+ case DIALOG_CONFIRM_MULTIPLE_DELETE:
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.deleteConfirmation_title)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(R.string.multipleContactDeleteConfirmation)
+ .setNegativeButton(android.R.string.cancel, null)
+ .setPositiveButton(android.R.string.ok, new DeleteClickListener())
+ .setCancelable(false)
+ .create();
+ case DIALOG_CONFIRM_READONLY_HIDE:
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.deleteConfirmation_title)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(R.string.readOnlyContactWarning)
+ .setPositiveButton(android.R.string.ok, new DeleteClickListener())
+ .setCancelable(false)
+ .create();
+ }
+ return null;
+ }
+
/**
* Start managing this {@link Dialog} along with the {@link Activity}.
*/
return true;
}
+ private class DeleteClickListener implements DialogInterface.OnClickListener {
+
+ public void onClick(DialogInterface dialog, int which) {
+ Sources sources = Sources.getInstance(EditContactActivity.this);
+ // Mark all raw contacts for deletion
+ for (EntityDelta delta : mState) {
+ delta.markDeleted();
+ }
+ // Save the deletes
+ doSaveAction(SAVE_MODE_DEFAULT);
+ finish();
+ }
+ }
+
private void onSaveCompleted(boolean success, int saveMode, Uri contactLookupUri) {
switch (saveMode) {
case SAVE_MODE_DEFAULT:
*/
private boolean doDeleteAction() {
if (!hasValidState()) return false;
-
- showAndManageDialog(createDeleteDialog());
- return true;
+ int readOnlySourcesCnt = 0;
+ int writableSourcesCnt = 0;
+ Sources sources = Sources.getInstance(EditContactActivity.this);
+ for (EntityDelta delta : mState) {
+ final String accountType = delta.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
+ final ContactsSource contactsSource = sources.getInflatedSource(accountType,
+ ContactsSource.LEVEL_CONSTRAINTS);
+ if (contactsSource != null && contactsSource.readOnly) {
+ readOnlySourcesCnt += 1;
+ } else {
+ writableSourcesCnt += 1;
+ }
+ }
+
+ if (readOnlySourcesCnt > 0 && writableSourcesCnt > 0) {
+ showDialog(DIALOG_CONFIRM_READONLY_DELETE);
+ } else if (readOnlySourcesCnt > 0 && writableSourcesCnt == 0) {
+ showDialog(DIALOG_CONFIRM_READONLY_HIDE);
+ } else if (readOnlySourcesCnt == 0 && writableSourcesCnt > 1) {
+ showDialog(DIALOG_CONFIRM_MULTIPLE_DELETE);
+ } else {
+ showDialog(DIALOG_CONFIRM_DELETE);
+ }
+ return true;
}
/**