BaseAdapter for RecyclerView. Support MultiViewType,ItemAnimation,HeaderView, ParallaxHeaderView, LoadingView etc
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
library
sample
.gitignore
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

BaseRecyclerViewAdapter

This is a Fast and Flexible RecyclerView adapter, and is also my first library.

You can set up your adapter easily, and you can use multi item type support easily, and there are many item animations and some fast api to decorate your adapter, free and enjoy it!

DEMO

Download

Run on your device
Download apk

dependencies {
    compile 'com.yat3s.library:baseadapter:0.1.1'
}

Feature

  • HeaderView/ParallaxHeaderView
    You can easily to add header view or parallax header View.
  • MultiViewType
    You can ignore origin view type, and just one line to set multi view type.
  • LoadAnimation
    You needn't use recycler view itemAnimator and quick set item animation.
  • CustomAnimation
    Also you want set your custom animation is ok.
  • ItemClickListener
    You can set onItemClickListener easily.
  • LoadingView
    You can set loading view while still loading data.
  • EmptyView
    You can set empty view when data is empty.
  • SectionView
    //TODO But I dont have any idea to implement it.

Usage

public class MusicAdapter extends BaseAdapter<MusicModel> {
    public MusicAdapter(Context context) {
        super(context);
    }

    @Override
    protected void bindDataToItemView(BaseViewHolder holder, MusicModel item, int position) {
        holder.setText(R.id.name_tv, item.name)
                .setText(R.id.price_tv, "$ " + item.price)
                .setTextColorRes(R.id.price_tv, R.color.white);
        holder.getView(R.id.custom_view).setXXXX();
        
        if(isLargeMusicItem(position, item)) {
            // Do something
        }
    }

    @Override
    protected int getItemViewLayoutId(int position, MusicModel musicModel) {
        if (isLargeMusicItem(position, musicModel)) {
            return R.layout.item_music_large;
        }
        return R.layout.item_music_small;
    }

    private boolean isLargeMusicItem(int position, MusicModel musicModel) {
        return 0 == position % 3 && musicModel.price < 80;
    }
}

You need set mMusicAdapter.addFirstDataSet(dataList); if you set first data to your adapter. and usemMusicAdapter.addMoreDataSet(dataList);when your addd more data to your adapter

Features

  • Header View
mMusicAdapter.addHeaderViewResId(R.layout.layout_header);
  • Parallax Header View
mMusicAdapter.addParallaxHeaderViewLayoutResId(R.layout.layout_header, mRecyclerView);
  • ItemClickListener / HeaderViewClickListener
mMusicAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener<MusicModel>() {
            @Override
            public void onClick(View view, MusicModel car, int position) {
                Toast.makeText(MainActivity.this, "Click " + position + ":" + car.name, Toast.LENGTH_SHORT).show();
            }
        });
mMusicAdapter.setOnHeaderClickListener(new BaseAdapter.OnHeaderClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(MainActivity.this, "Click Header", Toast.LENGTH_SHORT).show();
        }
    });
  • ItemAnimation / CustomItemAnimation
mMusicAdapter.setItemAnimation(AnimationType.SCALE);
mMusicAdapter.setCustomItemAnimator(new BaseAdapter.CustomAnimator() {
            @Override
            public Animator getAnimator(View itemView) {
                return ObjectAnimator.ofFloat(itemView, "translationX", 0, 200);
            }
        });
  • LoadingView / EmptyView
mMusicAdapter.setLoadingView(yourLoadingView);
// if setShowLoadingViewIgnoreHeader(true) means when app is loading data, loading view will cover header;
mMusicAdapter.setShowLoadingViewIgnoreHeader(true);
mMusicAdapter.setEmptyView(yourEmptyView);
  • Other setting
// Item Animation duration
mMusicAdapter.setItemAnimationDuration(300);  
// if true, show item animation every time when you scroll recycler view.
mMusicAdapter.setShowItemAnimationEveryTime(true);  
mMusicAdapter.setItemAnimationInterpolator(new OvershootInterpolator());
// set parallax header scroll multiplier
mMusicAdapter.setScrollMultiplier(0.5f);
mMusicAdapter.setParallaxScrollListener(new BaseAdapter.OnParallaxScrollListener() {
    @Override
    public void onParallaxScroll(float percentage, float offset, View parallax) {
        // Do some thing such as hide toolbar
    }
});

Thanks

@kanytu
give me some idea about parallax header https://github.com/kanytu/android-parallax-recyclerview