I am currently combining Mike Penz Fastadapter with Android Room. The expandable model class needs to be implemented like this:
public class MyClass<Parent extends IItem & IExpandable,
SubItem extends IItem & ISubItem>
extends AbstractExpandableItem<MyClass<Parent, SubItem>, MyClass.ViewHolder, SubItem> {
I want to use the model also as a room entity. The first problem was easy to solve - I created a custom version of AbstractExpandableItem where the fields would be annoteted with @Ignore tags to not brake the code generation. A simpler implementation of Fastadapter worked just fine this way.
However, Room seems to have a problem with bounded type parameters for entities, as it throws these compile errors in the DAO implementation:
- Error:(40, 115) error: cannot find symbol class Parent
- Error:(40, 123) error: cannot find symbol class SubItem
My DAO is:
@Dao
public interface MyDAO {
@Query("Select * from Table")
LiveData<List<MyClass>> getAllStuff();
Unlike this guy, I could not solve my issues with an update - I put my Room gradle version on 1.1.1 and the error still happens.
The FastAdapter also offers the possibility to define a normal
Model
class, which can be a super simple POJO and aItem
class.This way you can have all your data definition in the model, which will not require any parent classes or implementations, and the
Item
which will do the UI binding.A simple example can be found in the sample application of the
FastAdapter
.Instead of an
ItemAdapter
you will use aModelAdapter
, and then you provide the logic on how your model converts to aItem
.This can be as simple as:
For this simple sample the model looks like:
And the item looks like this:
The full sample code can be found here: https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/ModelItemActivity.java#L51