Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Support sections in RealmRecycler #129

Open
trimolesi opened this issue Oct 4, 2017 · 3 comments
Open

FR: Support sections in RealmRecycler #129

trimolesi opened this issue Oct 4, 2017 · 3 comments

Comments

@trimolesi
Copy link

trimolesi commented Oct 4, 2017

What do you want to achieve?

Support sections in Recycler View with RealmRecyclerViewAdapter.
I would like can add more than one header in a RealmRecyclerViewAdapter.

Example:

I have one list of items that I wanna separate by 2 sections.
The first will be the items added in a header with name "DAY" and the other items in a section header with name "ITEMS".

@CriseX
Copy link

CriseX commented Nov 18, 2017

The poorman's version of this is to create an unmanaged RealmList and add your sections as dummy items. Then set the item type accordingly when you implement the adapter. Though I haven't actually tested this but the concept should be workable.

Having said that, it is a rather hacky solution and the likely new problem that is then introduced is how to efficiently build this dummy list (and keep it up to date if you want to re-organize your sections).

Edit: if realm did support GROUP BY type operation doing this might become easier assuming such operation would have an API allowing access to the grouped items from its result. realm/realm-java#2309 (comment) (note: this does not exist, but it sure would be nice convenience to have)

@FarmaanElahi
Copy link

One other way is to use ItemDecoration in grouping the element and still use the existing RealmRecyclerViewAdapter

@aharish
Copy link
Contributor

aharish commented Jun 1, 2018

I had 4 sections, and the way I ended up implementing it was to have 4 different RealmResults and then combine them all by converting them to a List.

I added in strings for the headers and in my Adapter, I overrode getItemViewType() and returned 0 or 1 depending on if the element at the current position was an instance of String or something else.

This got too costly though. There was a visible delay when loading the Fragment, so I ended up removing the headers until I could think of a better implementation.

One good thing though, was that you could still have animations work when you used notifyItemRangeChanged(...) when you interacted with the data.

The other alternative (especially if you have a logical way) is to have just one RealmResult, and then sort it using a sufficient sorting algorithm into sectioned lists. Of course, then you would have to sort the data again if the RealmResult ends up changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants