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

Commit 3bbd9a0c authored by Katherine Kuan's avatar Katherine Kuan
Browse files

Fix NPE on tablet contact card with social updates

- In tablet portrait, instead of having 3 fragments
on screen (2 fragments for the view pager and
1 detail fragment for contact with no updates), just
have 2 fragments where the view pager adapter has
count = 1 when there are no updates (which disables
the swipe).

- Store whether or not the contact has updates in
the save instance state bundle so it can be
restored in onCreate()

- Set retain instance = true for the ContactLoaderFragment

- There should always be a ContactDetailFragment and
ContactDetailUpdatesFragment after onCreate() of the
PeopleActivity on the tablet

- Basically apply similar logic from the phone CL:
https://android-git.corp.google.com/g/#change,125585

- TODO: Take out duplicated code from ContactDetailLayoutController
and ContactDetailActivity

Bug: 5106878
Bug: 5082871

Change-Id: I3af08bf84072d3d94e4f3a6bc1d01faf3432e3e7
parent db0d8669
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

<!--
  Two-column layout for a contact with social updates. If the contact does not
  have social updates, then the second fragment view will just be hidden.
  have social updates, then the second fragment container will just be hidden.
-->

<LinearLayout
@@ -26,14 +26,24 @@
    android:scrollbars="none"
    android:orientation="horizontal">

    <fragment class="com.android.contacts.detail.ContactDetailFragment"
        android:id="@+id/about_fragment"
    <!--
      Container for the "About" fragment on the contact card for a contact
      with social updates. This view ID must match with a view ID in the layout
      that is used after an orientation change.
    -->
    <FrameLayout
        android:id="@+id/about_fragment_container"
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <fragment class="com.android.contacts.detail.ContactDetailUpdatesFragment"
        android:id="@+id/updates_fragment"
    <!--
      Container for the "Updates" fragment on the contact card for a contact
      with social updates. This view ID must match with a view ID in the layout
      that is used after an orientation change.
    -->
    <FrameLayout
        android:id="@+id/updates_fragment_container"
        android:layout_width="306dip"
        android:layout_height="match_parent" />

+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@

            <!-- This layout includes all possible views needed for a contact detail page -->
            <include
                android:id="@+id/contact_detail_container"
                layout="@layout/contact_detail_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
+2 −7
Original line number Diff line number Diff line
@@ -43,12 +43,7 @@
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <fragment
        android:id="@+id/contact_detail_fragment"
        class="com.android.contacts.detail.ContactDetailFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
        android:layout_height="wrap_content"
        android:visibility="gone"/>

</RelativeLayout>
 No newline at end of file
+0 −7
Original line number Diff line number Diff line
@@ -75,8 +75,6 @@ public class ContactDetailActivity extends ContactsActivity {

    private static final String KEY_CONTACT_HAS_UPDATES = "contactHasUpdates";
    private static final String KEY_CURRENT_PAGE_INDEX = "currentPageIndex";
    private static final String KEY_DETAIL_FRAGMENT_TAG = "detailFragTag";
    private static final String KEY_UPDATES_FRAGMENT_TAG = "updatesFragTag";

    public static final int FRAGMENT_COUNT = 2;

@@ -273,11 +271,6 @@ public class ContactDetailActivity extends ContactsActivity {
        super.onSaveInstanceState(outState);
        outState.putBoolean(KEY_CONTACT_HAS_UPDATES, mContactHasUpdates);
        outState.putInt(KEY_CURRENT_PAGE_INDEX, getCurrentPage());
        if (mViewPager != null) {
            outState.putString(KEY_DETAIL_FRAGMENT_TAG, mDetailFragment.getTag());
            outState.putString(KEY_UPDATES_FRAGMENT_TAG, mUpdatesFragment.getTag());
            return;
        }
    }

    private final ContactLoaderFragmentListener mLoaderFragmentListener =
+7 −25
Original line number Diff line number Diff line
@@ -122,8 +122,6 @@ public class PeopleActivity extends ContactsActivity

    private ContactDetailFragment mContactDetailFragment;
    private ContactDetailUpdatesFragment mContactDetailUpdatesFragment;
    private final ContactDetailFragmentListener mContactDetailFragmentListener =
            new ContactDetailFragmentListener();

    private ContactLoaderFragment mContactDetailLoaderFragment;
    private final ContactDetailLoaderFragmentListener mContactDetailLoaderFragmentListener =
@@ -226,7 +224,6 @@ public class PeopleActivity extends ContactsActivity
    public void onAttachFragment(Fragment fragment) {
        if (fragment instanceof ContactDetailFragment) {
            mContactDetailFragment = (ContactDetailFragment) fragment;
            mContactDetailFragment.setListener(mContactDetailFragmentListener);
        } else if (fragment instanceof ContactDetailUpdatesFragment) {
            mContactDetailUpdatesFragment = (ContactDetailUpdatesFragment) fragment;
        } else if (fragment instanceof ContactsUnavailableFragment) {
@@ -379,21 +376,21 @@ public class PeopleActivity extends ContactsActivity

            mContactDetailLoaderFragment = getFragment(R.id.contact_detail_loader_fragment);
            mContactDetailLoaderFragment.setListener(mContactDetailLoaderFragmentListener);
            mContactDetailLoaderFragment.setRetainInstance(true);

            mGroupDetailFragment = getFragment(R.id.group_detail_fragment);
            mGroupDetailFragment.setListener(mGroupDetailFragmentListener);
            mGroupDetailFragment.setQuickContact(true);

            if (mContactDetailFragment != null) {
                transaction.hide(mContactDetailFragment);
            }
            transaction.hide(mGroupDetailFragment);

            // Configure contact details
            ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
            ContactDetailTabCarousel tabCarousel = (ContactDetailTabCarousel)
                    findViewById(R.id.tab_carousel);
            mContactDetailLayoutController = new ContactDetailLayoutController(
                    getFragmentManager(), viewPager, tabCarousel,
                    mContactDetailFragmentListener);
            mContactDetailLayoutController = new ContactDetailLayoutController(this, savedState,
                    getFragmentManager(), findViewById(R.id.contact_detail_container),
                    new ContactDetailFragmentListener());
        }
        transaction.commit();
        fragmentManager.executePendingTransactions();
@@ -1066,13 +1063,6 @@ public class PeopleActivity extends ContactsActivity
                    if (isFinishing()) {
                        return;
                    }
                    if (!mContactDetailLayoutController.isInitialized()) {
                        mContactDetailLayoutController.setContactDetailFragment(
                                mContactDetailFragment);
                        mContactDetailLayoutController.setContactDetailUpdatesFragment(
                                mContactDetailUpdatesFragment);
                        mContactDetailLayoutController.initialize();
                    }
                    mContactDetailLayoutController.setContactData(result);
                }
            });
@@ -1569,14 +1559,6 @@ public class PeopleActivity extends ContactsActivity
        mActionBarAdapter.setListener(null);
    }

    @Override
    protected void onRestoreInstanceState(Bundle inState) {
        super.onRestoreInstanceState(inState);
        if (mContactDetailLayoutController != null) {
            mContactDetailLayoutController.onRestoreInstanceState(inState);
        }
    }

    @Override
    public DialogManager getDialogManager() {
        return mDialogManager;
Loading