An Android library to create complex items easily in RecyclerView.
// androidx
implementation 'coffeepartner.complextype:complextype-androidx:1.0.0'// appcompat
implementation 'coffeepartner.complextype:complextype-appcompat:1.0.0'// Like Gson TypeFactory, build the providerComplexProviderprovider = newComplexProvider.Builder()
.registerHierarchyBinder(Person.class, newPersonViewBinder())
.registerBinderFactory(newViewBinderFactory() {
@SuppressWarnings("unchecked")
@Overridepublic <T, VextendsRecyclerView.ViewHolder> ViewBinder<T, V> create(ComplexProvidercontext, Class<? extendsT> clazz) {
if (clazz == Teacher.class) {
return (ViewBinder<T, V>) newDelegationTeacherViewBinder(context.nextViewBinder(this, Person.class));
} elseif (clazz == Parent.class) {
return (ViewBinder<T, V>) newDelegationParentViewBinder(context.nextViewBinder(this, Person.class));
}
returnnull;
}
})
.build();
// The Adapter with providerComplexAdapteradapter = newComplexAdapter(provider);
adapter.setItems(Arrays.asList(
newPerson("Bob", 25),
newTeacher("Nancy", 30, "English"),
newParent("Lucy", 28, newPerson[]{
newPerson("Zz", 3),
newPerson("Yy", 2)
})
));
RecyclerViewrv;
// set to RecyclerViewrv.setAdapter(adapter);More details, see example.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.