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