/** * Converts a group and/or child position to a flat position. * * @param packedPosition The group and/or child position to be converted in packed position representation. * @return The group and/or child position for the given flat position in packed position representation. */ public int getFlatPosition(long packedPosition) { if (mWrapperAdapter == null) { return RecyclerView.NO_POSITION; } return mWrapperAdapter.getFlatPosition(packedPosition); }
/*package*/ void notifyChildItemMoved(int fromGroupPosition, int fromChildPosition, int toGroupPosition, int toChildPosition) { long packedFrom = RecyclerViewExpandableItemManager.getPackedPositionForChild(fromGroupPosition, fromChildPosition); long packedTo = RecyclerViewExpandableItemManager.getPackedPositionForChild(toGroupPosition, toChildPosition); int flatFrom = getFlatPosition(packedFrom); int flatTo = getFlatPosition(packedTo); mPositionTranslator.moveChildItem(fromGroupPosition, fromChildPosition, toGroupPosition, toChildPosition); if (flatFrom != RecyclerView.NO_POSITION && flatTo != RecyclerView.NO_POSITION) { notifyItemMoved(flatFrom, flatTo); } else if (flatFrom != RecyclerView.NO_POSITION) { notifyItemRemoved(flatFrom); } else if (flatTo != RecyclerView.NO_POSITION) { notifyItemInserted(flatTo); } }
/*package*/ void notifyGroupItemMoved(int fromGroupPosition, int toGroupPosition) { long packedFrom = RecyclerViewExpandableItemManager.getPackedPositionForGroup(fromGroupPosition); long packedTo = RecyclerViewExpandableItemManager.getPackedPositionForGroup(toGroupPosition); int flatFrom = getFlatPosition(packedFrom); int flatTo = getFlatPosition(packedTo); boolean fromExpanded = isGroupExpanded(fromGroupPosition); boolean toExpanded = isGroupExpanded(toGroupPosition); mPositionTranslator.moveGroupItem(fromGroupPosition, toGroupPosition); if (!fromExpanded && !toExpanded) { notifyItemMoved(flatFrom, flatTo); } else { notifyDataSetChanged(); } }