From 3cc7a72b3df2df3760c30d2219f8c63a716157e3 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 4 Apr 2021 09:20:02 +0200 Subject: [PATCH] Fix XXXValueWithUnit Refactoring --- .../androidaps/plugins/general/food/FoodFragment.kt | 4 ++-- .../src/main/java/info/nightscout/androidaps/Constants.java | 6 +++--- .../androidaps/utils/UserEntryPresentationHelper.kt | 6 +----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt index c7da926edd..848bd3f043 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodFragment.kt @@ -18,7 +18,7 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.Food import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources -import info.nightscout.androidaps.database.entities.XXXValueWithUnit +import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction import info.nightscout.androidaps.databinding.FoodFragmentBinding import info.nightscout.androidaps.databinding.FoodItemBinding @@ -77,7 +77,7 @@ class FoodFragment : DaggerFragment() { context?.let { context -> OKDialog.showConfirmation(context, resourceHelper.gs(R.string.refresheventsfromnightscout) + " ?", { uel.log(Action.FOOD, Sources.Food, - XXXValueWithUnit.StringResource(R.string.refresheventsfromnightscout)) + ValueWithUnit.StringResource(R.string.refresheventsfromnightscout)) disposable += Completable.fromAction { repository.deleteAllFoods() } .subscribeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.main) diff --git a/core/src/main/java/info/nightscout/androidaps/Constants.java b/core/src/main/java/info/nightscout/androidaps/Constants.java index 32421893ce..5d3e4cf6a8 100644 --- a/core/src/main/java/info/nightscout/androidaps/Constants.java +++ b/core/src/main/java/info/nightscout/androidaps/Constants.java @@ -1,14 +1,14 @@ package info.nightscout.androidaps; -import info.nightscout.androidaps.database.entities.XXXValueWithUnit; +import info.nightscout.androidaps.database.entities.ValueWithUnit; import info.nightscout.androidaps.utils.T; /** * Created by mike on 07.06.2016. */ public class Constants { - public static final String MGDL = XXXValueWithUnit.MGDL; // This is Nightscout's representation - public static final String MMOL = XXXValueWithUnit.MMOL; + public static final String MGDL = ValueWithUnit.MGDL; // This is Nightscout's representation + public static final String MMOL = ValueWithUnit.MMOL; public static final double MMOLL_TO_MGDL = 18; // 18.0182; public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL; diff --git a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt index ca61f82f48..569f49c4af 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt @@ -184,10 +184,7 @@ class UserEntryPresentationHelper @Inject constructor( is ValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value) is ValueWithUnit.SimpleInt -> other = other.addWithSeparator(valueWithUnit.value) is ValueWithUnit.SimpleString -> other = other.addWithSeparator(valueWithUnit.value) -// is XXXValueWithUnit.StringResource -> stringResource = if (stringResource == "") resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map { it.value() }.toTypedArray()) else stringResource + " / " + resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map { it.value() }.toTypedArray()) - is ValueWithUnit.StringResource -> if (valueWithUnit.params.isEmpty()) { - stringResource = if (stringResource == "") resourceHelper.gs(valueWithUnit.value) else stringResource + " / " + resourceHelper.gs(valueWithUnit.value) - } + is ValueWithUnit.StringResource -> stringResource = stringResource.addWithSeparator(resourceHelper.gs(valueWithUnit.value, *(valueWithUnit.params.map { it.value() }.toTypedArray()))) is ValueWithUnit.TherapyEventMeterType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value)) is ValueWithUnit.TherapyEventTTReason -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value)) is ValueWithUnit.TherapyEventType -> therapyEvent = therapyEvent.addWithSeparator(translator.translate(valueWithUnit.value)) @@ -213,7 +210,6 @@ class UserEntryPresentationHelper @Inject constructor( return "$timestampRec;$dateTimestampRev;$utcOffset;$action;$therapyEvent;$source;$note;$stringResource;$timestamp;$bg;$gram;$insulin;$unitPerHour;$percent;$hour;$minute;$other" } - private fun saveString(id: Int): String = if (id != 0) resourceHelper.gs(id) else "" private fun csvString(action: Action): String = "\"" + translator.translate(action).replace("\"", "\"\"") + "\"" private fun csvString(id: Int): String = if (id != 0) "\"" + resourceHelper.gs(id).replace("\"", "\"\"") + "\"" else "" private fun csvString(s: String): String = if (s != "") "\"" + s.replace("\"", "\"\"") + "\"" else ""