No toast when navigating back to the compact editor for existing contacts

Bug 19624360

Change-Id: Ic1b344583a453e482acb2c2911ae05eee077fb43
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index f33f796..e53f841 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -133,7 +133,6 @@
     private PhotoHandler mPhotoHandler;
     private Uri mPhotoUri;
     private long mPhotoRawContactId;
-    private boolean mShowToastAfterSave = true;
 
     @Override
     public void onCreate(Bundle savedState) {
@@ -306,11 +305,6 @@
     }
 
     @Override
-    protected boolean showToastAfterSave() {
-        return mShowToastAfterSave;
-    }
-
-    @Override
     protected boolean doSaveAction(int saveMode) {
         // Save contact. No need to pass the palette since we are finished editing after the save.
         final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index 5e9a987..640ceeb 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -354,8 +354,7 @@
     protected Bundle mUpdatedPhotos = new Bundle();
 
     //
-    // Editor state for {@link ContactEditorView}.
-    // (Not saved/restored on rotates)
+    // Not saved/restored on rotates
     //
 
     // Used to pre-populate the editor with a display name when a user edits a read-only contact.
@@ -364,6 +363,10 @@
     // Whether the name editor should receive focus after being bound
     protected boolean mRequestFocus;
 
+    // Whether to show a Toast message after saves have completed.
+    // Does not affect successful toasts shown after joins, which are never displayed.
+    protected boolean mShowToastAfterSave = true;
+
     /**
      * The contact data loader listener.
      */
@@ -896,16 +899,15 @@
 
         mStatus = Status.SAVING;
 
-        // Don't abort if there are no changes and we are returning to the compact editor --
-        // the user may have simply expanded the editor then hit back
-        if (!hasPendingChanges() && saveMode != SaveMode.COMPACT) {
+        if (!hasPendingChanges()) {
             if (mLookupUri == null && saveMode == SaveMode.RELOAD) {
                 // We don't have anything to save and there isn't even an existing contact yet.
                 // Nothing to do, simply go back to editing mode
                 mStatus = Status.EDITING;
                 return true;
             }
-            onSaveCompleted(false, saveMode, /* saveSucceeded =*/ mLookupUri != null, mLookupUri,
+            onSaveCompleted(/* hadChanges =*/ false, saveMode,
+                    /* saveSucceeded =*/ mLookupUri != null, mLookupUri,
                     /* updatedPhotos =*/ null);
             return true;
         }
@@ -1329,7 +1331,7 @@
             Uri contactLookupUri, Bundle updatedPhotos) {
         if (hadChanges) {
             if (saveSucceeded) {
-                if (saveMode != SaveMode.JOIN && showToastAfterSave()) {
+                if (saveMode != SaveMode.JOIN && mShowToastAfterSave) {
                     Toast.makeText(mContext, R.string.contactSavedToast, Toast.LENGTH_SHORT).show();
                 }
             } else {
@@ -1340,26 +1342,28 @@
             case SaveMode.CLOSE:
             case SaveMode.COMPACT:
                 final Intent resultIntent;
-                if (saveSucceeded && contactLookupUri != null) {
+                if (!saveSucceeded || contactLookupUri == null) {
+                    resultIntent = saveMode == SaveMode.COMPACT
+                            ? EditorIntents.createCompactInsertContactIntent(
+                                    mState, getDisplayName(), updatedPhotos)
+                            : null;
+                } else {
                     final Uri lookupUri = maybeConvertToLegacyLookupUri(
                             mContext, contactLookupUri, mLookupUri);
                     if (saveMode == SaveMode.CLOSE) {
                         resultIntent = ImplicitIntentsUtil.composeQuickContactIntent(lookupUri,
                                 QuickContactActivity.MODE_FULLY_EXPANDED);
                     } else if (saveMode == SaveMode.COMPACT) {
-                        if (isInsert(getActivity().getIntent())) {
-                            resultIntent = EditorIntents.createCompactInsertContactIntent(
-                                    mState, getDisplayName(), updatedPhotos);
-                        } else {
-                            resultIntent = EditorIntents.createCompactEditContactIntent(
-                                    lookupUri, getMaterialPalette(), updatedPhotos);
-                        }
+                        resultIntent = isInsert(getActivity().getIntent())
+                                ? EditorIntents.createCompactInsertContactIntent(
+                                        mState, getDisplayName(), updatedPhotos)
+                                : EditorIntents.createCompactEditContactIntent(
+                                        lookupUri, getMaterialPalette(), updatedPhotos);
                     } else {
                         resultIntent = null;
                     }
-                } else {
-                    resultIntent = null;
                 }
+
                 // It is already saved, so prevent that it is saved again
                 mStatus = Status.CLOSING;
                 if (mListener != null) mListener.onSaveFinished(resultIntent);
@@ -1395,14 +1399,6 @@
     }
 
     /**
-     * Whether to show a Toast message after saves have completed.
-     * Does not affect successful toasts shown after joins, which are never displayed.
-     */
-    protected boolean showToastAfterSave() {
-        return true;
-    }
-
-    /**
      * Shows a list of aggregates that can be joined into the currently viewed aggregate.
      *
      * @param contactLookupUri the fresh URI for the currently edited contact (after saving it)