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

Commit c2978a24 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Storing the widget item views in Widget holder, to avoid looks on every...

Merge "Storing the widget item views in Widget holder, to avoid looks on every bind/recycle" into ub-launcher3-calgary
parents b765b182 81259cd0
Loading
Loading
Loading
Loading
+11 −25
Original line number Diff line number Diff line
@@ -51,14 +51,13 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
    private static final String TAG = "WidgetsListAdapter";
    private static final boolean DEBUG = false;

    private Launcher mLauncher;
    private LayoutInflater mLayoutInflater;
    private final WidgetPreviewLoader mWidgetPreviewLoader;
    private final LayoutInflater mLayoutInflater;

    private WidgetsModel mWidgetsModel;
    private WidgetPreviewLoader mWidgetPreviewLoader;
    private final View.OnClickListener mIconClickListener;
    private final View.OnLongClickListener mIconLongClickListener;

    private View.OnClickListener mIconClickListener;
    private View.OnLongClickListener mIconLongClickListener;
    private WidgetsModel mWidgetsModel;

    private final int mIndent;

@@ -66,10 +65,10 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
            View.OnLongClickListener iconLongClickListener,
            Launcher launcher) {
        mLayoutInflater = launcher.getLayoutInflater();
        mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache();

        mIconClickListener = iconClickListener;
        mIconLongClickListener = iconLongClickListener;
        mLauncher = launcher;
        mIndent = launcher.getResources().getDimensionPixelSize(R.dimen.widget_section_indent);
    }

@@ -89,7 +88,7 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
    public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
        List<WidgetItem> infoList = mWidgetsModel.getSortedWidgets(pos);

        ViewGroup row = ((ViewGroup) holder.getContent().findViewById(R.id.widgets_cell_list));
        ViewGroup row = holder.cellContainer;
        if (DEBUG) {
            Log.d(TAG, String.format(
                    "onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]",
@@ -122,14 +121,9 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
        }

        // Bind the views in the application info section.
        PackageItemInfo infoOut = mWidgetsModel.getPackageItemInfo(pos);
        BubbleTextView tv = ((BubbleTextView) holder.getContent().findViewById(R.id.section));
        tv.applyFromPackageItemInfo(infoOut);
        holder.title.applyFromPackageItemInfo(mWidgetsModel.getPackageItemInfo(pos));

        // Bind the view in the widget horizontal tray region.
        if (getWidgetPreviewLoader() == null) {
            return;
        }
        for (int i=0; i < infoList.size(); i++) {
            WidgetCell widget = (WidgetCell) row.getChildAt(i);
            widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
@@ -162,10 +156,9 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {

    @Override
    public void onViewRecycled(WidgetsRowViewHolder holder) {
        ViewGroup row = ((ViewGroup) holder.getContent().findViewById(R.id.widgets_cell_list));

        for (int i = 0; i < row.getChildCount(); i++) {
            WidgetCell widget = (WidgetCell) row.getChildAt(i);
        int total = holder.cellContainer.getChildCount();
        for (int i = 0; i < total; i++) {
            WidgetCell widget = (WidgetCell) holder.cellContainer.getChildAt(i);
            widget.clear();
        }
    }
@@ -182,11 +175,4 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
    public long getItemId(int pos) {
        return pos;
    }

    private WidgetPreviewLoader getWidgetPreviewLoader() {
        if (mWidgetPreviewLoader == null) {
            mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache();
        }
        return mWidgetPreviewLoader;
    }
}
+9 −22
Original line number Diff line number Diff line
@@ -91,19 +91,14 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
    @Override
    public String scrollToPositionAtProgress(float touchFraction) {
        // Skip early if widgets are not bound.
        if (mWidgets == null) {
            return "";
        }

        // Skip early if there are no widgets.
        int rowCount = mWidgets.getPackageSize();
        if (rowCount == 0) {
        if (isModelNotReady()) {
            return "";
        }

        // Stop the scroller if it is scrolling
        stopScroll();

        int rowCount = mWidgets.getPackageSize();
        getCurScrollState(mScrollPosState, -1);
        float pos = rowCount * touchFraction;
        int availableScrollHeight = getAvailableScrollHeight(rowCount);
@@ -121,14 +116,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
    @Override
    public void onUpdateScrollbar(int dy) {
        // Skip early if widgets are not bound.
        if (mWidgets == null) {
            return;
        }

        // Skip early if there are no widgets.
        int rowCount = mWidgets.getPackageSize();
        if (rowCount == 0) {
            mScrollbar.setThumbOffset(-1, -1);
        if (isModelNotReady()) {
            return;
        }

@@ -139,7 +127,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
            return;
        }

        synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, rowCount);
        synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, mWidgets.getPackageSize());
    }

    /**
@@ -151,15 +139,10 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
        stateOut.itemPos = -1;

        // Skip early if widgets are not bound.
        if (mWidgets == null) {
        if (isModelNotReady()) {
            return;
        }

        // Return early if there are no items
        int rowCount = mWidgets.getPackageSize();
        if (rowCount == 0) {
            return;
        }
        View child = getChildAt(0);
        int position = getChildPosition(child);

@@ -178,4 +161,8 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
        View child = getChildAt(0);
        return child.getMeasuredHeight() * rowIndex;
    }

    private boolean isModelNotReady() {
        return mWidgets == null || mWidgets.getPackageSize() == 0;
    }
}
 No newline at end of file
+7 −5
Original line number Diff line number Diff line
@@ -18,16 +18,18 @@ package com.android.launcher3.widget;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.ViewGroup;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;

public class WidgetsRowViewHolder extends ViewHolder {

    ViewGroup mContent;
    public final ViewGroup cellContainer;
    public final BubbleTextView title;

    public WidgetsRowViewHolder(ViewGroup v) {
        super(v);
        mContent = v;
    }

    ViewGroup getContent() {
        return mContent;
        cellContainer = (ViewGroup) v.findViewById(R.id.widgets_cell_list);
        title = (BubbleTextView) v.findViewById(R.id.section);
    }
}