@Test public void testRegisterOnDataSetListener() { final TestAdapter adapter = new TestAdapter(context); final OnDataSetListener mockListener = mock(OnDataSetListener.class); adapter.registerOnDataSetListener(mockListener); adapter.registerOnDataSetListener(mockListener); adapter.notifyDataSetChanged(); adapter.notifyItemRangeInserted(0, 1); adapter.notifyItemRangeChanged(0, 1, null); adapter.notifyItemMoved(0, 1); adapter.notifyItemRangeRemoved(0, 1); verify(mockListener, times(5)).onDataSetChanged(); verifyNoMoreInteractions(mockListener); }
@Override public void registerOnDataSetListener(@NonNull final OnDataSetListener listener) { if (dataSetListeners == null) { this.dataSetListeners = new DataSetListeners(this); } this.dataSetListeners.registerOnDataSetListener(listener); if (dataObserver == null) { registerAdapterDataObserver(dataObserver = new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final @Nullable Object payload) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } }); } }
BaseRecyclerAdapter extends RecyclerView.Adapter<VH> implements
		DataSetAdapter<I>,
		AdapterHolder.FactoryAdapter<VH>,
		AdapterHolder.BinderAdapter<A, VH> { @Override public void registerOnDataSetListener(@NonNull final OnDataSetListener listener) { if (dataSetListeners == null) { this.dataSetListeners = new DataSetListeners(this); } this.dataSetListeners.registerOnDataSetListener(listener); if (dataObserver == null) { registerAdapterDataObserver(dataObserver = new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final @Nullable Object payload) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } }); } } }
BaseRecyclerAdapter extends RecyclerView.Adapter<VH> implements
		DataSetAdapter<I>,
		AdapterHolder.FactoryAdapter<VH>,
		AdapterHolder.BinderAdapter<A, VH> { @Override public void registerOnDataSetListener(@NonNull final OnDataSetListener listener) { if (dataSetListeners == null) { this.dataSetListeners = new DataSetListeners(this); } this.dataSetListeners.registerOnDataSetListener(listener); if (dataObserver == null) { registerAdapterDataObserver(dataObserver = new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final @Nullable Object payload) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } }); } } BaseRecyclerAdapter(@NonNull final Context context); }
BaseRecyclerAdapter extends RecyclerView.Adapter<VH> implements
		DataSetAdapter<I>,
		AdapterHolder.FactoryAdapter<VH>,
		AdapterHolder.BinderAdapter<A, VH> { @Override public void registerOnDataSetListener(@NonNull final OnDataSetListener listener) { if (dataSetListeners == null) { this.dataSetListeners = new DataSetListeners(this); } this.dataSetListeners.registerOnDataSetListener(listener); if (dataObserver == null) { registerAdapterDataObserver(dataObserver = new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final @Nullable Object payload) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } }); } } BaseRecyclerAdapter(@NonNull final Context context); @NonNull final Context getContext(); @NonNull final Resources getResources(); @Override void registerOnDataSetListener(@NonNull final OnDataSetListener listener); @Override void unregisterOnDataSetListener(@NonNull final OnDataSetListener listener); @Override void registerOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); @SuppressWarnings("SimplifiableIfStatement") boolean notifyDataSetActionSelected(final int action, final int position, @Nullable final Object payload); @Override void unregisterOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); @Override boolean isEmpty(); @Override boolean isEnabled(final int position); @Override boolean hasItemAt(final int position); @Override long getItemId(final int position); @Override void setHolderFactory(@Nullable final AdapterHolder.Factory<VH> factory); @Override @Nullable AdapterHolder.Factory<VH> getHolderFactory(); @Override void setHolderBinder(@Nullable final AdapterHolder.Binder<A, VH> binder); @Override @Nullable AdapterHolder.Binder<A, VH> getHolderBinder(); @Override VH onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType); @NonNull View inflateView(@LayoutRes final int resource, @Nullable final ViewGroup parent); @SuppressWarnings("unchecked") @Override void onBindViewHolder(@NonNull final VH viewHolder, final int position, @NonNull final List<Object> payloads); @SuppressWarnings("unchecked") @Override void onBindViewHolder(@NonNull final VH viewHolder, final int position); @Override @CallSuper @NonNull Parcelable saveInstanceState(); @Override @CallSuper void restoreInstanceState(@NonNull Parcelable savedState); }
BaseRecyclerAdapter extends RecyclerView.Adapter<VH> implements
		DataSetAdapter<I>,
		AdapterHolder.FactoryAdapter<VH>,
		AdapterHolder.BinderAdapter<A, VH> { @Override public void registerOnDataSetListener(@NonNull final OnDataSetListener listener) { if (dataSetListeners == null) { this.dataSetListeners = new DataSetListeners(this); } this.dataSetListeners.registerOnDataSetListener(listener); if (dataObserver == null) { registerAdapterDataObserver(dataObserver = new RecyclerView.AdapterDataObserver() { @Override public void onChanged() { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeInserted(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeChanged(final int positionStart, final int itemCount, final @Nullable Object payload) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { dataSetListeners.notifyDataSetChanged(); } @Override public void onItemRangeRemoved(final int positionStart, final int itemCount) { dataSetListeners.notifyDataSetChanged(); } }); } } BaseRecyclerAdapter(@NonNull final Context context); @NonNull final Context getContext(); @NonNull final Resources getResources(); @Override void registerOnDataSetListener(@NonNull final OnDataSetListener listener); @Override void unregisterOnDataSetListener(@NonNull final OnDataSetListener listener); @Override void registerOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); @SuppressWarnings("SimplifiableIfStatement") boolean notifyDataSetActionSelected(final int action, final int position, @Nullable final Object payload); @Override void unregisterOnDataSetActionListener(@NonNull final OnDataSetActionListener listener); @Override boolean isEmpty(); @Override boolean isEnabled(final int position); @Override boolean hasItemAt(final int position); @Override long getItemId(final int position); @Override void setHolderFactory(@Nullable final AdapterHolder.Factory<VH> factory); @Override @Nullable AdapterHolder.Factory<VH> getHolderFactory(); @Override void setHolderBinder(@Nullable final AdapterHolder.Binder<A, VH> binder); @Override @Nullable AdapterHolder.Binder<A, VH> getHolderBinder(); @Override VH onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType); @NonNull View inflateView(@LayoutRes final int resource, @Nullable final ViewGroup parent); @SuppressWarnings("unchecked") @Override void onBindViewHolder(@NonNull final VH viewHolder, final int position, @NonNull final List<Object> payloads); @SuppressWarnings("unchecked") @Override void onBindViewHolder(@NonNull final VH viewHolder, final int position); @Override @CallSuper @NonNull Parcelable saveInstanceState(); @Override @CallSuper void restoreInstanceState(@NonNull Parcelable savedState);  }