Giter Club home page Giter Club logo

superrecyclerview's Introduction

Super RecyclerView

Download Build Status

Super RecyclerView is a library that helps to use RecyclerView adapter without code, just using annotations on your class, creating Collection of that class and creating Adapter that parametrize that class, and its all.

Features

  • No adapter code required
  • Click and Long Click events
  • View element filter/hide
  • Single view click events
  • Data events (new, remove and replace single and all data)
  • Animations, single animation listener

You can know how it works if you see the code, all it's on SuperRecyclerAdapter file

For more functions or bugs, create a issue.

Usage

Step 1:

Add gradle dependecy

dependencies {
  compile 'com.nicolkill:superrecyclerview:{latest_release}'
}

Step 2:

Use the LayoutResource annotation in your class and BindField of the method that you want bind:

@LayoutResource(R.layout.row)
public class Option {

    private int mOptionNumber;

    public Option(int number) {
        mOptionNumber = number;
    }

    @BindField(id = R.id.option_name)
    public String getOptionName() {
        return "Option " + (mOptionNumber + 1);
    }

    @BindField(type = BindField.Type.IMAGE, id = R.id.option_logo)
    public String getOptionImage(Context context) {
        return "https://dummyimage.com/200x200/" +
                Integer.toHexString(context.getResources().getColor(R.color.colorPrimary)) +
                "/ffffff.png&text=" + (mOptionNumber + 1);
    }

}

Step 3:

Create the adapter:

ArrayList<Option> options = new ArrayList<>();
SuperRecyclerAdapter<Option> adapter = new SuperRecyclerAdapter<>(options);

Step 4:

Customize the adapter with the functions and listeners that you want

// click
adapter.setOnClickListener(new ClickListener<Option>() {
    @Override
    public void onItemSelected(View view, int position, Option element) {
        Snackbar.make(view, "Click option selected: " + element.getOptionName(), Snackbar.LENGTH_SHORT).show();
    }
});

// long click
adapter.setOnLongClickListener(new LongClickListener<Option>() {
    @Override
    public void onLongClickItemSelected(View view, int position, Option element) {
        Snackbar.make(view, "Long Click ppt
#### [Add slides:][Intro Activity]ion selected: " + element.getOptionName(), Snackbar.LENGTH_SHORT).show();
    }
});

// data listener
adapter.addOnDataChangeListener(new OnDataChangeListener<Option>() {
    @Override
    public void onDataAdded(List<Option> objects) {
        Log.e(TAG, "New data is added: " + objects.toString());
    }

    @Override
    public void onDataRemoved(List<Option> last) {
        Log.e(TAG, "Data is removed: " + last.toString());
    }

    @Override
    public void onSimpleDataAdded(Option object) {
        Log.e(TAG, "Individual data is added: " + object.getOptionName());
    }

    @Override
    public void onSimpleDataRemoved(Option object) {
        Log.e(TAG, "Individual data is removed: " + object.getOptionName());
    }

    @Override
    public void onSimpleDataReplaced(Option object, Option last) {
        Log.e(TAG, "Data replaced new: " + object.getOptionName() + ", last: " + last.getOptionName());
    }
});

// view functions
adapter.addClickOnViewListener(R.id.option_logo, new ViewClickListener<Option>() {
    @Override
    public void onViewClick(View view, int position, Option element) {
        Snackbar.make(view, "Click on logo of option selected: " + element.getOptionName(), Snackbar.LENGTH_SHORT)
                .show();
    }
});
adapter.addFilterApplicator(new FilterApplicator() {
    @Override
    public boolean canApplyFilter(int position) {
        if (position % 2 == 0) {
            return true;
        }
        return false;
    }
});
adapter.addFilterToView(R.id.option_name, R.color.colorAccent);

// view animations
adapter.setItemLayoutAnimation(R.anim.slide_in_right);
adapter.setItemsAnimationListener(new ItemsAnimationListener() {
    @Override
    public void onAnimationStart() {
        Log.e(TAG, "Animation start!");
    }

    @Override
    public void onAnimationEnd() {
        Log.e(TAG, "Animation end!");
    }

    @Override
    public void onAnimationConfigure(Animation animation, int position) {
        // You can configure animation of any element
    }
});
adapter.disableAnimationOnEnd();

superrecyclerview's People

Contributors

aliwaris0572 avatar nicolkill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.