/** * Create wrapped adapter. * * @param adapter The target adapter. * @return Wrapped adapter which is associated to this {@link RecyclerViewDragDropManager} instance. */ @SuppressWarnings("unchecked") @NonNull public RecyclerView.Adapter createWrappedAdapter(@NonNull RecyclerView.Adapter adapter) { if (!adapter.hasStableIds()) { throw new IllegalArgumentException("The passed adapter does not support stable IDs"); } if (mWrapperAdapter != null) { throw new IllegalStateException("already have a wrapped adapter"); } mWrapperAdapter = new DraggableItemWrapperAdapter(this, adapter); return mWrapperAdapter; }
/** * Create wrapped adapter. * * @param adapter The target adapter. * @return Wrapped adapter which is associated to this {@link RecyclerViewSwipeManager} instance. */ @SuppressWarnings("unchecked") @NonNull public RecyclerView.Adapter createWrappedAdapter(@NonNull RecyclerView.Adapter adapter) { if (!adapter.hasStableIds()) { throw new IllegalArgumentException("The passed adapter does not support stable IDs"); } if (mWrapperAdapter != null) { throw new IllegalStateException("already have a wrapped adapter"); } mWrapperAdapter = new SwipeableItemWrapperAdapter(this, adapter); return mWrapperAdapter; }
/** * Create wrapped adapter. * * @param adapter The target adapter. * @return Wrapped adapter which is associated to this {@link RecyclerViewExpandableItemManager} instance. */ @SuppressWarnings("unchecked") @NonNull public RecyclerView.Adapter createWrappedAdapter(@NonNull RecyclerView.Adapter adapter) { if (!adapter.hasStableIds()) { throw new IllegalArgumentException("The passed adapter does not support stable IDs"); } if (mWrapperAdapter != null) { throw new IllegalStateException("already have a wrapped adapter"); } long[] adapterSavedState = (mSavedState != null) ? mSavedState.adapterSavedState : null; mSavedState = null; mWrapperAdapter = new ExpandableRecyclerViewWrapperAdapter(this, adapter, adapterSavedState); // move listeners to wrapper adapter mWrapperAdapter.setOnGroupExpandListener(mOnGroupExpandListener); mOnGroupExpandListener = null; mWrapperAdapter.setOnGroupCollapseListener(mOnGroupCollapseListener); mOnGroupCollapseListener = null; return mWrapperAdapter; }
/** * @param adapter Adapter with which this data set differ is associated. * @param callback Callback that provides information about the items set in the adapter. */ public DataSetDiffer(RecyclerView.Adapter adapter, Callback callback) { if (!adapter.hasStableIds()) { adapter.setHasStableIds(true); } this.adapter = adapter; this.callback = callback; this.itemsObserver = new ItemsObserver(items, callback); this.adapterNotifyDiffHandler = new AdapterNotifyDiffHandler(adapter); startObservingItems(); }
/** * Make sure this constructor is called before setting the adapter on the RecyclerView * so this class will be notified before the RecyclerView in case of data set changes. */ public MultiChoiceHelper(@NonNull AppCompatActivity activity, @NonNull RecyclerView.Adapter adapter) { this.activity = activity; this.adapter = adapter; adapter.registerAdapterDataObserver(new AdapterDataSetObserver()); checkStates = new SparseBooleanArray(0); if (adapter.hasStableIds()) { checkedIdStates = new LongSparseArray<>(0); } }
@Override public void setAdapter(Adapter adapter) { if (!isInEditMode()) { if (!(adapter instanceof DragItemAdapter)) { throw new RuntimeException("Adapter must extend DragItemAdapter"); } if (!adapter.hasStableIds()) { throw new RuntimeException("Adapter must have stable ids"); } } super.setAdapter(adapter); mAdapter = (DragItemAdapter) adapter; }
/** * @param adapter Adapter with which this data set differ is associated. * @param callback Callback that provides information about the items set in the adapter. */ public AsyncDataSetDiffer(RecyclerView.Adapter adapter, DataSetDiffer.Callback callback) { if (!adapter.hasStableIds()) { adapter.setHasStableIds(true); } this.adapter = adapter; dataSetDiffer = new DataSetDiffer(adapter, callback); }
AdapterWrapper(Adapter<ViewHolder> adapter) { if (adapter == null) { throw new NullPointerException("adapter is null"); } this.adapter = adapter; setHasStableIds(adapter.hasStableIds()); }
/** * * @param adapter Wrapped contents adapter. */ @SuppressWarnings("unchecked") @NonNull public AbstractHeaderFooterWrapperAdapter setAdapter(@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter) { if (mWrappedAdapter != null) { throw new IllegalStateException("setAdapter() can call only once"); } mWrappedAdapter = adapter; mHeaderAdapter = onCreateHeaderAdapter(); mFooterAdapter = onCreateFooterAdapter(); final boolean hasStableIds = adapter.hasStableIds(); mHeaderAdapter.setHasStableIds(hasStableIds); mFooterAdapter.setHasStableIds(hasStableIds); setHasStableIds(hasStableIds); mHeaderAdapterTag = addAdapter(mHeaderAdapter); mWrappedAdapterTag = addAdapter(mWrappedAdapter); mFooterAdapterTag = addAdapter(mFooterAdapter); return this; }
/** * Adda child adapter to the specified position. * * @param adapter The adapter which to be managed by the ComposedAdapter * @param position The position inserting a child adapter * @return An instance of {@link ComposedChildAdapterTag} * @see #addAdapter(RecyclerView.Adapter) */ @NonNull public ComposedChildAdapterTag addAdapter(@NonNull RecyclerView.Adapter adapter, int position) { if (hasObservers() && hasStableIds()) { if (!adapter.hasStableIds()) { throw new IllegalStateException("Wrapped child adapter must has stable IDs"); } } final ComposedChildAdapterTag tag = mAdaptersSet.addAdapter(adapter, position); final int segment = mAdaptersSet.getAdapterSegment(tag); mSegmentedPositionTranslator.invalidateSegment(segment); // NOTE: Need to assume as data set change here because view types and item IDs are completely changed! notifyDataSetChanged(); return tag; }
/** * {@inheritDoc} */ @Override public void setHasStableIds(boolean hasStableIds) { // checks all children adapters support stable IDs if (hasStableIds && !hasStableIds()) { final int numSegments = mAdaptersSet.getSegmentCount(); for (int i = 0; i < numSegments; i++) { RecyclerView.Adapter adapter = mAdaptersSet.getAdapter(i); if (!adapter.hasStableIds()) { throw new IllegalStateException("All child adapters must support stable IDs"); } } } super.setHasStableIds(hasStableIds); }
/** * Constructor * @param adapter The adapter which to be wrapped */ public SimpleWrapperAdapter(@NonNull RecyclerView.Adapter<VH> adapter) { mWrappedAdapter = adapter; mBridgeObserver = new BridgeAdapterDataObserver(this, mWrappedAdapter, null); mWrappedAdapter.registerAdapterDataObserver(mBridgeObserver); super.setHasStableIds(mWrappedAdapter.hasStableIds()); }