1 /**
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package com.android.healthconnect.controller.entrydetails
15 
16 import android.view.LayoutInflater
17 import android.view.View
18 import android.view.ViewGroup
19 import android.widget.TextView
20 import com.android.healthconnect.controller.R
21 import com.android.healthconnect.controller.data.entries.FormattedEntry.FormattedSectionContent
22 import com.android.healthconnect.controller.shared.recyclerview.ViewBinder
23 import com.android.healthconnect.controller.utils.logging.EntryDetailsElement
24 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger
25 import com.android.healthconnect.controller.utils.logging.HealthConnectLoggerEntryPoint
26 import dagger.hilt.android.EntryPointAccessors
27 
28 class FormattedSectionContentViewBinder : ViewBinder<FormattedSectionContent, View> {
29     private lateinit var logger: HealthConnectLogger
30 
newViewnull31     override fun newView(parent: ViewGroup): View {
32         val context = parent.context.applicationContext
33         val hiltEntryPoint =
34             EntryPointAccessors.fromApplication(context, HealthConnectLoggerEntryPoint::class.java)
35         logger = hiltEntryPoint.logger()
36         return LayoutInflater.from(parent.context)
37             .inflate(R.layout.item_data_entry_content, parent, false)
38     }
39 
bindnull40     override fun bind(view: View, data: FormattedSectionContent, index: Int) {
41         val title = view.findViewById<TextView>(R.id.item_data_entry_content)
42 
43         title.text =
44             if (data.bulleted) {
45                 title.setPaddingRelative(
46                     view.context.resources.getDimension(R.dimen.spacing_small).toInt(),
47                     /* top= */ 0,
48                     /* end= */ 0,
49                     /* bottom= */ 0)
50                 view.context.getString(R.string.bulleted_content, data.title)
51             } else {
52                 data.title
53             }
54         title.contentDescription = data.title
55         logger.logImpression(EntryDetailsElement.FORMATTED_SECTION_CONTENT_VIEW)
56     }
57 }
58