Git Product home page Git Product logo

android_multicolumn_recyclerview's Introduction

android_multicolumn_recyclerview

A simple multi column recyclerview supporting column count modification

use with Gradle

Install the dependency into your project using

dependencies {
  compile 'eu.codlab:android_multicolumn_adaptable:1.8'
}

Declare in your layout

    <eu.codlab.recyclercolumnadaptable.RecyclerColumnsWithContentView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:columns="5"
        app:columnsVisibleExpanded="3"/>

Customize the number of columns shown in expanded mode with:

app:columns="integer"

Default value : 3

And the number of columns displayed when the content is expanded

app:columnsVisibleExpanded="integer"

Default value : 1

Usage

  • register a listener for events
mGrid.setRecyclerColumnsListener(IRecyclerColumnsListener listener)
  • Set the adapter simply by calling
mGrid.setRecyclerAdapter(AbstractItemInflater inflater)
  • expand the content using the expand method
mGrid.showContent();

or

mGrid.showContent(int position_from_an_AbstractItem);

Example :

    @Override
    public void onBindViewHolder(final ColumnsNewItemHolder holder) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this,
                        "Click on " + holder.getItem().getPosition(),
                        Toast.LENGTH_SHORT).show();

                _grid.showContent(holder.getItem().getPosition());
            }
        });
    }
  • collapse the content using the collapse method
mGrid.hideContent();
  • set a custom ItemDecoration to the grid using
mGrid.addItemDecoration(ItemDecoration item_decoration)

Declare an inflater

To create a new Adapter for the grid, you must instantiate a MainArrayAdapter object. The instantiation method helper takes an AbstractItemInflater interface instance and a parent RecyclerColumnsWithContentView

The interface signature is declared as :

public interface AbstractItemInflater<T extends ColumnItemHolder> {
    /**
     * Called from the array adapter with the ColumnItemHolder to create
     *
     * @param parent the parent view
     * @return an instance of ColumnItemHolder with the proper data default data binded
     */
    @NonNull
    T onCreateViewHolder(@NonNull ViewGroup parent);

    /**
     * Set the data for a displayed / managed holder containing an AbstractItem
     * <p/>
     * Each holder will provide an **AbstractItem** which contains getPosition()
     * the getPosition() >= 0 will give a value into the provider's list of real items
     * it is safe to call a get on the provider's internal list of items from this value
     * <p/>
     * for now, returning -1 means that the object was unintialized
     *
     * @param holder the holder to manage
     */
    void onBindViewHolder(@NonNull T holder);

    /**
     * The number of items
     *
     * @return the number of item managed by the provider
     */
    int getItemCount();

    /**
     * Retrieve a specific item at a given position
     * <p/>
     * The implementation must create a ContentItem with at least the usage of ths
     * ContentItem(int position) constructor
     *
     * @param position the position greater or equals than 0
     * @return the corresponding item or null if invalid position
     */
    @NonNull
    ContentItem getContentItemAt(int position);

    /**
     * Set the provider with a specific header in the column
     *
     * @return true if the provider will manage the creation of an header view
     */
    boolean hasHeader();

    /**
     * Create the header view requested by the main component
     *
     * @param parent a non-null parent
     * @return
     */
    @NonNull
    View getHeader(@NonNull ViewGroup parent);

    /**
     * Set the provider with a specific footer in the column
     *
     * @return true if the provider will manage the creation of a footer view
     */
    boolean hasFooter();

    /**
     * Create the header view requested by the ain component
     *
     * @param parent a non-null parent
     * @return
     */
    @NonNull
    View getFooter(@NonNull ViewGroup parent);
}

TODO list

  • make the header and footer state (always visible or invisible when the content is visible/invisible)
  • customize the animation

android_multicolumn_recyclerview's People

Contributors

codlab avatar

Watchers

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