OSDN Git Service

Fixes bug where delete option from Menu list is disabled in Contact view mode.
authorMegha Joshi <mjoshi@google.com>
Fri, 2 Oct 2009 00:31:49 +0000 (17:31 -0700)
committerMegha Joshi <mjoshi@google.com>
Sat, 3 Oct 2009 06:59:29 +0000 (23:59 -0700)
Bug was caused by the count increment logic being removed in the next submitted change
https://android-git.corp.google.com/w/?p=platform/packages/apps/Contacts.git;a=commit;h=df18120ed2c37a45eb47e39c4da0c8e3b6eb335c
Disabled menu was removed in some other subsequent change, so adding dialog for the case when writable contacts = 0.

Changes delete contact bebavior in EditContactActivity to be same
ViewContactActivity.

Updates dialog message for readonly contact deletion.

bug 2161222
Dr No : TS
Reviewed By: dplotnikov, timsullivan

res/values/ids.xml
res/values/strings.xml
src/com/android/contacts/ContactsListActivity.java
src/com/android/contacts/ViewContactActivity.java
src/com/android/contacts/ui/EditContactActivity.java

index 72ab82f..5e287ad 100644 (file)
@@ -43,7 +43,7 @@
 
     <!-- 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" />
 
index 7dc1778..dbe8d09 100644 (file)
     <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>
index 3250c41..4125d7a 100644 (file)
@@ -402,15 +402,7 @@ public class ContactsListActivity extends ListActivity implements
         }
 
         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);
         }
     }
 
@@ -890,18 +882,21 @@ public class ContactsListActivity extends ListActivity implements
                         .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();
             }
@@ -910,6 +905,7 @@ public class ContactsListActivity extends ListActivity implements
                         .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();
             }
@@ -1178,7 +1174,7 @@ public class ContactsListActivity extends ListActivity implements
            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 {
index ab8e931..d6ab83c 100644 (file)
@@ -91,6 +91,7 @@ public class ViewContactActivity extends Activity
     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;
@@ -146,15 +147,7 @@ public class ViewContactActivity extends Activity
 
     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();
     }
 
@@ -264,6 +257,15 @@ public class ViewContactActivity extends Activity
                         .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;
     }
@@ -384,10 +386,6 @@ public class ViewContactActivity extends Activity
         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;
     }
 
@@ -446,7 +444,9 @@ public class ViewContactActivity extends Activity
                 // 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);
@@ -649,7 +649,9 @@ public class ViewContactActivity extends Activity
             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);
@@ -725,6 +727,15 @@ public class ViewContactActivity extends Activity
                 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();
index 3377bd6..fef6a9f 100644 (file)
@@ -105,6 +105,10 @@ public final class EditContactActivity extends Activity
 
     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;
 
@@ -240,6 +244,48 @@ public final class EditContactActivity extends Activity
         }
     }
 
+    @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}.
      */
@@ -566,6 +612,20 @@ public final class EditContactActivity extends 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:
@@ -702,9 +762,30 @@ public final class EditContactActivity extends Activity
      */
     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;
     }
 
     /**