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

Commit e9a33cef authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Fixing crash in All Apps." into ub-launcher3-burnaby

parents 2a53cb7a 3857d7ae
Loading
Loading
Loading
Loading
+45 −30
Original line number Diff line number Diff line
@@ -33,13 +33,13 @@ class AppsGridAdapter extends RecyclerView.Adapter<AppsGridAdapter.ViewHolder> {
     */
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public View mContent;
        public boolean mIsSectionRow;
        public boolean mIsSectionHeader;
        public boolean mIsEmptyRow;

        public ViewHolder(View v, boolean isSectionRow, boolean isEmptyRow) {
        public ViewHolder(View v, boolean isSectionHeader, boolean isEmptyRow) {
            super(v);
            mContent = v;
            mIsSectionRow = isSectionRow;
            mIsSectionHeader = isSectionHeader;
            mIsEmptyRow = isEmptyRow;
        }
    }
@@ -72,18 +72,10 @@ class AppsGridAdapter extends RecyclerView.Adapter<AppsGridAdapter.ViewHolder> {
        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
            if (items.isEmpty()) {
                return;
            }

            for (int i = 0; i < parent.getChildCount(); i++) {
                View child = parent.getChildAt(i);
                ViewHolder holder = (ViewHolder) parent.getChildViewHolder(child);
                if (holder != null) {
                    GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams)
                            child.getLayoutParams();
                    if (!holder.mIsSectionRow && !holder.mIsEmptyRow && !lp.isItemRemoved()) {
                        if (items.get(holder.getPosition() - 1).isSectionHeader) {
                if (shouldDrawItemSection(holder, child, items)) {
                    // Draw at the parent
                    AlphabeticalAppsList.AdapterItem item =
                            items.get(holder.getPosition());
@@ -104,14 +96,37 @@ class AppsGridAdapter extends RecyclerView.Adapter<AppsGridAdapter.ViewHolder> {
                }
            }
        }
            }
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                RecyclerView.State state) {
            // Do nothing
        }

        private boolean shouldDrawItemSection(ViewHolder holder, View child,
                List<AlphabeticalAppsList.AdapterItem> items) {
            // Ensure item is not already removed
            GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams)
                    child.getLayoutParams();
            if (lp.isItemRemoved()) {
                return false;
            }
            // Ensure we have a valid holder
            if (holder == null) {
                return false;
            }
            // Ensure it's not an empty row
            if (holder.mIsEmptyRow) {
                return false;
            }
            // Ensure we have a holder position
            int pos = holder.getPosition();
            if (pos <= 0 || pos >= items.size()) {
                return false;
            }
            // Only draw the first item in the section (the first one after the section header)
            return items.get(pos - 1).isSectionHeader && !items.get(pos).isSectionHeader;
        }
    }

    private LayoutInflater mLayoutInflater;