public final class

RowColumnReorderManager

extends Object
implements RecyclerView.OnItemTouchListener
java.lang.Object
   ↳ com.shinobicontrols.grids.supplement.RowColumnReorderManager

Class Overview

A convenience class responsible for interpreting user long press and drag gestures on a given GridRecyclerView component of a ShinobiGridView into reorder events of optionally, rows and columns.

The RowColumnReorderManager provides visual feedback of the reorder event, pulling the row or column out of the grid and moving it in-sync with the user's finger. When the user lifts their finger from the screen the row or column is put back into the grid. For column reordering, the columns will be re-arranged inline with where the column was placed. For row reordering, it is up to the RowReorderDetector.OnRowReorderListener passed into the constructor to perform any updating of the backing data store for the grid. Additionally, the ItemStateManager held by the ShinobiGridView will be used to maintain the selection state and visibility state of items within the grid across row reorder events. For column reorder events this is done by the ShinobiGridView automatically.

The RowColumnReorderManager restricts row reordering to being performed on the data items of the ShinobiGridView and restricts column reordering to being performed on the header items of the ShinobiGridView. As such, if the ShinobiGridView does not have a header row (because none of the Columns have a header) it will not be possible to reorder the columns.

The RowColumnReorderManager is an android.support.v7.widget.RecyclerView.OnItemTouchListener and so is added directly to the header and data GridRecyclerViews of the ShinobiGridView. Therefore, there are three steps necessary to enable row and column reordering on your ShinobiGridView:

For example:

 RowColumnReorderManager rowColumnReorderManager = new RowColumnReorderManager(shinobiGridView,
          onRowReorderListener);
 shinobiGridView.getHeaderRecyclerView().addOnItemTouchListener(rowColumnReorderManager);
 shinobiGridView.getDataRecyclerView().addOnItemTouchListener(rowColumnReorderManager);
 

You can additionally allow and disallow row or column reordering by using the setShouldManageRowReorder(boolean) and setShouldManageColumnReorder(boolean) methods. If you wish to change the way items are searched for when the initial long press is made and when the user lifts their finger you can set a ChildViewFinder using the setChildViewFinder(ChildViewFinder) method. By default, a NearestInTouchBoundsChildViewFinder is used.

The RowColumnReorderManager makes use of a number of different components within the library in order to provide a simple way to add visual row and column reordering to your grid. These are listed below. If you require greater control and flexibility you can piece together the various components yourself, adding in your own customisations. This will of course require some extra work.

Summary

Public Constructors
RowColumnReorderManager(ShinobiGridView shinobiGridView, RowReorderDetector.OnRowReorderListener onRowReorderListener)
Public Methods
void setChildViewFinder(ChildViewFinder childViewFinder)

Sets the ChildViewFinder which will be used to determine how a child view is searched for, during a user gesture.

void setShouldManageColumnReorder(boolean shouldManageColumnReorder)

Sets if this RowColumnReorderManager should react to column reorder gestures.

void setShouldManageRowReorder(boolean shouldManageRowReorder)

Sets if this RowColumnReorderManager should react to row reorder gestures.

[Expand]
Inherited Methods
From class java.lang.Object
From interface android.support.v7.widget.RecyclerView.OnItemTouchListener

Public Constructors

public RowColumnReorderManager (ShinobiGridView shinobiGridView, RowReorderDetector.OnRowReorderListener onRowReorderListener)

Parameters
shinobiGridView the ShinobiGridView on which the user gestures will occur. This cannot be null.
onRowReorderListener the RowReorderDetector.OnRowReorderListener whose methods will be invoked during a row reorder event. This object will be responsible for updating the backing data store appropriately, to perform the reorder of the data itself. This cannot be null.

Public Methods

public void setChildViewFinder (ChildViewFinder childViewFinder)

Sets the ChildViewFinder which will be used to determine how a child view is searched for, during a user gesture. This cannot be null.

By default this RowColumnReorderManager uses a NearestInTouchBoundsChildViewFinder.

Parameters
childViewFinder the ChildViewFinder to set, if this parameter is null an IllegalArgumentException will be thrown

public void setShouldManageColumnReorder (boolean shouldManageColumnReorder)

Sets if this RowColumnReorderManager should react to column reorder gestures. This is set to true by default.

Parameters
shouldManageColumnReorder set to false this RowColumnReorderManager should not react to column reorder gestures. This is set to true by default.

public void setShouldManageRowReorder (boolean shouldManageRowReorder)

Sets if this RowColumnReorderManager should react to row reorder gestures. This is set to true by default.

Parameters
shouldManageRowReorder set to false this RowColumnReorderManager should not react to row reorder gestures. This is set to true by default.