From 9b4814747b59793ab4489f1f8645f61729d6cb66 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 20 Jul 2024 07:12:28 -0400 Subject: [PATCH] Fix lighterpack weight format --- .../packs/infrastructure/LighterPackIOService.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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),