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.permissions.request 17 18 import android.content.Context 19 import android.util.AttributeSet 20 import android.widget.TextView 21 import androidx.preference.Preference 22 import androidx.preference.PreferenceViewHolder 23 import com.android.healthconnect.controller.R 24 import com.android.healthconnect.controller.utils.boldAppName 25 26 internal class AdditionalPermissionHeaderPreference 27 @JvmOverloads 28 constructor( 29 context: Context, 30 attrs: AttributeSet? = null, 31 defStyleAttr: Int = 0, 32 defStyleRes: Int = 0, 33 ) : Preference(context, attrs, defStyleAttr, defStyleRes) { 34 35 private lateinit var title: TextView 36 private var appName: String? = null 37 private var titleText = 0 38 39 private lateinit var summary: TextView 40 private var summaryText = "" 41 42 init { 43 layoutResource = R.layout.widget_request_additional_permission_header 44 isSelectable = false 45 } 46 onBindViewHoldernull47 override fun onBindViewHolder(holder: PreferenceViewHolder) { 48 super.onBindViewHolder(holder) 49 title = holder.findViewById(R.id.title) as TextView 50 summary = holder.findViewById(R.id.summary) as TextView 51 52 updateTitle() 53 updateSummary() 54 } 55 bindnull56 fun bind(titleText: Int, appName: String, summaryText: String) { 57 this.appName = appName 58 this.titleText = titleText 59 this.summaryText = summaryText 60 notifyChanged() 61 } 62 updateTitlenull63 private fun updateTitle() { 64 if (titleText != 0) { 65 val text = context.getString(titleText, appName) 66 title.text = boldAppName(appName, text) 67 } 68 } 69 updateSummarynull70 private fun updateSummary() { 71 summary.text = summaryText 72 } 73 } 74