• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 com.android.healthconnect.controller.shared.preference
17 
18 import android.content.Context
19 import android.util.AttributeSet
20 import androidx.preference.Preference
21 import com.android.healthconnect.controller.permissions.connectedapps.ComparablePreference
22 import com.android.healthconnect.controller.utils.logging.ElementName
23 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger
24 import com.android.healthconnect.controller.utils.logging.UnknownGenericElement
25 
26 /** A [Preference] that allows logging. */
27 open class HealthPreference
28 @JvmOverloads
29 constructor(context: Context, attrs: AttributeSet? = null) :
30     Preference(context, attrs), ComparablePreference {
31 
32     private var logger: HealthConnectLogger = HealthPreferenceUtils.initializeLogger(context)
33     var logName: ElementName = UnknownGenericElement.UNKNOWN_HEALTH_PREFERENCE
34 
onAttachednull35     override fun onAttached() {
36         super.onAttached()
37         logger.logImpression(logName)
38     }
39 
setOnPreferenceClickListenernull40     override fun setOnPreferenceClickListener(
41         onPreferenceClickListener: OnPreferenceClickListener?
42     ) {
43         super.setOnPreferenceClickListener(
44             HealthPreferenceUtils.loggingPreferenceClickListener(
45                 logger,
46                 logName,
47                 onPreferenceClickListener,
48             )
49         )
50     }
51 
isSameItemnull52     override fun isSameItem(preference: Preference): Boolean =
53         HealthPreferenceUtils.isSameItem(preference, this)
54 
55     override fun hasSameContents(preference: Preference): Boolean =
56         HealthPreferenceUtils.hasSameContents(preference, this)
57 }
58