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

Commit c4e9baf0 authored by Walter Jang's avatar Walter Jang Committed by android-build-merger
Browse files

Don\'t save editor before showing join suggestions

am: e3373dce

* commit 'e3373dce':
  Don't save editor before showing join suggestions
parents 20526f3f e3373dce
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -147,6 +147,12 @@
    <!-- Confirmation dialog for unlinking contacts into multiple instances [CHAR LIMIT=NONE] -->
    <string name="splitConfirmation">This contact will be unlinked into multiple contacts.</string>

    <!-- Title of the confirmation dialog for joining contacts when there are unsaved changes. [CHAR LIMIT=40] -->
    <string name="joinConfirmation_title">Link contact?</string>

    <!-- Confirmation dialog message for joining contacts when there are unsaved changes. [CHAR LIMIT=NONE] -->
    <string name="joinConfirmation">There are unsaved changes. Do you want to save them before linking?</string>

    <!-- Menu item that links an aggregate with another aggregate -->
    <string name="menu_joinAggregate">Link</string>

+9 −2
Original line number Diff line number Diff line
@@ -313,7 +313,8 @@ public class ContactSaveService extends IntentService {
        Bundle bundle = new Bundle();
        bundle.putParcelable(String.valueOf(rawContactId), updatedPhotoPath);
        return createSaveContactIntent(context, state, saveModeExtraKey, saveMode, isProfile,
                callbackActivity, callbackAction, bundle);
                callbackActivity, callbackAction, bundle,
                /* joinContactIdExtraKey */ null, /* joinContactId */ null);
    }

    /**
@@ -321,12 +322,15 @@ public class ContactSaveService extends IntentService {
     * using data presented as a set of ContentValues.
     * This variant is used when multiple contacts' photos may be updated, as in the
     * Contact Editor.
     *
     * @param updatedPhotos maps each raw-contact's ID to the file-path of the new photo.
     * @param joinContactIdExtraKey the key used to pass the joinContactId in the callback intent.
     * @param joinContactId the raw contact ID to join to the contact after doing the save.
     */
    public static Intent createSaveContactIntent(Context context, RawContactDeltaList state,
            String saveModeExtraKey, int saveMode, boolean isProfile,
            Class<? extends Activity> callbackActivity, String callbackAction,
            Bundle updatedPhotos) {
            Bundle updatedPhotos, String joinContactIdExtraKey, Long joinContactId) {
        Intent serviceIntent = new Intent(
                context, ContactSaveService.class);
        serviceIntent.setAction(ContactSaveService.ACTION_SAVE_CONTACT);
@@ -344,6 +348,9 @@ public class ContactSaveService extends IntentService {
            // the callback intent.
            Intent callbackIntent = new Intent(context, callbackActivity);
            callbackIntent.putExtra(saveModeExtraKey, saveMode);
            if (joinContactIdExtraKey != null && joinContactId != null) {
                callbackIntent.putExtra(joinContactIdExtraKey, joinContactId);
            }
            callbackIntent.setAction(callbackAction);
            serviceIntent.putExtra(ContactSaveService.EXTRA_CALLBACK_INTENT, callbackIntent);
        }
+3 −2
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
         * Invoked after the contact is saved.
         */
        void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
                Uri contactLookupUri);
                Uri contactLookupUri, Long joinContactId);

        /**
         * Invoked after the contact is joined.
@@ -256,7 +256,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
                    intent.getIntExtra(ContactEditorFragment.SAVE_MODE_EXTRA_KEY,
                            ContactEditor.SaveMode.CLOSE),
                    intent.getBooleanExtra(ContactSaveService.EXTRA_SAVE_SUCCEEDED, false),
                    intent.getData());
                    intent.getData(),
                    intent.getLongExtra(ContactEditorFragment.JOIN_CONTACT_ID_EXTRA_KEY, -1));
        } else if (ACTION_JOIN_COMPLETED.equals(action)) {
            mFragment.onJoinCompleted(intent.getData());
        }
+3 −2
Original line number Diff line number Diff line
@@ -159,11 +159,12 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
    }

    @Override
    protected boolean doSaveAction(int saveMode) {
    protected boolean doSaveAction(int saveMode, Long joinContactId) {
        final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
                SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
                ((Activity) mContext).getClass(),
                CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos);
                CompactContactEditorActivity.ACTION_SAVE_COMPLETED, mUpdatedPhotos,
                JOIN_CONTACT_ID_EXTRA_KEY, joinContactId);
        try {
            mContext.startService(intent);
        } catch (Exception exception) {
+34 −14
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import java.util.Set;
 */
