blob: c513e732d8c1e5b09fcdaed358e859ed5997e5c1 [file] [log] [blame]
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.support.v17.leanback.widget;
import android.support.annotation.NonNull;
import java.util.List;
/**
* Callback that informs {@link ArrayObjectAdapter} how to compute list updates when using
* {@link android.support.v7.util.DiffUtil} in {@link ArrayObjectAdapter#setItems(List,
* DiffCallback)} method.
* <p>
* The {@link ArrayObjectAdapter#setItems(List,
* DiffCallback)} method will pass items from different
* lists to this callback in order to implement
* the {@link android.support.v7.util.DiffUtil.Callback} it uses to compute differences between
* lists.
*
* @param <Value> Type of items to compare.
*/
public abstract class DiffCallback<Value> {
/**
* Called to decide whether two objects represent the same item.
*
* @param oldItem The item in the old list.
* @param newItem The item in the new list.
* @return True if the two items represent the same object or false if they are different.
* @see android.support.v7.util.DiffUtil.Callback#areItemsTheSame(int, int)
*/
public abstract boolean areItemsTheSame(@NonNull Value oldItem, @NonNull Value newItem);
/**
* Called to decide whether two items have the same data. This information is used to detect if
* the contents of an item have changed.
*
* @param oldItem The item in the old list.
* @param newItem The item in the new list.
* @return True if the contents of the items are the same or false if they are different.
* @see android.support.v7.util.DiffUtil.Callback#areContentsTheSame(int, int)
*/
public abstract boolean areContentsTheSame(@NonNull Value oldItem, @NonNull Value newItem);
/**
* Called to get a change payload between an old and new version of an item.
*
* @see android.support.v7.util.DiffUtil.Callback#getChangePayload(int, int)
*/
@SuppressWarnings("WeakerAccess")
public Object getChangePayload(@NonNull Value oldItem, @NonNull Value newItem) {
return null;
}
}