public static interface

RowReorderDetector.OnRowReorderListener

com.shinobicontrols.grids.supplement.RowReorderDetector.OnRowReorderListener
Known Indirect Subclasses

Class Overview

Callback to be invoked when a row on the grid has been reordered.

This listener provides the user with an opportunity to update the backing data store of the ShinobiGridView when a row reorder event has taken place.

For example, say your grid displays various bits of information about a group of people. This information comes from an ordered list of Person objects and each row in the grid represents a single Person. When a row reorder event occurs it is necessary to rearrange this list of Person objects inline with the reorder event so they are then displayed in the correct order. To do this you could create an RowReorderDetector.OnRowReorderListener with an onRowReorderEnded(int, int, GridRecyclerView) method as follows:

 final List<Person> people = model.getPeople();
 RowReorderDetector.OnRowReorderListener onRowReorderListener = new
          RowReorderDetector.OnRowReorderListener() {

     ...

     @Override
     public void onRowReorderEnded(int rowIndex, int endRowIndex, GridRecyclerView
              gridRecyclerView) {
         int minIndex = Math.min(rowIndex, endRowIndex);
         int rowCount = Math.abs(endRowIndex - rowIndex) + 1;
         Person person = people.get(rowIndex);
         people.remove(person);
         people.add(endRowIndex, person);
         shinobiGridView.notifyRowRangeChanged(minIndex, rowCount);
     }

     ...
 }
 

Here you can see we are removing the Person being reordered from the list and placing them back in the correct position. Finally, we notify the ShinobiGridView that a number of rows within it have changed.

Summary

Public Methods
abstract void onRowIndexChanged(int rowIndex, int fromRowIndex, int toRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked during a reorder event when a row has been moved enough for it to have been deemed to have changed places with an adjacent row.

abstract void onRowReorderCancelled(int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is cancelled.

abstract void onRowReorderEnded(int rowIndex, int endRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event that is performed on a row in the grid has ended.

abstract void onRowReorderStarted(int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is started on a row in the grid.

Public Methods

public abstract void onRowIndexChanged (int rowIndex, int fromRowIndex, int toRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked during a reorder event when a row has been moved enough for it to have been deemed to have changed places with an adjacent row. This will be called multiple times as the user drags their finger vertically across the ShinobiGridView.

Parameters
rowIndex the index of the row that is being reordered
fromRowIndex the index that the row being reordered has moved from due to dragging
toRowIndex the index that the row being reordered has moved to due to dragging
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public abstract void onRowReorderCancelled (int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is cancelled. More specifically, this is when the row has been dragged to somewhere deemed invalid for the grid, for example, out of its bounds.

Parameters
rowIndex the index of the row that was being reordered
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public abstract void onRowReorderEnded (int rowIndex, int endRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event that is performed on a row in the grid has ended. More specifically, this will be called at the end of a drag gesture, that is when the user lifts up their finger.

If at the end of the drag gesture the row has not been dragged far enough from its original position this method will be called with both parameters being the same value.

Parameters
rowIndex the index of the row that is being reordered
endRowIndex the index that the row being reordered has moved to at the end of the reorder event
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public abstract void onRowReorderStarted (int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is started on a row in the grid. More specifically, this will be called when the user long presses a row. For the rest of the reorder event this row will be used as the reference point.

Parameters
rowIndex the index of the row that is being reordered
gridRecyclerView the GridRecyclerView on which the reordering event was initiated