Skip to content
This repository was archived by the owner on Mar 26, 2019. It is now read-only.
This repository was archived by the owner on Mar 26, 2019. It is now read-only.

Item order not respected when using SpanSize width = number of columns #39

@DennyWeinberg

Description

@DennyWeinberg

I have the following code to collect my items to show in my RV:

    // Spanned
    public RecyclerView.LayoutManager getLayoutManager() {
        if (!mMainView || mDataHolder.getViewMode(mActivity).equals("grid")) { // We force the grid view in subset
            final Integer numColumns = UserPreferencesHandler.<Integer>readValue(mActivity, UserPreferencesHandler.PREF_KEY_NUM_COLUMNS);

            SpannedGridLayoutManager layoutManager = new SpannedGridLayoutManager(SpannedGridLayoutManager.Orientation.VERTICAL, numColumns);
            layoutManager.setSpanSizeLookup(new SpannedGridLayoutManager.SpanSizeLookup(position -> {
                try {
                    switch (RVAdapterTimeline.this.getItemViewType(position)) {
                        case RVAdapter.VIEW_TYPE_HEADER:
                            try {
                                return new SpanSize(numColumns, 1);
                            } catch (ClassCastException e) {
                                return new SpanSize(1, 1);
                            }
                        default:
                            LineItem lineitem = mItems.get(position);
                            if (lineitem != null && lineitem.mediaItem != null && lineitem.mediaItem.getRating() != null && lineitem.mediaItem.getRating() == 5) {
                                return new SpanSize(2, 2);
                            }

                            return new SpanSize(1, 1);
                    }
                } catch (IndexOutOfBoundsException e) {
                    MyApplication.toastSomething(mActivity, e); // Seen on firebase
                    return new SpanSize(1, 1);
                }
            }));

            return layoutManager;
        } else {
            return new LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false);
        }
    }

There are header items with a full column span:
return new SpanSize(numColumns, 1);
Other items are with span width 2 or 2. The number of columns is 5.

After collecting the items, they are used for the RV adapter. The problem is that the order in the rendered RV is not the same as the items. Result:
Pic

Could you please fix that? I can confirm 100% that the default GridLayoutManager is working with these items.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions