SortedListAdapterCallback.java revision ac5fe7c617c66850fff75a9fce9979c6e5674b0f
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 17package androidx.recyclerview.widget; 18 19/** 20 * A {@link SortedList.Callback} implementation that can bind a {@link SortedList} to a 21 * {@link RecyclerView.Adapter}. 22 */ 23public abstract class SortedListAdapterCallback<T2> extends SortedList.Callback<T2> { 24 25 final RecyclerView.Adapter mAdapter; 26 27 /** 28 * Creates a {@link SortedList.Callback} that will forward data change events to the provided 29 * Adapter. 30 * 31 * @param adapter The Adapter instance which should receive events from the SortedList. 32 */ 33 public SortedListAdapterCallback(RecyclerView.Adapter adapter) { 34 mAdapter = adapter; 35 } 36 37 @Override 38 public void onInserted(int position, int count) { 39 mAdapter.notifyItemRangeInserted(position, count); 40 } 41 42 @Override 43 public void onRemoved(int position, int count) { 44 mAdapter.notifyItemRangeRemoved(position, count); 45 } 46 47 @Override 48 public void onMoved(int fromPosition, int toPosition) { 49 mAdapter.notifyItemMoved(fromPosition, toPosition); 50 } 51 52 @Override 53 public void onChanged(int position, int count) { 54 mAdapter.notifyItemRangeChanged(position, count); 55 } 56 57 @Override 58 public void onChanged(int position, int count, Object payload) { 59 mAdapter.notifyItemRangeChanged(position, count, payload); 60 } 61} 62