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

Commit 92f8ccc1 authored by Walter Jang's avatar Walter Jang
Browse files

Do setIntentExtras, on[Save|Join]Completed in base contact edit fragment

Do setGroupMetaData in the child classes since the layout will be
drastically different between the two.

Also moved a public Intent extra constant to the base.

Bug 19124091

Change-Id: Idd20ff39b91eb3584c69e406f1e3472bcb278f42
parent 3e9a6244
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
        void load(String action, Uri lookupUri, Bundle intentExtras);

        /**
         * Merges extras from the intent.
         * Applies extras from the hosting Activity to the first writable raw contact.
         */
        void setIntentExtras(Bundle extras);

+2 −15
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.android.contacts.R;
import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -55,24 +54,12 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment
    protected void bindEditors() {
    }

    //
    // ContactEditor
    //

    @Override
    public void setIntentExtras(Bundle extras) {
    protected void setGroupMetaData() {
    }

    @Override
    protected boolean doSaveAction(int saveMode) {
        onSaveCompleted(/* hadChanges =*/ false, saveMode,
                /* saveSucceeded =*/ mLookupUri != null, mLookupUri);
        return true;
    }

    @Override
    public void onJoinCompleted(Uri uri) {
        onSaveCompleted(/* hadChanges =*/ false, SaveMode.RELOAD,
                /* saveSucceeded =*/ uri != null, uri);
        return false;
    }
}
+34 −11
Original line number Diff line number Diff line
@@ -148,6 +148,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    public static final String INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION =
            "disableDeleteMenuOption";

    /**
     * Intent extra to specify a {@link ContactEditor.SaveMode}.
     */
    public static final String SAVE_MODE_EXTRA_KEY = "saveMode";

    /**
     * Callbacks for Activities that host contact editors Fragments.
     */
@@ -661,6 +666,16 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        }
    }

    /**
     * Invalidates the options menu if we are still associated with an Activity.
     */
    protected void invalidateOptionsMenu() {
        final Activity activity = getActivity();
        if (activity != null) {
            activity.invalidateOptionsMenu();
        }
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, final MenuInflater inflater) {
        inflater.inflate(R.menu.edit_contact, menu);
@@ -1061,22 +1076,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    /**
     * Sets group metadata on all bound editors.
     */
    protected void setGroupMetaData() {
        if (mGroupMetaData == null) {
            return;
        }
        int editorCount = mContent.getChildCount();
        for (int i = 0; i < editorCount; i++) {
            BaseRawContactEditorView editor = (BaseRawContactEditorView) mContent.getChildAt(i);
            editor.setGroupMetaData(mGroupMetaData);
        }
    }
    abstract protected void setGroupMetaData();

    /**
     * Bind editors using {@link #mState} and other members initialized from the loaded (or new)
     * Contact.
     */
    abstract void bindEditors();
    abstract protected void bindEditors();

    /**
     * Set the enabled state of editors.
@@ -1134,6 +1140,23 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        }
    }

    @Override
    public void setIntentExtras(Bundle extras) {
        if (extras == null || extras.size() == 0) {
            return;
        }

        final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
        for (RawContactDelta state : mState) {
            final AccountType type = state.getAccountType(accountTypes);
            if (type.areContactsWritable()) {
                // Apply extras to the first writable raw contact only
                RawContactModifier.parseExtras(mContext, type, state, extras);
                break;
            }
        }
    }

    @Override
    public void onJoinCompleted(Uri uri) {
        onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri);
+13 −21
Original line number Diff line number Diff line
@@ -71,8 +71,6 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
    private static final String KEY_CURRENT_PHOTO_URI = "currentphotouri";
    private static final String KEY_UPDATED_PHOTOS = "updatedPhotos";

    public static final String SAVE_MODE_EXTRA_KEY = "saveMode";

    // Used to store which raw contact editors have been expanded. Keyed on raw contact ids.
    private HashMap<Long, Boolean> mExpandedEditors = new HashMap<Long, Boolean>();

@@ -132,23 +130,6 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
        updatedExpandedEditorsMap();
    }

    @Override
    public void setIntentExtras(Bundle extras) {
        if (extras == null || extras.size() == 0) {
            return;
        }

        final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
        for (RawContactDelta state : mState) {
            final AccountType type = state.getAccountType(accountTypes);
            if (type.areContactsWritable()) {
                // Apply extras to the first writable raw contact only
                RawContactModifier.parseExtras(mContext, type, state, extras);
                break;
            }
        }
    }

    /**
     * Removes a current editor ({@link #mState}) and rebinds new editor for a new account.
     * Some of old data are reused with new restriction enforced by the new account.
@@ -180,6 +161,18 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
        }
    }

    @Override
    protected void setGroupMetaData() {
        if (mGroupMetaData == null) {
            return;
        }
        int editorCount = mContent.getChildCount();
        for (int i = 0; i < editorCount; i++) {
            BaseRawContactEditorView editor = (BaseRawContactEditorView) mContent.getChildAt(i);
            editor.setGroupMetaData(mGroupMetaData);
        }
    }

    @Override
    protected void bindEditors() {
        // bindEditors() can only bind views if there is data in mState, so immediately return
@@ -309,8 +302,7 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements

        // Refresh Action Bar as the visibility of the join command
        // Activity can be null if we have been detached from the Activity
        final Activity activity = getActivity();
        if (activity != null) activity.invalidateOptionsMenu();
        invalidateOptionsMenu();

        updatedExpandedEditorsMap();
    }