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

Commit 5a7a23bd authored by Walter Jang's avatar Walter Jang
Browse files

Return to the compact contact editor on back from the fully expanded one

Bug 19624360

Change-Id: I249f1e456a2d85c5ecd831358692d56b09ee5a5b
parent 22876085
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -42,4 +42,11 @@ public class CompactContactEditorActivity extends ContactEditorBaseActivity {
        final Uri uri = Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
        mFragment.load(action, uri, getIntent().getExtras());
    }

    @Override
    public void onBackPressed() {
        if (mFragment != null) {
            mFragment.save(ContactEditor.SaveMode.CLOSE);
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -45,4 +45,11 @@ public class ContactEditorActivity extends ContactEditorBaseActivity
                || Intent.ACTION_EDIT.equals(action) ? getIntent().getData() : null;
        mFragment.load(action, uri, getIntent().getExtras());
    }

    @Override
    public void onBackPressed() {
        if (mFragment != null) {
            mFragment.save(ContactEditor.SaveMode.COMPACT);
        }
    }
}
+5 −19
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.editor.ContactEditorBaseFragment;
import com.android.contacts.editor.ContactEditorFragment;
import com.android.contacts.editor.EditorIntents;
import com.android.contacts.interactions.ContactDeletionInteraction;
import com.android.contacts.util.DialogManager;

@@ -95,9 +96,9 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
            public static final int JOIN = 3;

            /**
             * Navigate to Contacts Home activity after saving.
             * Navigate to the compact editor view after saving.
             */
            public static final int HOME = 4;
            public static final int COMPACT = 4;
        }

        /**
@@ -258,13 +259,6 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
        return null;
    }

    @Override
    public void onBackPressed() {
        if (mFragment != null) {
            mFragment.save(ContactEditor.SaveMode.CLOSE);
        }
    }

    protected final ContactEditorBaseFragment.Listener  mFragmentListener =
            new ContactEditorBaseFragment.Listener() {

@@ -302,16 +296,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
        @Override
        public void onEditOtherContactRequested(
                Uri contactLookupUri, ArrayList<ContentValues> values) {
            Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                    | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            intent.putExtra(ContactEditorFragment.INTENT_EXTRA_ADD_TO_DEFAULT_DIRECTORY, "");

            // Pass on all the data that has been entered so far
            if (values != null && values.size() != 0) {
                intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, values);
            }

            final Intent intent = EditorIntents.createEditOtherContactIntent(
                    contactLookupUri, values);
            ImplicitIntentsUtil.startActivityInApp(ContactEditorBaseActivity.this, intent);
            finish();
        }
+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.contacts.activities.ActionBarAdapter.TabState;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.dialog.ClearFrequentsDialog;
import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.editor.EditorIntents;
import com.android.contacts.interactions.ContactDeletionInteraction;
import com.android.contacts.common.interactions.ImportExportDialogFragment;
import com.android.contacts.common.list.ContactEntryListFragment;
@@ -959,7 +960,7 @@ public class PeopleActivity extends ContactsActivity implements
        @Override
        public void onCreateNewContactAction() {
            ImplicitIntentsUtil.startActivityInApp(PeopleActivity.this,
                    new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
                    EditorIntents.createCompactInsertContactIntent());
        }

        @Override
+33 −32
Original line number Diff line number Diff line
@@ -31,14 +31,11 @@ import com.android.contacts.detail.PhotoSelectionHandler;
import com.android.contacts.util.ContactPhotoUtils;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -48,7 +45,6 @@ import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.io.FileNotFoundException;
import java.util.ArrayList;

/**
 * Contact editor with only the most important fields displayed initially.
@@ -184,6 +180,16 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onStop() {
        super.onStop();

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

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
@@ -339,38 +345,11 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
    @Override
    public void onExpandEditor() {
        // Determine if this is an insert (new contact) or edit
        final String action = getActivity().getIntent().getAction();
        final boolean isInsert = Intent.ACTION_INSERT.equals(action)
                || ContactEditorBaseActivity.ACTION_INSERT.equals(action);

        // Prepare an Intent to start the expanded editor
        final Intent intent = isInsert
                ? new Intent(ContactEditorBaseActivity.ACTION_INSERT,
                        ContactsContract.Contacts.CONTENT_URI)
                : new Intent(ContactEditorBaseActivity.ACTION_EDIT, mLookupUri);
        intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
                | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
        final boolean isInsert = isInsert(getActivity().getIntent());

        if (isInsert) {
            // For inserts, prevent any changes from being saved when the base fragment is destroyed
            mStatus = Status.CLOSING;

            // Pass on all the data that has been entered so far
            ArrayList<ContentValues> contentValues = mState.get(0).getContentValues();
            if (contentValues != null && contentValues.size() != 0) {
                intent.putParcelableArrayListExtra(
                        ContactsContract.Intents.Insert.DATA, contentValues);
            }
            // Name must be passed separately since it is skipped in RawContactModifier.parseValues
            final StructuredNameEditorView structuredNameEditorView =
                    getContent().getStructuredNameEditorView();
            if (structuredNameEditorView != null) {
                final String displayName = structuredNameEditorView.getDisplayName();
                if (!TextUtils.isEmpty(displayName)) {
                    intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName);
                }
            }
            getActivity().finish();
        } else {
            // Prevent a Toast from being displayed as we transition to the full editor
            mShowToastAfterSave = false;
@@ -379,7 +358,16 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
            save(SaveMode.RELOAD);
        }

        // Prepare an Intent to start the expanded editor
        final Intent intent = isInsert
                ? EditorIntents.createInsertContactIntent(mState, getDisplayName())
                : EditorIntents.createEditContactIntent(mLookupUri);
        ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);

        final Activity activity = getActivity();
        if (activity != null) {
            activity.finish();
        }
    }

    @Override
@@ -393,6 +381,19 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
        }
    }

    @Override
    public MaterialColorMapUtils.MaterialPalette getMaterialPalette() {
        return mMaterialPalette;
    }

    @Override
    public String getDisplayName() {
        final StructuredNameEditorView structuredNameEditorView =
                getContent().getStructuredNameEditorView();
        return structuredNameEditorView == null
                ? null : structuredNameEditorView.getDisplayName();
    }

    private CompactRawContactsEditorView getContent() {
        return (CompactRawContactsEditorView) mContent;
    }
Loading