diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/packs/infrastructure/LighterPackIOService.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/packs/infrastructure/LighterPackIOService.kt index a70f0c5dc..fb34e791b 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/packs/infrastructure/LighterPackIOService.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/packs/infrastructure/LighterPackIOService.kt @@ -1,6 +1,5 @@ package com.kylecorry.trail_sense.tools.packs.infrastructure -import android.content.Context import com.kylecorry.andromeda.fragments.AndromedaFragment import com.kylecorry.luna.text.toDoubleCompat import com.kylecorry.sol.units.Weight @@ -111,12 +110,11 @@ class LighterPackIOService(uriPicker: UriPicker, uriService: UriService) : } private fun formatWeightUnit(unit: WeightUnits): String { - return unit.name.lowercase() + return weightUnitMap[unit] ?: "gram" } private fun parseWeightUnit(unit: String): WeightUnits { - return WeightUnits.entries.find { it.name.lowercase() == unit.lowercase() } - ?: WeightUnits.Grams + return weightUnitMap.entries.find { it.value == unit }?.key ?: WeightUnits.Grams } companion object { @@ -130,6 +128,13 @@ class LighterPackIOService(uriPicker: UriPicker, uriService: UriService) : private const val HEADER_PACKED_QUANTITY = "packed qty" private const val HEADER_DESIRED_QUANTITY = "desired qty" + private val weightUnitMap = mapOf( + WeightUnits.Grams to "gram", + WeightUnits.Kilograms to "kilogram", + WeightUnits.Ounces to "ounce", + WeightUnits.Pounds to "pound", + ) + fun create(fragment: AndromedaFragment): LighterPackIOService { return LighterPackIOService( FragmentUriPicker(fragment),