1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.leanback.widget;
18
19import androidx.annotation.NonNull;
20import androidx.recyclerview.widget.DiffUtil;
21
22import java.util.List;
23
24/**
25 * Callback that informs {@link ArrayObjectAdapter} how to compute list updates when using
26 * {@link DiffUtil} in {@link ArrayObjectAdapter#setItems(List,
27 * DiffCallback)} method.
28 * <p>
29 * The {@link ArrayObjectAdapter#setItems(List,
30 * DiffCallback)} method will pass items from different
31 * lists to this callback in order to implement
32 * the {@link DiffUtil.Callback} it uses to compute differences between
33 * lists.
34 *
35 * @param  Type of items to compare.
36 */
37public abstract class DiffCallback<Value> {
38    /**
39     * Called to decide whether two objects represent the same item.
40     *
41     * @param oldItem The item in the old list.
42     * @param newItem The item in the new list.
43     * @return True if the two items represent the same object or false if they are different.
44     * @see DiffUtil.Callback#areItemsTheSame(int, int)
45     */
46    public abstract boolean areItemsTheSame(@NonNull Value oldItem, @NonNull Value newItem);
47
48    /**
49     * Called to decide whether two items have the same data. This information is used to detect if
50     * the contents of an item have changed.
51     *
52     * @param oldItem The item in the old list.
53     * @param newItem The item in the new list.
54     * @return True if the contents of the items are the same or false if they are different.
55     * @see DiffUtil.Callback#areContentsTheSame(int, int)
56     */
57    public abstract boolean areContentsTheSame(@NonNull Value oldItem, @NonNull Value newItem);
58
59    /**
60     * Called to get a change payload between an old and new version of an item.
61     *
62     * @see DiffUtil.Callback#getChangePayload(int, int)
63     */
64    @SuppressWarnings("WeakerAccess")
65    public Object getChangePayload(@NonNull Value oldItem, @NonNull Value newItem) {
66        return null;
67    }
68}
69