1 package com.android.healthconnect.controller.shared 2 3 import androidx.preference.Preference 4 import androidx.preference.PreferenceManager 5 import com.android.healthconnect.controller.permissions.connectedapps.ComparablePreference 6 7 /** A {@link PreferenceComparisonCallback} to identify changed preferences. */ 8 class HealthPreferenceComparisonCallback : PreferenceManager.PreferenceComparisonCallback() { arePreferenceItemsTheSamenull9 override fun arePreferenceItemsTheSame( 10 oldPreference: Preference, 11 newPreference: Preference 12 ): Boolean { 13 return if (oldPreference is ComparablePreference) { 14 (oldPreference as ComparablePreference).isSameItem(newPreference) 15 } else comparePreference(oldPreference, newPreference) == 0 16 } 17 arePreferenceContentsTheSamenull18 override fun arePreferenceContentsTheSame( 19 oldPreference: Preference, 20 newPreference: Preference 21 ): Boolean { 22 return if (oldPreference is ComparablePreference) { 23 (oldPreference as ComparablePreference).hasSameContents(newPreference) 24 } else comparePreference(oldPreference, newPreference) == 0 25 } 26 comparePreferencenull27 private fun comparePreference(oldPreference: Preference, newPreference: Preference): Int { 28 return if (oldPreference.title == newPreference.title) { 29 0 30 } else if (oldPreference.title == null) { 31 1 32 } else { 33 -1 34 } 35 } 36 } 37