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  * ```
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
17 
18 import android.content.Context
19 import android.health.connect.datatypes.MenstruationFlowRecord
20 import android.health.connect.datatypes.MenstruationFlowRecord.MenstruationFlowType.FLOW_HEAVY
21 import android.health.connect.datatypes.MenstruationFlowRecord.MenstruationFlowType.FLOW_LIGHT
22 import android.health.connect.datatypes.MenstruationFlowRecord.MenstruationFlowType.FLOW_MEDIUM
23 import com.android.healthconnect.controller.R
24 import com.android.healthconnect.controller.dataentries.formatters.shared.EntryFormatter
25 import com.android.healthconnect.controller.dataentries.units.UnitPreferences
26 import dagger.hilt.android.qualifiers.ApplicationContext
27 import javax.inject.Inject
28 
29 /** Formatter for printing MenstruationRecord data. */
30 class MenstruationFlowFormatter
31 @Inject
32 constructor(@ApplicationContext private val context: Context) :
33     EntryFormatter<MenstruationFlowRecord>(context) {
34 
formatValuenull35     override suspend fun formatValue(
36         record: MenstruationFlowRecord,
37         unitPreferences: UnitPreferences
38     ): String {
39         return when (record.flow) {
40             FLOW_LIGHT -> return context.getString(R.string.flow_light)
41             FLOW_MEDIUM -> return context.getString(R.string.flow_medium)
42             FLOW_HEAVY -> return context.getString(R.string.flow_heavy)
43             else -> {
44                 ""
45             }
46         }
47     }
48 
formatA11yValuenull49     override suspend fun formatA11yValue(
50         record: MenstruationFlowRecord,
51         unitPreferences: UnitPreferences
52     ): String {
53         return formatValue(record, unitPreferences)
54     }
55 }
56