1 /* 2 * Copyright 2018 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 package androidx.recyclerview.widget; 17 18 import org.jspecify.annotations.Nullable; 19 20 /** 21 * An interface that can receive Update operations that are applied to a list. 22 * <p> 23 * This class can be used together with DiffUtil to detect changes between two lists. 24 */ 25 public interface ListUpdateCallback { 26 /** 27 * Called when {@code count} number of items are inserted at the given position. 28 * 29 * @param position The position of the new item. 30 * @param count The number of items that have been added. 31 */ onInserted(int position, int count)32 void onInserted(int position, int count); 33 34 /** 35 * Called when {@code count} number of items are removed from the given position. 36 * 37 * @param position The position of the item which has been removed. 38 * @param count The number of items which have been removed. 39 */ onRemoved(int position, int count)40 void onRemoved(int position, int count); 41 42 /** 43 * Called when an item changes its position in the list. 44 * 45 * @param fromPosition The previous position of the item before the move. 46 * @param toPosition The new position of the item. 47 */ onMoved(int fromPosition, int toPosition)48 void onMoved(int fromPosition, int toPosition); 49 50 /** 51 * Called when {@code count} number of items are updated at the given position. 52 * 53 * @param position The position of the item which has been updated. 54 * @param count The number of items which has changed. 55 * @param payload The payload for the changed items. 56 */ onChanged(int position, int count, @Nullable Object payload)57 void onChanged(int position, int count, @Nullable Object payload); 58 } 59