1 /** 2 * Copyright (C) 2022 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.dataentries 15 16 import android.view.LayoutInflater 17 import android.view.View 18 import android.view.ViewGroup 19 import android.widget.ImageButton 20 import android.widget.TextView 21 import com.android.healthconnect.controller.R 22 import com.android.healthconnect.controller.data.entries.FormattedEntry.FormattedDataEntry 23 import com.android.healthconnect.controller.shared.recyclerview.ViewBinder 24 import com.android.healthconnect.controller.utils.logging.DataEntriesElement 25 import com.android.healthconnect.controller.utils.logging.HealthConnectLogger 26 import com.android.healthconnect.controller.utils.logging.HealthConnectLoggerEntryPoint 27 import dagger.hilt.android.EntryPointAccessors 28 29 /** ViewBinder for FormattedDataEntry. */ 30 class EntryItemViewBinder(private val onDeleteEntryListener: OnDeleteEntryListener) : 31 ViewBinder<FormattedDataEntry, View> { 32 33 private lateinit var logger: HealthConnectLogger 34 newViewnull35 override fun newView(parent: ViewGroup): View { 36 val context = parent.context.applicationContext 37 val hiltEntryPoint = 38 EntryPointAccessors.fromApplication( 39 context.applicationContext, HealthConnectLoggerEntryPoint::class.java) 40 logger = hiltEntryPoint.logger() 41 return LayoutInflater.from(parent.context).inflate(R.layout.item_data_entry, parent, false) 42 } 43 bindnull44 override fun bind(view: View, data: FormattedDataEntry, index: Int) { 45 val header = view.findViewById<TextView>(R.id.item_data_entry_header) 46 val title = view.findViewById<TextView>(R.id.item_data_entry_title) 47 val deleteButton = view.findViewById<ImageButton>(R.id.item_data_entry_delete) 48 logger.logImpression(DataEntriesElement.DATA_ENTRY_VIEW) 49 logger.logImpression(DataEntriesElement.DATA_ENTRY_DELETE_BUTTON) 50 51 title.text = data.title 52 title.contentDescription = data.titleA11y 53 54 header.text = data.header 55 header.contentDescription = data.headerA11y 56 57 deleteButton.contentDescription = 58 view.resources.getString( 59 R.string.data_point_action_content_description, data.headerA11y) 60 deleteButton.setOnClickListener { 61 logger.logInteraction(DataEntriesElement.DATA_ENTRY_DELETE_BUTTON) 62 onDeleteEntryListener.onDeleteEntry( 63 data.uuid, data.dataType, index, data.startTime, data.endTime) 64 } 65 } 66 } 67