Java Code Examples for androidx.recyclerview.widget.DiffUtil#ItemCallback

The following examples show how to use androidx.recyclerview.widget.DiffUtil#ItemCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RVListRendererAdapter.java    From Renderers with Apache License 2.0 5 votes vote down vote up
public RVListRendererAdapter(RendererBuilder<T> rendererBuilder,
                             @NonNull DiffUtil.ItemCallback diffCallback,
                             AdapteeCollection<T> collection) {
    super(diffCallback);
    this.rendererBuilder = rendererBuilder;
    this.collection = collection;
}
 
Example 2
Source File: PagedListDelegationAdapterTest.java    From AdapterDelegates with Apache License 2.0 5 votes vote down vote up
@Test
public void itemCallbackIsNull() {
    try {
        PagedListDelegationAdapter<Object> adapter = new PagedListDelegationAdapter<Object>((DiffUtil.ItemCallback<Object>) null) {
            @Override
            public int getItemCount() {
                return 0;
            }
        };
        Assert.fail("Expected NullPointerException");
    } catch (NullPointerException e) {
        Assert.assertEquals("ItemCallback is null", e.getMessage());
    }
}
 
Example 3
Source File: DatabasePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private DatabasePagingOptions(@NonNull LiveData<PagedList<DataSnapshot>> data,
                              @NonNull SnapshotParser<T> parser,
                              @NonNull DiffUtil.ItemCallback<DataSnapshot> diffCallback,
                              @Nullable LifecycleOwner owner) {
    mParser = parser;
    mData = data;
    mDiffCallback = diffCallback;
    mOwner = owner;
}
 
Example 4
Source File: PagedListDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 5 votes vote down vote up
public PagedListDelegationAdapter(@NonNull AdapterDelegatesManager<List<T>> delegatesManager,
                                  @NonNull DiffUtil.ItemCallback<T> diffCallback) {
    super(diffCallback);
    if (diffCallback == null) {
        throw new NullPointerException("ItemCallback is null");
    }

    if (delegatesManager == null) {
        throw new NullPointerException("AdapterDelegatesManager is null");
    }
    this.delegatesManager = delegatesManager;
}
 
Example 5
Source File: FirestorePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private FirestorePagingOptions(@NonNull LiveData<PagedList<DocumentSnapshot>> data,
                               @NonNull SnapshotParser<T> parser,
                               @NonNull DiffUtil.ItemCallback<DocumentSnapshot> diffCallback,
                               @Nullable LifecycleOwner owner) {
    mData = data;
    mParser = parser;
    mDiffCallback = diffCallback;
    mOwner = owner;
}
 
Example 6
Source File: PagedListDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 5 votes vote down vote up
/**
 * @param diffCallback The Callback
 * @param delegates    The {@link AdapterDelegate}s that should be added
 * @since 4.1.0
 */
public PagedListDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback, AdapterDelegate<List<T>>... delegates) {
    this(new AdapterDelegatesManager<List<T>>(), diffCallback);
    for (int i = 0; i < delegates.length; i++) {
        delegatesManager.addDelegate(delegates[i]);
    }
}
 
Example 7
Source File: AsyncListDifferDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a list of {@link AdapterDelegate}s
 *
 * @param delegates
 * @since 4.2.0
 */
public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback,
                                        @NonNull AdapterDelegate<List<T>>... delegates) {

    if (diffCallback == null) {
        throw new NullPointerException("ItemCallback is null");
    }
    
    this.differ = new AsyncListDiffer<T>(this, diffCallback);
    this.delegatesManager = new AdapterDelegatesManager<List<T>>(delegates);
}
 
Example 8
Source File: DifferActivity.java    From Flap with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_differ);

    RecyclerView recyclerView = findViewById(R.id.rv_items);

    flapAdapter = new DifferFlapAdapter<>(new DiffUtil.ItemCallback<SimpleTextModel>() {
        @Override
        public boolean areItemsTheSame(@NonNull final SimpleTextModel simpleTextModel, @NonNull final SimpleTextModel t1) {
            return true;
        }

        @Override
        public boolean areContentsTheSame(@NonNull final SimpleTextModel simpleTextModel, @NonNull final SimpleTextModel t1) {
            return simpleTextModel.equals(t1);
        }

        @Nullable
        @Override
        public Object getChangePayload(@NonNull final SimpleTextModel oldItem, @NonNull final SimpleTextModel newItem) {
            return super.getChangePayload(oldItem, newItem);
        }
    });

    List<SimpleTextModel> models = new ArrayList<>();

    for (int i = 0; i < 20; i++) {
        models.add(new SimpleTextModel("Android :" + i));
    }

    flapAdapter.setData(models);

    recyclerView.setAdapter(flapAdapter);
}
 
