Skip to content

Commit

Permalink
Fix lighterpack weight format
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Jul 20, 2024
1 parent c4265c7 commit 9b48147
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit 9b48147

Please sign in to comment.