mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Fix duplicated weight conversion
This commit is contained in:
+2
-2
@@ -200,8 +200,8 @@ public class WeightChartFragment extends AbstractChartFragment<WeightChartFragme
|
||||
return (float) WeightUnit.Companion.convertWeight(weight, weightUnit);
|
||||
}
|
||||
|
||||
private String formatWeight(float weight) {
|
||||
return WeightUnit.Companion.formatWeight(requireContext(), weight, weightUnit);
|
||||
private String formatWeight(float convertedWeight) {
|
||||
return WeightUnit.Companion.formatConvertedWeight(requireContext(), convertedWeight, weightUnit);
|
||||
}
|
||||
|
||||
protected static class WeightChartsData extends DefaultChartsData<LineData> {
|
||||
|
||||
@@ -22,26 +22,29 @@ enum class WeightUnit {
|
||||
}
|
||||
|
||||
fun formatWeight(context: Context, kg: Double, target: WeightUnit): String {
|
||||
val convertedWeight = convertWeight(kg, target)
|
||||
return formatConvertedWeight(context, convertedWeight, target)
|
||||
}
|
||||
|
||||
fun formatConvertedWeight(context: Context, convertedWeight: Double, target: WeightUnit): String {
|
||||
return when (target) {
|
||||
JIN -> {
|
||||
val jin: Double = kg * 2
|
||||
context.getString(R.string.weight_scale_jin_format, jin)
|
||||
context.getString(R.string.weight_scale_jin_format, convertedWeight)
|
||||
}
|
||||
|
||||
POUND -> {
|
||||
val pound: Double = kg / 0.45359237
|
||||
context.getString(R.string.weight_scale_pound_format, pound)
|
||||
context.getString(R.string.weight_scale_pound_format, convertedWeight)
|
||||
}
|
||||
|
||||
STONE -> {
|
||||
val total: Int = (kg / 0.45359237).roundToInt()
|
||||
val stone: Int = total / 14
|
||||
val pound: Int = total % 14
|
||||
val totalPounds: Int = (convertedWeight * 14).roundToInt()
|
||||
val stone: Int = totalPounds / 14
|
||||
val pound: Int = totalPounds % 14
|
||||
context.getString(R.string.weight_scale_stone_format, stone, pound)
|
||||
}
|
||||
|
||||
KILOGRAM -> {
|
||||
context.getString(R.string.weight_scale_kilogram_format, kg)
|
||||
context.getString(R.string.weight_scale_kilogram_format, convertedWeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user