GithubHelp home page GithubHelp logo

243787656 / recyclerviewutils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adammc331/recyclerviewutils

0.0 2.0 1.0 106 KB

Core utility classes for repetitive RecyclerView work.

License: MIT License

Java 100.00%

recyclerviewutils's Introduction

Android Arsenal

RecyclerViewUtils Library

This library contains a few core classes that are often used alongside a RecyclerView, and are intended to remove some of the tedious boilerplate code from being written many times.

Usage

To have access to the library, add the dependency to your build.gradle:

	compile 'com.adammcneilly:recyclerviewutils:1.0.0'

CoreViewHolder

At the heart of these classes is CoreViewHolder which is a RecyclerView.ViewHolder class used to display an object of a specific type. It has one abstract method for binding an object of that type.

Below is a sample of a CoreViewHolder for Account objects:

public class AccountViewHolder extends CoreViewHolder<Account> {
    private TextView tvName;
    private TextView tvBalance;

    public AccountViewHolder(View view) {
        super(view);

        this.tvName = (TextView) view.findViewById(R.id.account_name);
        this.tvBalance = (TextView) view.findViewById(R.id.account_balance);
    }

    @Override
    protected void bindItem(Account item) {
        this.tvName.setText(item.getName());
        this.tvBalance.setText(String.valueOf(item.getBalance()));
    }
}

CoreRecyclerViewAdapter

Using the CoreViewHolder class from above, the CoreRecyclerViewAdapter is an abstract base class for using an adapter of objects with a given type. By using a generic type, we were able to override many boilerplate methods such as:

  • add
  • remove
  • swapItems
  • onBindViewHolder

Thanks to this handy utils class, it cuts down on a ton of boilerplate code inside your adapter, and makes it very simple:

public class AccountAdapter extends CoreRecyclerViewAdapter<Account, AccountAdapter.AccountViewHolder>{
    public AccountAdapter(Context context, List<Account> accounts) {
        super(context, accounts);
    }

    @Override
    public AccountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AccountViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item_account, parent, false));
    }

    public class AccountViewHolder extends CoreViewHolder<Account> {
        ...
    }
}

CoreDividerItemDecoration

The CoreDividerItemDecoration class is used to display a simple line divider between list items in your RecyclerView.

Credits & Contact

This library was created by Adam McNeilly.

And reviewed by Maurício Pessoa.

License

The RecyclerViewUtils library is available under the MIT License. You are free to modify and enhance it in any way. If you submit a pull request, please add your name into the credits section! :)

recyclerviewutils's People

Contributors

adammc331 avatar mauker1 avatar

Watchers

James Cloos avatar  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.