https://kotlinlang.org logo
#splitties
Title
# splitties
n

nickk

08/13/2019, 11:44 AM
How would you go about supporting more than one cell type in RecyclerView? I would like to implement a data-driven approach that draws a different view according to what the current item of a list specifies.
l

louiscad

08/13/2019, 11:49 AM
Multiple ways. Manual way. Or using one of these libraries (unordered): - Epoxy (from Airbnb) - Groupie (from LisaWray) - RecylerView delegates AdapterDelegates (no ambiguity)
n

nickk

08/13/2019, 12:08 PM
What do you mean “no ambiguity”?
l

louiscad

08/13/2019, 12:54 PM
I didn't remember the name of the author, but RecyclerView is easier to Google that common words like epoxy and groupie which have non technical meanings before being library names
n

nickk

08/13/2019, 12:55 PM
Well, Groupie seems very nice… I guess creating the views with Splitties DSL is straight forward.
l

louiscad

08/13/2019, 12:57 PM
BTW, the author is looking for maintainers: https://twitter.com/lisawrayz/status/1160981822529892352
n

nickk

08/13/2019, 12:59 PM
I like that it doesn’t impose on you to use custom Annotations, like Epoxy does.
l

louiscad

08/13/2019, 1:01 PM
Ah yes, also it won't slow your build down because of kapt 🙂
n

nickk

08/13/2019, 1:02 PM
BTW, I did not spot the 3rd lib (there is some ambiguity, after all 😉 )
l

louiscad

08/13/2019, 1:02 PM
It's because I was wrong on the name. It's "AdapterDelegates": https://github.com/sockeqwe/AdapterDelegates
👍 1
n

nickk

08/13/2019, 1:20 PM
Well, the
getLayout()
method in Groupie returns a LayoutRes, which is then inflated… I see no place to hook a view generated by Splitties DSL.
Copy code
// GroupAdapter.Java: 170
    @Override
    @NonNull
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        Item<VH> item = getItemForViewType(viewType);
        View itemView = inflater.inflate(item.getLayout(), parent, false);
        return item.createViewHolder(itemView);
    }
l

louiscad

08/13/2019, 1:36 PM
Should I respond "Me!" to Lisa and add the feature?
n

nickk

08/13/2019, 1:37 PM
Well I guess we need a
getView()
alternative to
getLayout()
l

louiscad

08/13/2019, 1:45 PM
I'd start by forking and try to add it, or opening an issue.
n

nickk

08/13/2019, 1:47 PM
OK. I’ll create a fork. I guess they will appreciate a PR more than opening an issue.
l

louiscad

08/13/2019, 2:04 PM
Probably 🙂 I'll be happy to review it if you want.
n

nickk

08/13/2019, 2:07 PM
Hmm… This I do not like: “The Item class gives you simple callbacks to bind your model object to the generated fields. Because of Kotlin Android extensions, there’s no need to write a view holder.” Without an XML layout, we will have to manually code the ViewHolder. Or am I missing something?
l

louiscad

08/13/2019, 2:10 PM
Nope, you only need the type of your View, and you'll have all the properties. FYI, I made a Splitties module to have
ViewHolder
be generic and keep the type of the passed `View`: https://github.com/LouisCAD/Splitties/tree/master/modules/typesaferecyclerview
2 Views