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

Commit 91cee285 authored by Tingting Wang's avatar Tingting Wang
Browse files

Fix bugs on Contact editor.

1) Remove primary photo checkbox in full editor. Primary photo should
be set in photo picker.
2) Remove save menu if there's only one read only contact in the full editor.
3) Add account type icon in account info when there's only one account
for a contact.
4) Return back to Compact editor after saving results in full editor.

BUG 24547289

Change-Id: I02f8ee01f7cc7d1b0b06ad338570dc4b17c55e31
parent 655ad1a2
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -21,10 +21,18 @@
        android:id="@+id/account_container"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:background="?android:attr/selectableItemBackground"
        android:paddingStart="16dp"
        android:paddingTop="8dip"
        >

    <ImageView
            android:id="@+id/account_type_icon"
            android:layout_width="@dimen/detail_network_icon_size"
            android:layout_height="@dimen/detail_network_icon_size"
            android:layout_margin="16dip"
            android:layout_gravity="center_vertical" />

    <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="0dp"
+3 −6
Original line number Diff line number Diff line
@@ -260,14 +260,11 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
    }

    @Override
    public void onRawContactSelected(Uri uri, long rawContactId) {
    public void onRawContactSelected(Uri uri, long rawContactId, boolean isReadOnly) {
        final Activity activity = getActivity();
        if (activity != null && !activity.isFinishing()) {
            final Intent intent = new Intent(activity, ContactEditorActivity.class);
            intent.setAction(ContactEditorBaseActivity.ACTION_EDIT);
            intent.setData(uri);
            intent.putExtra(ContactEditorFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE,
                    rawContactId);
            final Intent intent = EditorIntents.createEditContactIntentForRawContact(
                    activity, uri, rawContactId, isReadOnly);
            activity.startActivity(intent);
        }
    }
+18 −12
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        /**
         * Invoked when a rawcontact from merged contacts is selected in editor.
         */
        public void onRawContactSelected(Uri uri, long rawContactId);
        public void onRawContactSelected(Uri uri, long rawContactId, boolean isReadOnly);
    }

    /**
@@ -382,6 +382,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    private View mAccountHeaderContainer;
    private TextView mAccountHeaderType;
    private TextView mAccountHeaderName;
    private ImageView mAccountHeaderIcon;

    // Account selector
    private View mAccountSelectorContainer;
@@ -430,6 +431,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        mAccountHeaderContainer = findViewById(R.id.account_container);
        mAccountHeaderType = (TextView) findViewById(R.id.account_type);
        mAccountHeaderName = (TextView) findViewById(R.id.account_name);
        mAccountHeaderIcon = (ImageView) findViewById(R.id.account_type_icon);

        // Account selector
        mAccountSelectorContainer = findViewById(R.id.account_selector_container);
@@ -824,6 +826,10 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        }
        mAccountHeaderType.setText(accountInfo.second);

        final AccountType primaryAccountType = mPrimaryRawContactDelta.getRawContactAccountType(
                getContext());
        mAccountHeaderIcon.setImageDrawable(primaryAccountType.getDisplayIcon(getContext()));

        mAccountHeaderContainer.setContentDescription(
                EditorUiUtils.getAccountInfoContentDescription(
                        accountInfo.first, accountInfo.second));
@@ -906,19 +912,19 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
                    public void onItemClick(AdapterView<?> parent, View view, int position,
                                            long id) {
                        UiClosables.closeQuietly(popup);
                        final RawContactDelta rawContactDelta = adapter.getItem(position);

                        if (mListener != null) {
                            final long rawContactId = adapter.getItemId(position);
                            final Uri rawContactUri = ContentUris.withAppendedId(
                                    ContactsContract.RawContacts.CONTENT_URI, rawContactId);
                        // Start new activity for the raw contact in selected account.
                        final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                        intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);

                        ArrayList<ContentValues> values = rawContactDelta.getContentValues();
                        intent.putExtra(ContactsContract.Intents.Insert.DATA, values);
                            final RawContactDelta rawContactDelta = adapter.getItem(position);
                            final AccountTypeManager accountTypes = AccountTypeManager.getInstance(
                                    getContext());
                            final AccountType accountType = rawContactDelta.getAccountType(
                                    accountTypes);
                            final boolean isReadOnly = !accountType.areContactsWritable();

                        if (mListener != null) {
                            mListener.onRawContactSelected(rawContactUri, rawContactId);
                            mListener.onRawContactSelected(rawContactUri, rawContactId, isReadOnly);
                        }
                    }
                });
+26 −2
Original line number Diff line number Diff line
@@ -128,6 +128,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    private static final String KEY_IS_EDIT = "isEdit";
    private static final String KEY_EXISTING_CONTACT_READY = "existingContactDataReady";

    private static final String KEY_RAW_CONTACT_DISPLAY_ALONE_IS_READ_ONLY = "isReadOnly";

    // Phone option menus
    private static final String KEY_SEND_TO_VOICE_MAIL_STATE = "sendToVoicemailState";
    private static final String KEY_ARE_PHONE_OPTIONS_CHANGEABLE = "arePhoneOptionsChangable";
@@ -182,6 +184,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     */
    public static final String INTENT_EXTRA_PHOTO_ID = "photo_id";

    /**
     * Intent key to pass the boolean value of if the raw contact id that should be displayed
     * in the full editor by itself is read-only.
     */
    public static final String INTENT_EXTRA_RAW_CONTACT_DISPLAY_ALONE_IS_READ_ONLY =
            "raw_contact_display_alone_is_read_only";

    /**
     * Intent extra to specify a {@link ContactEditor.SaveMode}.
     */
