1 /* 2 * Copyright (C) 2024 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 package com.android.systemui.media.controls.ui.util 18 19 import androidx.recyclerview.widget.DiffUtil 20 import com.android.systemui.media.controls.ui.viewmodel.MediaControlViewModel 21 22 /** A [DiffUtil.Callback] to calculate difference between old and new media view-model list. */ 23 class MediaViewModelCallback( 24 private val old: List<MediaControlViewModel>, 25 private val new: List<MediaControlViewModel>, 26 ) : DiffUtil.Callback() { 27 getOldListSizenull28 override fun getOldListSize(): Int { 29 return old.size 30 } 31 getNewListSizenull32 override fun getNewListSize(): Int { 33 return new.size 34 } 35 areItemsTheSamenull36 override fun areItemsTheSame(oldIndex: Int, newIndex: Int): Boolean { 37 val oldItem = old[oldIndex] 38 val newItem = new[newIndex] 39 return oldItem.instanceId == newItem.instanceId 40 } 41 areContentsTheSamenull42 override fun areContentsTheSame(oldIndex: Int, newIndex: Int): Boolean { 43 val oldItem = old[oldIndex] 44 val newItem = new[newIndex] 45 return oldItem.updateTime == newItem.updateTime 46 } 47 } 48