Example 9
Source File: AsyncListDifferDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 5 votes vote down vote up
public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback,
                                        @NonNull AdapterDelegatesManager<List<T>> delegatesManager) {

    if (diffCallback == null) {
        throw new NullPointerException("ItemCallback is null");
    }

    if (delegatesManager == null) {
        throw new NullPointerException("AdapterDelegatesManager is null");
    }
    this.differ = new AsyncListDiffer<T>(this, diffCallback);
    this.delegatesManager = delegatesManager;
}
 
Example 10
Source File: AsyncListDifferDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 4 votes vote down vote up
public AsyncListDifferDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback) {
    this(diffCallback, new AdapterDelegatesManager<List<T>>());
}
 
Example 11
Source File: RVListRendererAdapter.java    From Renderers with Apache License 2.0 4 votes vote down vote up
public RVListRendererAdapter(RendererBuilder<T> rendererBuilder, @NonNull DiffUtil.ItemCallback diffCallback) {
    this(rendererBuilder, diffCallback, new ListAdapteeCollection<T>());
}
 
Example 12
Source File: PagedListDelegationAdapter.java    From AdapterDelegates with Apache License 2.0 4 votes vote down vote up
public PagedListDelegationAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback) {
    this(new AdapterDelegatesManager<List<T>>(), diffCallback);
}
 
Example 13
Source File: FirestorePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@NonNull
public DiffUtil.ItemCallback<DocumentSnapshot> getDiffCallback() {
    return mDiffCallback;
}
 
Example 14
Source File: DatabasePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@NonNull
public DiffUtil.ItemCallback<DataSnapshot> getDiffCallback() {
    return mDiffCallback;
}
 
Example 15
Source File: ListAyatAdapter.java    From AlquranQ with MIT License 4 votes vote down vote up
ListAyatAdapter(@NonNull DiffUtil.ItemCallback<Ayat> diffCallback) {
    super(diffCallback);
}
 
Example 16
Source File: ListSurahAdapter.java    From AlquranQ with MIT License 4 votes vote down vote up
ListSurahAdapter(@NonNull DiffUtil.ItemCallback<Surah> diffCallback, OnSurahItemClick click) {
    super(diffCallback);
    this.click = click;
}
 
Example 17
Source File: DifferFlapAdapter.java    From Flap with Apache License 2.0 4 votes vote down vote up
public DifferFlapAdapter(final @NonNull DiffUtil.ItemCallback<T> itemCallback) {
    differ = new AsyncListDiffer(this, itemCallback);
}
 
Example 18
Source File: FirestorePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Sets an optional custom {@link DiffUtil.ItemCallback} to compare
 * {@link DocumentSnapshot} objects.
 *
 * The default implementation is {@link DefaultSnapshotDiffCallback}.
 * 
 * @return this, for chaining.
 */
@NonNull
public Builder<T> setDiffCallback(@NonNull DiffUtil.ItemCallback<DocumentSnapshot> diffCallback) {
    mDiffCallback = diffCallback;
    return this;
}
 
Example 19
Source File: DatabasePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Sets an optional custom {@link DiffUtil.ItemCallback} to compare
 * {@link T} objects.
 *
 * @return this, for chaining.
 */
@NonNull
public Builder<T> setDiffCallback(@NonNull DiffUtil.ItemCallback<DataSnapshot> diffCallback) {
    mDiffCallback = diffCallback;
    return this;
}
 
Example 20
Source File: AssemblyPagedListAdapter.java    From assembly-adapter with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a PagedListAdapter with default threading and
 * {@link androidx.recyclerview.widget.ListUpdateCallback}.
 * <p>
 * Convenience for PagedListAdapter(AsyncDifferConfig), which uses default threading
 * behavior.
 *
 * @param diffCallback The {@link DiffUtil.ItemCallback DiffUtil.ItemCallback} instance to
 *                     compare items in the list.
 */
public AssemblyPagedListAdapter(@NonNull DiffUtil.ItemCallback<T> diffCallback) {
    mDiffer = new AsyncPagedListDiffer<T>(this, diffCallback);
    mDiffer.addPagedListListener(mListener);
}