@@ -335,6 +344,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    //
    protected RawContactDeltaList mState;
    protected int mStatus;
    protected boolean mRawContactDisplayAloneIsReadOnly = false;

    // Whether to show the new contact blank form and if it's corresponding delta is ready.
    protected boolean mHasNewContact;
@@ -463,6 +473,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            // Read state from savedState. No loading involved here
            mState = savedState.<RawContactDeltaList> getParcelable(KEY_EDIT_STATE);
            mStatus = savedState.getInt(KEY_STATUS);
            mRawContactDisplayAloneIsReadOnly = savedState.getBoolean(
                    KEY_RAW_CONTACT_DISPLAY_ALONE_IS_READ_ONLY);

            mHasNewContact = savedState.getBoolean(KEY_HAS_NEW_CONTACT);
            mNewContactDataReady = savedState.getBoolean(KEY_NEW_CONTACT_READY);
@@ -587,6 +599,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        outState.putBoolean(KEY_NEW_CONTACT_ACCOUNT_CHANGED, mNewContactAccountChanged);
        outState.putBoolean(KEY_IS_EDIT, mIsEdit);
        outState.putBoolean(KEY_EXISTING_CONTACT_READY, mExistingContactDataReady);
        outState.putBoolean(KEY_RAW_CONTACT_DISPLAY_ALONE_IS_READ_ONLY,
                mRawContactDisplayAloneIsReadOnly);

        outState.putBoolean(KEY_IS_USER_PROFILE, mIsUserProfile);

@@ -753,6 +767,9 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            helpMenu.setVisible(false);
        }

        // Save menu is invisible when there's only one read only contact in the editor.
        saveMenu.setVisible(!mRawContactDisplayAloneIsReadOnly);

        // Hide telephony-related settings (ringtone, send to voicemail)
        // if we don't have a telephone or are editing a new contact.
        sendToVoiceMailMenu.setChecked(mSendToVoicemailState);
@@ -1291,6 +1308,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                        mIntentExtras.getInt(INTENT_EXTRA_MATERIAL_PALETTE_SECONDARY_COLOR));
            }
            mPhotoId = mIntentExtras.getLong(INTENT_EXTRA_PHOTO_ID);
            mRawContactDisplayAloneIsReadOnly = mIntentExtras.getBoolean(
                    INTENT_EXTRA_RAW_CONTACT_DISPLAY_ALONE_IS_READ_ONLY);
        }
    }

@@ -1329,8 +1348,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            }
        }
        switch (saveMode) {
            case SaveMode.CLOSE:
            case SaveMode.COMPACT: {
            case SaveMode.CLOSE: {
                final Intent resultIntent;
                if (saveSucceeded && contactLookupUri != null) {
                    final Uri lookupUri = maybeConvertToLegacyLookupUri(
@@ -1345,6 +1363,12 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                if (mListener != null) mListener.onSaveFinished(resultIntent);
                break;
            }
            case SaveMode.COMPACT: {
                // It is already saved, so prevent it from being saved again
                mStatus = Status.CLOSING;
                if (mListener != null) mListener.onSaveFinished(/* resultIntent= */ null);
                break;
            }
            case SaveMode.RELOAD:
            case SaveMode.JOIN:
                if (saveSucceeded && contactLookupUri != null) {
+7 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.widget.ListPopupWindow;
import com.android.contacts.ContactSaveService;
import com.android.contacts.R;
import com.android.contacts.activities.ContactEditorActivity;
import com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
@@ -168,6 +169,8 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            return revert();
        } else if (item.getItemId() == R.id.menu_save && mRawContactIdToDisplayAlone != -1) {
            return super.save(SaveMode.COMPACT);
        }
        return super.onOptionsItemSelected(item);
    }
@@ -354,7 +357,7 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
    private void bindPhotoHandler(BaseRawContactEditorView editor, AccountType type,
            RawContactDeltaList state) {
        final int mode;
        final boolean showIsPrimaryOption;
        boolean showIsPrimaryOption;
        if (type.areContactsWritable()) {
            if (editor.hasSetPhoto()) {
                mode = PhotoActionPopup.Modes.WRITE_ABLE_PHOTO;
@@ -372,6 +375,9 @@ public class ContactEditorFragment extends ContactEditorBaseFragment implements
            editor.getPhotoEditor().setShowPrimary(false);
            return;
        }
        if (mRawContactIdToDisplayAlone != -1) {
            showIsPrimaryOption = false;
        }
        final PhotoHandler photoHandler = new PhotoHandler(mContext, editor, mode, state);
        editor.getPhotoEditor().setEditorListener(
                (PhotoHandler.PhotoEditorListener) photoHandler.getListener());
Loading