Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e76408e authored by Walter Jang's avatar Walter Jang
Browse files

Distinguish between editor back button presses and framework stopage

We carry whether the editor fragment is being stopped
because of a back button press or because the framework
stopped the hosting Activity all the way through the various
editor fragment callbacks and the ContactSaveService because
it is not until ContactEditorBaseActivity.onSaveFinished
where we start the next Intent -- starting it causes a
"flash" if recents is clicked and follwed by an immediate
starting of the next editor Activity, which is the bug
that was filed.

With this change, we only use the ContactSaveService
resultIntent to go back to the compact editor on back
presses.  The expected behavior/tested scenarios are
described at go/b21198041

Bug 21198041
Bug 19624360

Change-Id: Ic350e12aa447cff81747e003f504f25100bd5c60
parent 11708263
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactModifier;
import com.android.contacts.common.model.RawContactModifier;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.editor.ContactEditorFragment;
import com.android.contacts.util.ContactPhotoUtils;
import com.android.contacts.util.ContactPhotoUtils;


import com.google.common.collect.Lists;
import com.google.common.collect.Lists;
@@ -300,7 +301,7 @@ public class ContactSaveService extends IntentService {
        Bundle bundle = new Bundle();
        Bundle bundle = new Bundle();
        bundle.putParcelable(String.valueOf(rawContactId), updatedPhotoPath);
        bundle.putParcelable(String.valueOf(rawContactId), updatedPhotoPath);
        return createSaveContactIntent(context, state, saveModeExtraKey, saveMode, isProfile,
        return createSaveContactIntent(context, state, saveModeExtraKey, saveMode, isProfile,
                callbackActivity, callbackAction, bundle);
                callbackActivity, callbackAction, bundle, /* backPressed =*/ false);
    }
    }


    /**
    /**
@@ -309,11 +310,13 @@ public class ContactSaveService extends IntentService {
     * This variant is used when multiple contacts' photos may be updated, as in the
     * This variant is used when multiple contacts' photos may be updated, as in the
     * Contact Editor.
     * Contact Editor.
     * @param updatedPhotos maps each raw-contact's ID to the file-path of the new photo.
     * @param updatedPhotos maps each raw-contact's ID to the file-path of the new photo.
     * @param backPressed whether the save was initiated as a result of a back button press
     *         or because the framework stopped the editor Activity
     */
     */
    public static Intent createSaveContactIntent(Context context, RawContactDeltaList state,
    public static Intent createSaveContactIntent(Context context, RawContactDeltaList state,
            String saveModeExtraKey, int saveMode, boolean isProfile,
            String saveModeExtraKey, int saveMode, boolean isProfile,
            Class<? extends Activity> callbackActivity, String callbackAction,
            Class<? extends Activity> callbackActivity, String callbackAction,
            Bundle updatedPhotos) {
            Bundle updatedPhotos, boolean backPressed) {
        Intent serviceIntent = new Intent(
        Intent serviceIntent = new Intent(
                context, ContactSaveService.class);
                context, ContactSaveService.class);
        serviceIntent.setAction(ContactSaveService.ACTION_SAVE_CONTACT);
        serviceIntent.setAction(ContactSaveService.ACTION_SAVE_CONTACT);
@@ -333,6 +336,8 @@ public class ContactSaveService extends IntentService {
            if (updatedPhotos != null) {
            if (updatedPhotos != null) {
                callbackIntent.putExtra(EXTRA_UPDATED_PHOTOS, (Parcelable) updatedPhotos);
                callbackIntent.putExtra(EXTRA_UPDATED_PHOTOS, (Parcelable) updatedPhotos);
            }
            }
            callbackIntent.putExtra(ContactEditorFragment.INTENT_EXTRA_SAVE_BACK_PRESSED,
                    backPressed);
            serviceIntent.putExtra(ContactSaveService.EXTRA_CALLBACK_INTENT, callbackIntent);
            serviceIntent.putExtra(ContactSaveService.EXTRA_CALLBACK_INTENT, callbackIntent);
        }
        }
        return serviceIntent;
        return serviceIntent;
+1 −1
Original line number Original line Diff line number Diff line
@@ -60,7 +60,7 @@ public class CompactContactEditorActivity extends ContactEditorBaseActivity {
    @Override
    @Override
    public void onBackPressed() {
    public void onBackPressed() {
        if (mFragment != null) {
        if (mFragment != null) {
            mFragment.save(ContactEditor.SaveMode.CLOSE);
            mFragment.save(ContactEditor.SaveMode.CLOSE, /* backPressed =*/ true);
        }
        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ public class ContactEditorActivity extends ContactEditorBaseActivity
    @Override
    @Override
    public void onBackPressed() {
    public void onBackPressed() {
        if (mFragment != null) {
        if (mFragment != null) {
            mFragment.save(ContactEditor.SaveMode.COMPACT);
            mFragment.save(ContactEditor.SaveMode.COMPACT, /* backPressed =*/ true);
        }
        }
    }
    }
}
}
+14 −5
Original line number Original line Diff line number Diff line
@@ -153,14 +153,17 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
        /**
        /**
         * Saves or creates the contact based on the mode, and if successful
         * Saves or creates the contact based on the mode, and if successful
         * finishes the activity.
         * finishes the activity.
         *
         * @param backPressed whether the save was initiated as a result of a back button press
         *         or because the framework stopped the editor Activity
         */
         */
        boolean save(int saveMode);
        boolean save(int saveMode, boolean backPressed);


        /**
        /**
         * Invoked after the contact is saved.
         * Invoked after the contact is saved.
         */
         */
        void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
        void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
                Uri contactLookupUri, Bundle updatedPhotos);
                Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed);


        /**
        /**
         * Invoked after the contact is joined.
         * Invoked after the contact is joined.
@@ -238,7 +241,9 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
                            ContactEditor.SaveMode.CLOSE),
                            ContactEditor.SaveMode.CLOSE),
                    intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false),
                    intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false),
                    intent.getData(),
                    intent.getData(),
                    (Bundle) intent.getParcelableExtra(ContactSaveService.EXTRA_UPDATED_PHOTOS));
                    (Bundle) intent.getParcelableExtra(ContactSaveService.EXTRA_UPDATED_PHOTOS),
                    intent.getBooleanExtra(ContactEditorFragment.INTENT_EXTRA_SAVE_BACK_PRESSED,
                            false));
        } else if (ACTION_JOIN_COMPLETED.equals(action)) {
        } else if (ACTION_JOIN_COMPLETED.equals(action)) {
            mFragment.onJoinCompleted(intent.getData());
            mFragment.onJoinCompleted(intent.getData());
        }
        }
@@ -268,12 +273,16 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity


        @Override
        @Override
        public void onSaveFinished(Intent resultIntent) {
        public void onSaveFinished(Intent resultIntent) {
            final boolean backPressed = resultIntent == null ? false : resultIntent.getBooleanExtra(
                    ContactEditorBaseFragment.INTENT_EXTRA_SAVE_BACK_PRESSED, false);
            if (mFinishActivityOnSaveCompleted) {
            if (mFinishActivityOnSaveCompleted) {
                setResult(resultIntent == null ? RESULT_CANCELED : RESULT_OK, resultIntent);
                setResult(resultIntent == null ? RESULT_CANCELED : RESULT_OK, resultIntent);
            } else if (resultIntent != null) {
            } else if (resultIntent != null) {
                if (backPressed) {
                    ImplicitIntentsUtil.startActivityInApp(ContactEditorBaseActivity.this,
                    ImplicitIntentsUtil.startActivityInApp(ContactEditorBaseActivity.this,
                            resultIntent);
                            resultIntent);
                }
                }
            }
            finish();
            finish();
        }
        }


+4 −4
Original line number Original line Diff line number Diff line
@@ -188,7 +188,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl


        // If anything was left unsaved, save it now
        // If anything was left unsaved, save it now
        if (!getActivity().isChangingConfigurations() && mStatus == Status.EDITING) {
        if (!getActivity().isChangingConfigurations() && mStatus == Status.EDITING) {
            save(SaveMode.RELOAD);
            save(SaveMode.RELOAD, /* backPressed =*/ false);
        }
        }
    }
    }


@@ -297,12 +297,12 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
    }
    }


    @Override
    @Override
    protected boolean doSaveAction(int saveMode) {
    protected boolean doSaveAction(int saveMode, boolean backPressed) {
        // Save contact. No need to pass the palette since we are finished editing after the save.
        // Save contact. No need to pass the palette since we are finished editing after the save.
        final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
        final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
                SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
                SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
                ((Activity) mContext).getClass(),
                ((Activity) mContext).getClass(),
                CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos);
                CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos, backPressed);
        mContext.startService(intent);
        mContext.startService(intent);


        return true;
        return true;
@@ -350,7 +350,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
            mShowToastAfterSave = false;
            mShowToastAfterSave = false;


            // Save whatever is in the form
            // Save whatever is in the form
            save(SaveMode.RELOAD);
            save(SaveMode.RELOAD, /* backPressed =*/ false);
        }
        }


        // Prepare an Intent to start the expanded editor
        // Prepare an Intent to start the expanded editor
Loading