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

Commit c51f6eea authored by Brian Attwell's avatar Brian Attwell
Browse files

Apply card padding when fragment becomes unhidden

Part 2/2. See ag/535716 for part 1.

Bug: 17303217
Bug: 17135027
Change-Id: I38bb34a6a1e52403aaf47bef91148378653acc92
parent 0147c3ba
Loading
Loading
Loading
Loading
+11 −26
Original line number Diff line number Diff line
@@ -93,34 +93,19 @@ public class ContactTileListFragment extends Fragment {

        mListView.setItemsCanFocus(true);
        mListView.setAdapter(mAdapter);
        ContactListViewUtils.applyCardPaddingToView(getResources(), mListView, listLayout);

        // Set a padding on the list view so it appears in the center of the card
        // in the layout if required.
        Resources resources = getResources();
        final int listSpaceWeight = resources.getInteger(
                R.integer.contact_list_space_layout_weight);
        final int listViewWeight = resources.getInteger(
                R.integer.contact_list_card_layout_weight);
        if (listSpaceWeight > 0 && listViewWeight > 0) {
            listLayout.setBackgroundResource(0);
            // Set the card view visible
            View mCardView = listLayout.findViewById(R.id.list_card);
            if (mCardView == null) {
                throw new RuntimeException(
                        "Your content must have a list card view who can be turned visible " +
                        "whenever it is necessary.");
        return listLayout;
    }
            mCardView.setVisibility(View.VISIBLE);
            // Add extra padding to the list view to make them appear in the center of the card.
            SchedulingUtils.doOnPreDraw(mListView, true, new Runnable() {

    @Override
                        public void run() {
                    ContactListViewUtils.addPaddingToView(
                            mListView, listSpaceWeight, listViewWeight);
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (getActivity() != null && getView() != null && !hidden) {
            // If the padding was last applied when in a hidden state, it may have been applied
            // incorrectly. Therefore we need to reapply it.
            ContactListViewUtils.applyCardPaddingToView(getResources(), mListView, getView());
        }
                    });
        }
        return listLayout;
    }

    @Override