Description of base list row actions and list events
Actions
Action switch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | @Override public GSDRowConfig getConfigForRow(int position) { GSDRowConfig.Builder row = new GSDRowConfig.Builder(); ... row.setItemActionClickListener(GSDComplexRow.ACTION_SWITCH, new GSDRecyclerViewContract.RowItemActionClickListener() { @Override public void onItemClick(int position) { } @Override public void onItemStateChange(int position, boolean value) { elements.get(position).setSelected(value); // Do whatever you want } }); row.setSwitchState(obj.getState()); } |
Action button:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @Override public GSDRowConfig getConfigForRow(int position) { GSDRowConfig.Builder row = new GSDRowConfig.Builder(); ... row.setItemActionClickListener(GSDComplexRow.ACTION_BUTTON, new GSDRecyclerViewContract.RowItemActionClickListener() { @Override public void onItemClick(int position) { ///////////////////////////////////////////////////////////////// // This is sample ModelObject obj = elements.get(position); Toast.makeText(context, obj.getTitle, Toast.LENGTH_SHORT).show(); ///////////////////////////////////////////////////////////////// //Here you can put your logic } @Override public void onItemStateChange(int position, boolean value) { } }); row.setActionText("Action"); } |
Events
Item click:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @Override public GSDRowConfig getConfigForRow(int position) { GSDRowConfig.Builder row = new GSDRowConfig.Builder(); ... row.setItemInteractionListener(new GSDRecyclerViewContract.RowItemInteractionListener() { @Override public void onListElementClick(int position) { // Handle item single click } @Override public void onListElementLongClick(int position) { // Handle item long click } }); } |
Elements left/right swipe:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { ... recyclerView = (GSDRecyclerView) findViewById(R.id.recyclerView); ... recyclerView.setMotionEventListener(new GSDRecyclerViewContract.ListMotionEventListener() { @Override public void onSwipeLeft(int position) { // logic for swipe left } @Override public void onSwipeRight(int position) { // logic for swipe right } @Override public boolean dismissElementOnSwipe() { // if swipe left or right result element remove // than you can return true and list will animate // element remove from list return false; } }); } |
List elements drag and drop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { ... recyclerView = (GSDRecyclerView) findViewById(R.id.recyclerView); ... recyclerView.setDragAndDropListener(new GSDRecyclerViewContract.DragEventListener() { @Override public boolean onMove(int fromPosition, int toPosition) { // here you need to swap elements in collection // that is used by your provider // and return true if swap was successful return false; } }); } |
End of list during scroll:
1 2 3 4 5 6 7 8 9 10 11 12 13 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { ... recyclerView = (GSDRecyclerView) findViewById(R.id.recyclerView); ... recyclerView.addOnScrollListener(new GSDRecyclerViewOnScrollListener(100) { @Override public boolean onLoadMore(int page, int totalItemsCount) { // proceed loading additional data return true; } }); } |