abstract public class ContactEditorBaseFragment extends Fragment implements
        ContactEditor, SplitContactConfirmationDialogFragment.Listener,
        JoinContactConfirmationDialogFragment.Listener,
        AggregationSuggestionEngine.Listener, AggregationSuggestionView.Listener,
        CancelEditDialogFragment.Listener {

@@ -207,6 +208,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     */
    public static final String SAVE_MODE_EXTRA_KEY = "saveMode";

    /**
     * Intent extra key for the contact ID to join the current contact to after saving.
     */
    public static final String JOIN_CONTACT_ID_EXTRA_KEY = "joinContactId";

    /**
     * Callbacks for Activities that host contact editors Fragments.
     */
@@ -668,8 +674,14 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                if (resultCode != Activity.RESULT_OK) return;
                if (data != null) {
                    final long contactId = ContentUris.parseId(data.getData());
                    if (hasPendingChanges()) {
                        // Ask the user if they want to save changes before doing the join
                        JoinContactConfirmationDialogFragment.show(this, contactId);
                    } else {
                        // Do the join immediately
                        joinAggregate(contactId);
                    }
                }
                break;
            }
            case REQUEST_CODE_ACCOUNTS_CHANGED: {
@@ -870,7 +882,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    }

    private boolean doJoinContactAction() {
        if (!hasValidState()) {
        if (!hasValidState() || mLookupUri == null) {
            return false;
        }

@@ -883,7 +895,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            return true;
        }

        return save(SaveMode.JOIN);
        showJoinAggregateActivity(mLookupUri);
        return true;
    }

    @Override
    public void onJoinContactConfirmed(long joinContactId) {
        doSaveAction(SaveMode.JOIN, joinContactId);
    }

    private void doPickRingtone() {
@@ -931,19 +949,22 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                return true;
            }
            onSaveCompleted(/* hadChanges =*/ false, saveMode,
                    /* saveSucceeded =*/ mLookupUri != null, mLookupUri);
                    /* saveSucceeded =*/ mLookupUri != null, mLookupUri, /* joinContactId =*/ null);
            return true;
        }

        setEnabled(false);

        return doSaveAction(saveMode);
        return doSaveAction(saveMode, /* joinContactId */ null);
    }

    /**
     * Persist the accumulated editor deltas.
     *
     * @param joinContactId the raw contact ID to join the contact being saved to after the save,
     *         may be null.
     */
    abstract protected boolean doSaveAction(int saveMode);
    abstract protected boolean doSaveAction(int saveMode, Long joinContactId);

    //
    // State accessor methods
@@ -1392,12 +1413,12 @@ abstract public class ContactEditorBaseFragment extends Fragment implements

    @Override
    public void onJoinCompleted(Uri uri) {
        onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri);
        onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri, /* joinContactId */ null);
    }

    @Override
    public void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
            Uri contactLookupUri) {
            Uri contactLookupUri, Long joinContactId) {
        if (hadChanges) {
            if (saveSucceeded) {
                switch (saveMode) {
@@ -1438,14 +1459,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                if (mListener != null) mListener.onSaveFinished(/* resultIntent= */ null);
                break;
            }
            case SaveMode.RELOAD:
            case SaveMode.JOIN:
                if (saveSucceeded && contactLookupUri != null) {
                    // If it was a JOIN, we are now ready to bring up the join activity.
                    if (saveMode == SaveMode.JOIN && hasValidState()) {
                        showJoinAggregateActivity(contactLookupUri);
                if (saveSucceeded && contactLookupUri != null && joinContactId != null) {
                    joinAggregate(joinContactId);
                }

                break;
            case SaveMode.RELOAD:
                if (saveSucceeded && contactLookupUri != null) {
                    // If this was in INSERT, we are changing into an EDIT now.
                    // If it already was an EDIT, we are changing to the new Uri now
                    mState = new RawContactDeltaList();
Loading