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  */
17 
18 package com.android.settings.search2;
19 
20 import android.support.v7.util.DiffUtil;
21 
22 import java.util.List;
23 
24 /**
25  * Callback for DiffUtil to elegantly update search data when the query changes.
26  */
27 public class SearchResultDiffCallback extends DiffUtil.Callback {
28 
29     private List<SearchResult> mOldList;
30     private List<SearchResult> mNewList;
31 
SearchResultDiffCallback(List<SearchResult> oldList, List<SearchResult> newList)32     public SearchResultDiffCallback(List<SearchResult> oldList, List<SearchResult> newList) {
33         mOldList = oldList;
34         mNewList = newList;
35     }
36 
37     @Override
getOldListSize()38     public int getOldListSize() {
39         return mOldList.size();
40     }
41 
42     @Override
getNewListSize()43     public int getNewListSize() {
44         return mNewList.size();
45     }
46 
47     @Override
areItemsTheSame(int oldItemPosition, int newItemPosition)48     public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
49         return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition));
50     }
51 
52     @Override
areContentsTheSame(int oldItemPosition, int newItemPosition)53     public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
54         return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition));
55     }
56 }
57