1 /**
2  * Copyright (C) 2023 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  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.dataentries.formatters.shared
17 
18 import android.content.Context
19 import android.health.connect.datatypes.Record
20 import com.android.healthconnect.controller.data.entries.FormattedEntry
21 import com.android.healthconnect.controller.data.entries.FormattedEntry.FormattedDataEntry
22 import com.android.healthconnect.controller.dataentries.units.UnitPreferences
23 
24 /** Abstract formatter for Records to Formatted Entries. */
25 abstract class EntryFormatter<T : Record>(context: Context) : BaseFormatter<T>(context) {
26 
formatRecordnull27     override suspend fun formatRecord(
28         record: T,
29         header: String,
30         headerA11y: String,
31         unitPreferences: UnitPreferences
32     ): FormattedEntry {
33         return FormattedDataEntry(
34             uuid = record.metadata.id,
35             header = header,
36             headerA11y = headerA11y,
37             title = formatValue(record, unitPreferences),
38             titleA11y = formatA11yValue(record, unitPreferences),
39             dataType = getDataType(record))
40     }
41 
formatValuenull42     abstract suspend fun formatValue(record: T, unitPreferences: UnitPreferences): String
43 
44     abstract suspend fun formatA11yValue(record: T, unitPreferences: UnitPreferences): String
45 }
46