diff --git a/Sources/ViewControllers/Products/Add/EditNutritiveValueView.swift b/Sources/ViewControllers/Products/Add/EditNutritiveValueView.swift index 63c5c1cbce..3cb41c1a5e 100644 --- a/Sources/ViewControllers/Products/Add/EditNutritiveValueView.swift +++ b/Sources/ViewControllers/Products/Add/EditNutritiveValueView.swift @@ -16,7 +16,7 @@ enum NutritiveUnits { case alcohol case none - func unitsValues() -> [String] { + public var unitsValues: [String] { switch self { case .kcal: return [ @@ -105,7 +105,7 @@ class EditNutritiveValueView: UIView { singleUnitLabel.isHidden = true unitButton.isHidden = true - let values = displayedUnit.unitsValues() + let values = displayedUnit.unitsValues selectedUnit = selectedValue ?? values.first if values.count == 1 { @@ -137,7 +137,7 @@ class EditNutritiveValueView: UIView { } @IBAction func unitButtonTapped(_ sender: Any) { - let values = displayedUnit.unitsValues() + let values = displayedUnit.unitsValues if values.count < 2 { // button should not be visible anyway ? diff --git a/Sources/ViewControllers/Products/Add/ProductAddViewController.swift b/Sources/ViewControllers/Products/Add/ProductAddViewController.swift index 0450a6d3b0..52a3c00088 100644 --- a/Sources/ViewControllers/Products/Add/ProductAddViewController.swift +++ b/Sources/ViewControllers/Products/Add/ProductAddViewController.swift @@ -593,6 +593,20 @@ class ProductAddViewController: TakePictureViewController { } } + private func unit(for nutriment: String) -> NutritiveUnits { + switch nutriment { + case OFFJson.EnergyKey: + return .kJoule + case OFFJson.EnergyKcalKey: + return .kcal + case OFFJson.AlcoholKey: + return .alcohol + case OFFJson.PhKey: + return .none + default: return .units + } + } + private func configureLanguageField() { let languages = dataManager.getLanguages() @@ -723,7 +737,10 @@ class ProductAddViewController: TakePictureViewController { } else { view.inputTextField.text = nil } - view.selectedUnit = nutriment.unit + // do not use the nutriment values as provided by the json, + // these are the original input values + // Use the standard values coresponding to the Nutriment. + view.selectedUnit = unit(for: nutriment.nameKey).unitsValues.first } } }