1 /* 2 * Copyright 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 package androidx.leanback.widget; 17 18 import android.text.TextUtils; 19 20 import androidx.annotation.NonNull; 21 22 /** 23 * DiffCallback used for GuidedActions, see {@link 24 * androidx.leanback.app.GuidedStepSupportFragment#setActionsDiffCallback(DiffCallback)}. 25 */ 26 public class GuidedActionDiffCallback extends DiffCallback<GuidedAction> { 27 28 static final GuidedActionDiffCallback sInstance = new GuidedActionDiffCallback(); 29 30 /** 31 * Returns the singleton GuidedActionDiffCallback. 32 * @return The singleton GuidedActionDiffCallback. 33 */ getInstance()34 public static GuidedActionDiffCallback getInstance() { 35 return sInstance; 36 } 37 38 @Override areItemsTheSame(@onNull GuidedAction oldItem, @NonNull GuidedAction newItem)39 public boolean areItemsTheSame(@NonNull GuidedAction oldItem, @NonNull GuidedAction newItem) { 40 if (oldItem == null) { 41 return newItem == null; 42 } else if (newItem == null) { 43 return false; 44 } 45 return oldItem.getId() == newItem.getId(); 46 } 47 48 @Override areContentsTheSame(@onNull GuidedAction oldItem, @NonNull GuidedAction newItem)49 public boolean areContentsTheSame(@NonNull GuidedAction oldItem, 50 @NonNull GuidedAction newItem) { 51 if (oldItem == null) { 52 return newItem == null; 53 } else if (newItem == null) { 54 return false; 55 } 56 return oldItem.getCheckSetId() == newItem.getCheckSetId() 57 && oldItem.mActionFlags == newItem.mActionFlags 58 && TextUtils.equals(oldItem.getTitle(), newItem.getTitle()) 59 && TextUtils.equals(oldItem.getDescription(), newItem.getDescription()) 60 && oldItem.getInputType() == newItem.getInputType() 61 && TextUtils.equals(oldItem.getEditTitle(), newItem.getEditTitle()) 62 && TextUtils.equals(oldItem.getEditDescription(), newItem.getEditDescription()) 63 && oldItem.getEditInputType() == newItem.getEditInputType() 64 && oldItem.getDescriptionEditInputType() == newItem.getDescriptionEditInputType(); 65 } 66 } 67