Generic Recycler Adapter

Generic adapters for Android based on https://github.com/MaximeJallu/RecyclerAdapter-Java

License

License

The Code Project Open License (CPOL) 1.02
GroupId

GroupId

com.github.maximejallu
ArtifactId

ArtifactId

adapters
Last Version

Last Version

1.10.6
Release Date

Release Date

Type

Type

aar
Description

Description

Generic Recycler Adapter
Generic adapters for Android based on https://github.com/MaximeJallu/RecyclerAdapter-Java
Project URL

Project URL

https://github.com/MaximeJallu/RecyclerAdapter-Java
Source Code Management

Source Code Management

https://github.com/MaximeJallu/RecyclerAdapter-Java

Download adapters

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.maximejallu/adapters/ -->
<dependency>
    <groupId>com.github.maximejallu</groupId>
    <artifactId>adapters</artifactId>
    <version>1.10.6</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.maximejallu/adapters/
implementation 'com.github.maximejallu:adapters:1.10.6'
// https://jarcasting.com/artifacts/com.github.maximejallu/adapters/
implementation ("com.github.maximejallu:adapters:1.10.6")
'com.github.maximejallu:adapters:aar:1.10.6'
<dependency org="com.github.maximejallu" name="adapters" rev="1.10.6">
  <artifact name="adapters" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.maximejallu', module='adapters', version='1.10.6')
)
libraryDependencies += "com.github.maximejallu" % "adapters" % "1.10.6"
[com.github.maximejallu/adapters "1.10.6"]

Dependencies

compile (2)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 26.0.2
com.android.support » design jar 26.0.2

Project Modules

There are no modules declared in this project.

Status

alt text API

Maven Central

Android Arsenal

Generic-Adapter:

This tool allows you to no longer worry about adapters. Now you will only create your ViewHolder. Communication management between your Views and your ViewHolders is possible. Creating sections is now very easily. Enjoy.

Download Maven Central

buildtool used is 27 use {exclude group: 'com.android.support'} only if you have problems

dependencies {
    ...
    implementation ('com.github.maximejallu:adapters:{version}')
    ...
}

Decorators for : ButterKnife - Picasso - Glide ...

public class SampleApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        RecyclerAdapter.Helper()
                .append(new InitViewHolderDecorator() {
                    @Override
                    public void initBinding(Object target, View view) {
                        ButterKnife.bind(target, view);
                    }
                })
                .append(new ShowPictureDecorator() {
                    @Override
                    public void showPicture(ImageView picture, String url) {
                        //use Picasso, Glide... Other
                    }
                })
                .init();
    }
}

RecyclerAdapter (Easy sample method)

CustomerViewHolder.class :

@BindLayoutRes(R.layout.{name_of_your_layout})
public class CustomerViewHolder extends RecyclerViewHolder<Customer> {
    TextView mText;
    CustomerViewHolder(View view){
        super(view);
        mText = view.findViewById(R.id.text1);
    }
    
    void onBind(Customer item){
        //todo implements
    }
}

MainFragment.class

public class MainFragment extends Fragment {
...
private RecyclerAdapter<Customer> mAdapter;

void onCreate(...){
    mAdapter = new RecyclerAdapter(customerList, CustomerViewHolder.class);
}
...
}

RecyclerAdapter (Multi cell method)

  • create your necessary ViewHolder (here only one example)
@BindLayoutRes(R.layout.{name_of_your_layout1})
public class CustomerViewHolder1 extends RecyclerViewHolder<Customer> {
    CustomerViewHolder1(View view){
        super(view);
    }
    
    void onBind(Customer item){
        //todo implements
    }
}

//# Solution 1 : the object determines are own item view type 
public class Customer implements IViewType {
   public static final int TYPE_ON_LINE = 0; /*default*/
   public static final int TYPE_STORE = 1;
   public static final int TYPE_OTHER = 2;
   private int mType;
   
   @Override
    public int getItemViewType() {
        return mType;
    }
}

public class MyFragment extends Fragment {
    
    public void onCreateView(){
        private RecyclerAdapter<Customer> mAdapter;
        
        mAdapter = new RecyclerAdapter(customerList, CustomerViewHolder1.class/*type par default*/);
        mAdapter.putViewType(Customer.TYPE_STORE, CustomerViewHolder2.class, null /*callback*/);
        mAdapter.putViewType(Customer.TYPE_OTHER, CustomerViewHolder3.class, true /*add default callback*/);
        
        //# Solution 2 : We give the strategy of the IViewType to our adapt it
        mAdapter.setItemViewType(item -> {
            //todo stategy type of item
            return 0;
        });
        mRecyclerView.setAdapter(adapter);
    }

}

SectionDecorator (Recycler with LinearLayout or GridLayout)

precondition : create your RecyclerViewHolder Sample :

mRecylerView.setLayoutManager(...);
/*create Adapter*/
RecyclerAdapter<Customer> baseAdapter = new RecyclerAdapter<>(...);
/*create sectioned adapter. the Adapter type can be RecyclerView.Adapter*/
SectionedAdapter<String, RecyclerAdapter> adapter = new SectionedAdapter<>(SectionViewHolder.class, baseAdapter);
/*add your sections*/
sectionAdapter.addSection(0/*position*/, "Title Section 1");
/*attach Adapter to RecyclerView*/
mRecylerView.setAdapter(sectionAdapter);

ItemDecoration

mRecyclerView.addItemDecoration(new FooterDecoration(getContext(), this, R.layout.item_space_80));

Versions

Version
1.10.6
1.10.5
1.10.4
1.10.3
1.10.2
1.10.1
1.9
1.8
1.7
1.6
1.5
1.1.2
1.1.1
rootProject.ext.versionCode