• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.healthconnect.controller.shared.preference
17 
18 import android.content.Context
19 import android.view.View
20 import androidx.preference.Preference
21 import androidx.preference.Preference.OnPreferenceClickListener
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.HealthConnectLoggerEntryPoint
25 import dagger.hilt.android.EntryPointAccessors
26 
27 internal object HealthPreferenceUtils {
initializeLoggernull28     fun initializeLogger(context: Context): HealthConnectLogger {
29         val hiltEntryPoint =
30             EntryPointAccessors.fromApplication(
31                 context.applicationContext,
32                 HealthConnectLoggerEntryPoint::class.java,
33             )
34         return hiltEntryPoint.logger()
35     }
36 
loggingPreferenceClickListenernull37     fun loggingPreferenceClickListener(
38         logger: HealthConnectLogger,
39         logName: ElementName,
40         onPreferenceClickListener: OnPreferenceClickListener?,
41     ): OnPreferenceClickListener = OnPreferenceClickListener {
42         logger.logInteraction(logName)
43         onPreferenceClickListener?.onPreferenceClick(it) ?: false
44     }
45 
loggingButtonClickListenernull46     fun loggingButtonClickListener(
47         logger: HealthConnectLogger,
48         logName: ElementName,
49         onClickListener: View.OnClickListener?,
50     ): View.OnClickListener =
51         View.OnClickListener {
52             logger.logInteraction(logName)
53             onClickListener?.onClick(it)
54         }
55 
isSameItemnull56     fun isSameItem(preference1: Preference, preference2: Preference): Boolean {
57         return preference1 === preference2
58     }
59 
hasSameContentsnull60     fun hasSameContents(preference1: Preference, preference2: Preference): Boolean {
61         return preference1::class == preference2::class &&
62             preference1.title == preference2.title &&
63             preference1.summary == preference2.summary &&
64             preference1.icon == preference2.icon &&
65             preference1.isEnabled == preference2.isEnabled
66     }
67 }
68