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.units 17 18 import androidx.annotation.StringRes 19 import com.android.healthconnect.controller.R 20 21 object UnitPreferencesStrings { 22 23 private val map = 24 mapOf( 25 DistanceUnit.KILOMETERS to R.string.distance_unit_kilometers_label, 26 DistanceUnit.MILES to R.string.distance_unit_miles_label, 27 HeightUnit.CENTIMETERS to R.string.height_unit_centimeters_label, 28 HeightUnit.FEET to R.string.height_unit_feet_label, 29 WeightUnit.POUND to R.string.weight_unit_pound_label, 30 WeightUnit.KILOGRAM to R.string.weight_unit_kilogram_label, 31 WeightUnit.STONE to R.string.weight_unit_stone_label, 32 EnergyUnit.CALORIE to R.string.energy_unit_calorie_label, 33 EnergyUnit.KILOJOULE to R.string.energy_unit_kilojoule_label, 34 TemperatureUnit.FAHRENHEIT to R.string.temperature_unit_fahrenheit_label, 35 TemperatureUnit.CELSIUS to R.string.temperature_unit_celsius_label, 36 TemperatureUnit.KELVIN to R.string.temperature_unit_kelvin_label, 37 ) 38 39 @StringRes getUnitLabelnull40 fun getUnitLabel(unit: UnitPreference): Int { 41 if (!map.containsKey(unit)) { 42 throw IllegalArgumentException("Unit $unit is not supported!") 43 } 44 return map[unit]!! 45 } 46 } 47