From 6d82ceacf91402ef7fbcd4d3f664855f51857b76 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 8 Dec 2019 01:03:49 +0100 Subject: [PATCH 1/3] Replace the text string in the code with MainApp.gs to allow translation For bg I leave a decimal. I tried to use valueToUnitsToString but I don't know how to get units from json (NS data I guess) and this method does not work (missing import?) On the JsonHelper object ... --- .../treatments/dialogs/WizardInfoDialog.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt index c65c75c00e..d7102104f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt @@ -6,9 +6,11 @@ import android.view.View import android.view.ViewGroup import android.view.WindowManager import androidx.fragment.app.DialogFragment +import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.JsonHelper +import info.nightscout.androidaps.utils.StringUtils import kotlinx.android.synthetic.main.treatments_wizardinfo_dialog.* import org.json.JSONObject @@ -32,32 +34,32 @@ class WizardInfoDialog : DialogFragment() { close.setOnClickListener { dismiss() } // BG - treatments_wizard_bg.text = DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg")) + " ISF: " + DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "isf")) - treatments_wizard_bginsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulinbg")) + "U" + treatments_wizard_bg.text = DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg")) + String.format(MainApp.gs(R.string.format_bg_isf), "" , JsonHelper.safeGetDouble(json, "isf")) + treatments_wizard_bginsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinbg")) treatments_wizard_bgcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "insulinbgused") treatments_wizard_ttcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "ttused") // Trend treatments_wizard_bgtrend.text = JsonHelper.safeGetString(json, "trend") - treatments_wizard_bgtrendinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulintrend")) + "U" + treatments_wizard_bgtrendinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulintrend")) treatments_wizard_bgtrendcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "trendused") // COB - treatments_wizard_cob.text = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "cob")) + "g IC: " + DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "ic")) - treatments_wizard_cobinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulincob")) + "U" + treatments_wizard_cob.text = String.format(MainApp.gs(R.string.format_cob_ic), JsonHelper.safeGetDouble(json, "cob"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincob")) treatments_wizard_cobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "cobused") // Bolus IOB - treatments_wizard_bolusiobinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "bolusiob")) + "U" + treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "bolusiob")) treatments_wizard_bolusiobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "bolusiobused") // Basal IOB - treatments_wizard_basaliobinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "basaliob")) + "U" + treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "basaliob")) treatments_wizard_basaliobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "basaliobused") // Superbolus - treatments_wizard_sbinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulinsuperbolus")) + "U" + treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinsuperbolus")) treatments_wizard_sbcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "superbolusused") // Carbs - treatments_wizard_carbs.text = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "carbs")) + "g IC: " + DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "ic")) - treatments_wizard_carbsinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulincarbs")) + "U" + treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), JsonHelper.safeGetDouble(json, "carbs"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincarbs")) // Correction - treatments_wizard_correctioninsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "othercorrection")) + "U" + treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "othercorrection")) // Profile treatments_wizard_profile.text = JsonHelper.safeGetString(json, "profile") // Notes @@ -65,6 +67,6 @@ class WizardInfoDialog : DialogFragment() { // Percentage treatments_wizard_percent_used.text = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "percentageCorrection", 100.0)) + "%" // Total - treatments_wizard_totalinsulin.text = DecimalFormatter.to2Decimal(JsonHelper.safeGetDouble(json, "insulin")) + "U" + treatments_wizard_totalinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulin")) } } From 9d22e177bbd88e56f543ad02afc3a232503240f3 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 8 Dec 2019 21:30:25 +0100 Subject: [PATCH 2/3] replaced String.format(MainApp.gs(xx), yy, zz) by MainApp.gs(xx, yy, zz) for bg, cob and carbs --- .../plugins/treatments/dialogs/WizardInfoDialog.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt index d7102104f5..ee68b02375 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt @@ -34,7 +34,7 @@ class WizardInfoDialog : DialogFragment() { close.setOnClickListener { dismiss() } // BG - treatments_wizard_bg.text = DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg")) + String.format(MainApp.gs(R.string.format_bg_isf), "" , JsonHelper.safeGetDouble(json, "isf")) + treatments_wizard_bg.text = MainApp.gs(R.string.format_bg_isf, JsonHelper.safeGetDouble(json, "bg") , JsonHelper.safeGetDouble(json, "isf")) treatments_wizard_bginsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinbg")) treatments_wizard_bgcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "insulinbgused") treatments_wizard_ttcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "ttused") @@ -43,7 +43,7 @@ class WizardInfoDialog : DialogFragment() { treatments_wizard_bgtrendinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulintrend")) treatments_wizard_bgtrendcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "trendused") // COB - treatments_wizard_cob.text = String.format(MainApp.gs(R.string.format_cob_ic), JsonHelper.safeGetDouble(json, "cob"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_cob.text = MainApp.gs(R.string.format_cob_ic, JsonHelper.safeGetDouble(json, "cob"), JsonHelper.safeGetDouble(json, "ic")) treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincob")) treatments_wizard_cobcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "cobused") // Bolus IOB @@ -56,7 +56,7 @@ class WizardInfoDialog : DialogFragment() { treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinsuperbolus")) treatments_wizard_sbcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "superbolusused") // Carbs - treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), JsonHelper.safeGetDouble(json, "carbs"), JsonHelper.safeGetDouble(json, "ic")) + treatments_wizard_carbs.text = MainApp.gs(R.string.format_carbs_ic, JsonHelper.safeGetDouble(json, "carbs"), JsonHelper.safeGetDouble(json, "ic")) treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulincarbs")) // Correction treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "othercorrection")) From d6c58fc35ca4148bd2376724e0a4cd2ac38673cb Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 9 Dec 2019 00:24:02 +0100 Subject: [PATCH 3/3] Set number of decimal for bg value according to unit --- .../plugins/treatments/dialogs/WizardInfoDialog.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt index ee68b02375..50bf9aa790 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/dialogs/WizardInfoDialog.kt @@ -8,6 +8,8 @@ import android.view.WindowManager import androidx.fragment.app.DialogFragment import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.StringUtils @@ -32,9 +34,11 @@ class WizardInfoDialog : DialogFragment() { super.onViewCreated(view, savedInstanceState) close.setOnClickListener { dismiss() } - + val units = ProfileFunctions.getSystemUnits() + var bg_string= "" + if (units.equals(Constants.MGDL)) { bg_string = DecimalFormatter.to0Decimal(JsonHelper.safeGetDouble(json, "bg"))} else { bg_string = DecimalFormatter.to1Decimal(JsonHelper.safeGetDouble(json, "bg"))} // BG - treatments_wizard_bg.text = MainApp.gs(R.string.format_bg_isf, JsonHelper.safeGetDouble(json, "bg") , JsonHelper.safeGetDouble(json, "isf")) + treatments_wizard_bg.text = MainApp.gs(R.string.format_bg_isf, bg_string , JsonHelper.safeGetDouble(json, "isf")) treatments_wizard_bginsulin.text = StringUtils.formatInsulin(JsonHelper.safeGetDouble(json, "insulinbg")) treatments_wizard_bgcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "insulinbgused") treatments_wizard_ttcheckbox.isChecked = JsonHelper.safeGetBoolean(json, "ttused")