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

Commit 9a554fc3 authored by James Laskey's avatar James Laskey Committed by android-build-merger
Browse files

Fix rotation losing track of new group creation. am: b2d2e421

am: b893104d

Change-Id: Icb2c80e51af5635026e3c21d546834af0fc46cf0
parents 530369bb b893104d
Loading
Loading
Loading
Loading
+28 −17
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.contacts.editor;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
@@ -161,6 +162,18 @@ public class GroupMembershipView extends LinearLayout
    private boolean mDefaultGroupVisibilityKnown;
    private boolean mDefaultGroupVisible;
    private boolean mCreatedNewGroup;
    private GroupNameEditDialogFragment mGroupNameEditDialogFragment;
    private GroupNameEditDialogFragment.Listener mListener =
            new GroupNameEditDialogFragment.Listener() {
                @Override
                public void onGroupNameEditCancelled() {
                }

                @Override
                public void onGroupNameEditCompleted(String name) {
                    mCreatedNewGroup = true;
                }
            };

    private String mNoGroupString;
    private int mPrimaryTextColor;
@@ -185,6 +198,15 @@ public class GroupMembershipView extends LinearLayout
        setFocusableInTouchMode(true);
    }

    private void setGroupNameEditDialogFragment() {
        final FragmentManager fragmentManager = ((Activity) getContext()).getFragmentManager();
        mGroupNameEditDialogFragment = (GroupNameEditDialogFragment)
                fragmentManager.findFragmentByTag(TAG_CREATE_GROUP_FRAGMENT);
        if (mGroupNameEditDialogFragment != null) {
            mGroupNameEditDialogFragment.setListener(mListener);
        }
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
@@ -240,6 +262,7 @@ public class GroupMembershipView extends LinearLayout
        mDefaultGroupVisibilityKnown = false;
        mCreatedNewGroup = false;
        updateView();
        setGroupNameEditDialogFragment();
    }

    private void updateView() {
@@ -453,24 +476,12 @@ public class GroupMembershipView extends LinearLayout
    private void createNewGroup() {
        UiClosables.closeQuietly(mPopup);
        mPopup = null;

        final GroupNameEditDialogFragment dialog =
        mGroupNameEditDialogFragment =
                    GroupNameEditDialogFragment.newInstanceForCreation(
                            new AccountWithDataSet(mAccountName, mAccountType, mDataSet), null);

        // If the device is rotated after the dialog is shown, the listener will become null,
        // so that the popup from GroupMembershipView will not be shown.
        dialog.setListener(new GroupNameEditDialogFragment.Listener() {
            @Override
            public void onGroupNameEditStarted(String groupName) {
                mCreatedNewGroup = true;
            }
            @Override
            public void onGroupNameEditCancelled() { }
        });
        dialog.show(
        mGroupNameEditDialogFragment.setListener(mListener);
        mGroupNameEditDialogFragment.show(
                ((Activity) getContext()).getFragmentManager(),
                TAG_CREATE_GROUP_FRAGMENT);
    }

}
+5 −4
Original line number Diff line number Diff line
@@ -67,15 +67,15 @@ public final class GroupNameEditDialogFragment extends DialogFragment implements

    /** Callbacks for hosts of the {@link GroupNameEditDialogFragment}. */
    public interface Listener {
        void onGroupNameEditStarted(String name);
        void onGroupNameEditCancelled();
        void onGroupNameEditCompleted(String name);

        public static final Listener None = new Listener() {
            @Override
            public void onGroupNameEditStarted(String name) { }
            public void onGroupNameEditCancelled() { }

            @Override
            public void onGroupNameEditCancelled() { }
            public void onGroupNameEditCompleted(String name) { }
        };
    }

@@ -126,6 +126,7 @@ public final class GroupNameEditDialogFragment extends DialogFragment implements
        } else {
            mGroupName = savedInstanceState.getString(ARG_GROUP_NAME);
        }

        mGroupId = args.getLong(ARG_GROUP_ID, NO_GROUP_ID);
        mIsInsert = args.getBoolean(ARG_IS_INSERT, true);
        mAccount = getArguments().getParcelable(ARG_ACCOUNT);
@@ -252,7 +253,7 @@ public final class GroupNameEditDialogFragment extends DialogFragment implements
                    name, getActivity().getClass(), callbackAction);
        }
        ContactSaveService.startService(getActivity(), serviceIntent);
        getListener().onGroupNameEditStarted(name);
        getListener().onGroupNameEditCompleted(mGroupName);
        dismiss();
    }