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

Commit aebd28f7 authored by Adam Powell's avatar Adam Powell
Browse files

Fix bug 6048643 - verify ListView layoutparams while tracking stable IDs

Account for adapters that don't inflate item views using the ListView as
a parent.

Unify how AbsListView and subclasses generate layoutparams.

Change-Id: I963a5fcb4d98b721210a4d92d0db307f56acdf59
parent 38439390
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -2035,13 +2035,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            }

            child = mAdapter.getView(position, scrapView, this);
            if (mAdapterHasStableIds) {
                LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (lp == null) {
                    lp = (LayoutParams) generateDefaultLayoutParams();
                }
                lp.itemId = mAdapter.getItemId(position);
            }

            if (ViewDebug.TRACE_RECYCLER) {
                ViewDebug.trace(child, ViewDebug.RecyclerTraceType.BIND_VIEW,
@@ -2072,6 +2065,20 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            }
        }

        if (mAdapterHasStableIds) {
            final ViewGroup.LayoutParams vlp = child.getLayoutParams();
            LayoutParams lp;
            if (vlp == null) {
                lp = (LayoutParams) generateDefaultLayoutParams();
            } else if (!checkLayoutParams(vlp)) {
                lp = (LayoutParams) generateLayoutParams(vlp);
            } else {
                lp = (LayoutParams) vlp;
            }
            lp.itemId = mAdapter.getItemId(position);
            child.setLayoutParams(lp);
        }

        return child;
    }

@@ -5382,6 +5389,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

    @Override
    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    }

    @Override
    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
        return new LayoutParams(p);
+4 −6
Original line number Diff line number Diff line
@@ -1031,8 +1031,7 @@ public class GridView extends AbsListView {

            AbsListView.LayoutParams p = (AbsListView.LayoutParams) child.getLayoutParams();
            if (p == null) {
                p = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT, 0);
                p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
                child.setLayoutParams(p);
            }
            p.viewType = mAdapter.getItemViewType(0);
@@ -1364,8 +1363,7 @@ public class GridView extends AbsListView {
        // some up...
        AbsListView.LayoutParams p = (AbsListView.LayoutParams) child.getLayoutParams();
        if (p == null) {
            p = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 0);
            p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
        }
        p.viewType = mAdapter.getItemViewType(position);

+2 −4
Original line number Diff line number Diff line
@@ -1163,8 +1163,7 @@ public class ListView extends AbsListView {
    private void measureScrapChild(View child, int position, int widthMeasureSpec) {
        LayoutParams p = (LayoutParams) child.getLayoutParams();
        if (p == null) {
            p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 0);
            p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
            child.setLayoutParams(p);
        }
        p.viewType = mAdapter.getItemViewType(position);
@@ -1808,8 +1807,7 @@ public class ListView extends AbsListView {
        // noinspection unchecked
        AbsListView.LayoutParams p = (AbsListView.LayoutParams) child.getLayoutParams();
        if (p == null) {
            p = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, 0);
            p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
        }
        p.viewType = mAdapter.getItemViewType(position);