From 45c34c26779f1edbc49e9c82c928ff610a18bd18 Mon Sep 17 00:00:00 2001 From: osodebailar Date: Tue, 29 Mar 2022 13:14:05 +0200 Subject: [PATCH] Theme switcher preparation: gac for carbs, extbolus, boluswizard, profileviewer --- .../androidaps/dialogs/CarbsDialog.kt | 15 ++++++------ .../androidaps/dialogs/ExtendedBolusDialog.kt | 2 +- .../androidaps/utils/wizard/BolusWizard.kt | 23 ++++++++++--------- .../androidaps/dialogs/ProfileViewerDialog.kt | 12 +++++----- .../androidaps/extensions/HtmlString.kt | 5 ++++ core/src/main/res/values-night/styles.xml | 9 ++++++++ core/src/main/res/values/attrs.xml | 9 ++++++++ core/src/main/res/values/styles.xml | 9 ++++++++ 8 files changed, 59 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index ff4f64e0f4..59921a1611 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -234,8 +234,9 @@ class CarbsDialog : DialogFragmentWithDate() { if (activitySelected) actions.add( rh.gs(R.string.temptargetshort) + ": " + (DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + rh.gs(R.string.format_mins, activityTTDuration) + ")").formatColor( + context, rh, - R.color.tempTargetConfirmation + R.attr.tempTargetConfirmation ) ) val eatingSoonSelected = binding.eatingSoonTt.isChecked @@ -244,27 +245,27 @@ class CarbsDialog : DialogFragmentWithDate() { rh.gs(R.string.temptargetshort) + ": " + (DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + rh.gs( R.string.format_mins, eatingSoonTTDuration - ) + ")").formatColor(rh, R.color.tempTargetConfirmation) + ) + ")").formatColor(context, rh, R.attr.tempTargetConfirmation) ) val hypoSelected = binding.hypoTt.isChecked if (hypoSelected) actions.add( - rh.gs(R.string.temptargetshort) + ": " + (DecimalFormatter.to1Decimal(hypoTT) + " " + unitLabel + " (" + rh.gs(R.string.format_mins, hypoTTDuration) + ")").formatColor( + rh.gs(R.string.temptargetshort) + ": " + (DecimalFormatter.to1Decimal(hypoTT) + " " + unitLabel + " (" + rh.gs(R.string.format_mins, hypoTTDuration) + ")").formatColor( context, rh, - R.color.tempTargetConfirmation + R.attr.tempTargetConfirmation ) ) val timeOffset = binding.time.value.toInt() if (useAlarm && carbs > 0 && timeOffset > 0) - actions.add(rh.gs(R.string.alarminxmin, timeOffset).formatColor(rh, R.color.info)) + actions.add(rh.gs(R.string.alarminxmin, timeOffset).formatColor(context , rh, R.attr.infoColor)) val duration = binding.duration.value.toInt() if (duration > 0) actions.add(rh.gs(R.string.duration) + ": " + duration + rh.gs(R.string.shorthour)) if (carbsAfterConstraints > 0) { - actions.add(rh.gs(R.string.carbs) + ": " + "" + rh.gs(R.string.format_carbs, carbsAfterConstraints) + "") + actions.add(rh.gs(R.string.carbs) + ": " + "" + rh.gs(R.string.format_carbs, carbsAfterConstraints) + "") if (carbsAfterConstraints != carbs) - actions.add("" + rh.gs(R.string.carbsconstraintapplied) + "") + actions.add("" + rh.gs(R.string.carbsconstraintapplied) + "") } val notes = binding.notesLayout.notes.text.toString() if (notes.isNotEmpty()) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 7d4525bd8f..56e7856de9 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -93,7 +93,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { actions.add(rh.gs(R.string.formatinsulinunits, insulinAfterConstraint)) actions.add(rh.gs(R.string.duration) + ": " + rh.gs(R.string.format_mins, durationInMinutes)) if (abs(insulinAfterConstraint - insulin) > 0.01) - actions.add(rh.gs(R.string.constraintapllied).formatColor(rh, R.color.warning)) + actions.add(rh.gs(R.string.constraintapllied).formatColor(context, rh, R.attr.warningColor)) activity?.let { activity -> OKDialog.showConfirmation(activity, rh.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index dca32f246a..4b691ec932 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -300,12 +300,12 @@ class BolusWizard @Inject constructor( ) } - private fun confirmMessageAfterConstraints(advisor: Boolean): Spanned { + private fun confirmMessageAfterConstraints(context: Context, advisor: Boolean): Spanned { val actions: LinkedList = LinkedList() if (insulinAfterConstraints > 0) { val pct = if (percentageCorrection != 100) " ($percentageCorrection%)" else "" - actions.add(rh.gs(R.string.bolus) + ": " + rh.gs(R.string.formatinsulinunits, insulinAfterConstraints).formatColor(rh, R.color.bolus) + pct) + actions.add(rh.gs(R.string.bolus) + ": " + rh.gs(R.string.formatinsulinunits, insulinAfterConstraints).formatColor(context, rh, R.attr.bolusColor) + pct) } if (carbs > 0 && !advisor) { var timeShift = "" @@ -314,24 +314,25 @@ class BolusWizard @Inject constructor( } else if (carbTime < 0) { timeShift += " (" + rh.gs(R.string.mins, carbTime) + ")" } - actions.add(rh.gs(R.string.carbs) + ": " + rh.gs(R.string.format_carbs, carbs).formatColor(rh, R.color.carbs) + timeShift) + actions.add(rh.gs(R.string.carbs) + ": " + rh.gs(R.string.format_carbs, carbs).formatColor(context, rh, R.attr.carbsColor) + timeShift) } if (insulinFromCOB > 0) { actions.add( - rh.gs(R.string.cobvsiob) + ": " + rh.gs(R.string.formatsignedinsulinunits, insulinFromBolusIOB + insulinFromBasalIOB + insulinFromCOB + insulinFromBG).formatColor(rh, R.color.cobAlert) + rh.gs(R.string.cobvsiob) + ": " + rh.gs(R.string.formatsignedinsulinunits, insulinFromBolusIOB + insulinFromBasalIOB + insulinFromCOB + insulinFromBG).formatColor(context, rh, R.attr + .cobAlertColor) ) val absorptionRate = iobCobCalculator.ads.slowAbsorptionPercentage(60) if (absorptionRate > .25) - actions.add(rh.gs(R.string.slowabsorptiondetected, rh.gc(R.color.cobAlert), (absorptionRate * 100).toInt())) + actions.add(rh.gs(R.string.slowabsorptiondetected, rh.gac(context, R.attr.cobAlertColor), (absorptionRate * 100).toInt())) } if (abs(insulinAfterConstraints - calculatedTotalInsulin) > activePlugin.activePump.pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints)) - actions.add(rh.gs(R.string.bolusconstraintappliedwarn, calculatedTotalInsulin, insulinAfterConstraints).formatColor(rh, R.color.warning)) + actions.add(rh.gs(R.string.bolusconstraintappliedwarn, calculatedTotalInsulin, insulinAfterConstraints).formatColor(context, rh, R.attr.warningColor)) if (config.NSCLIENT && insulinAfterConstraints > 0) - actions.add(rh.gs(R.string.bolusrecordedonly).formatColor(rh, R.color.warning)) + actions.add(rh.gs(R.string.bolusrecordedonly).formatColor(context, rh, R.attr.warningColor)) if (useAlarm && !advisor && carbs > 0 && carbTime > 0) - actions.add(rh.gs(R.string.alarminxmin, carbTime).formatColor(rh, R.color.info)) + actions.add(rh.gs(R.string.alarminxmin, carbTime).formatColor(context, rh, R.attr.infoColor)) if (advisor) - actions.add(rh.gs(R.string.advisoralarm).formatColor(rh, R.color.info)) + actions.add(rh.gs(R.string.advisoralarm).formatColor(context, rh, R.attr.infoColor)) return HtmlHelper.fromHtml(Joiner.on("
").join(actions)) } @@ -360,7 +361,7 @@ class BolusWizard @Inject constructor( } private fun bolusAdvisorProcessing(ctx: Context) { - val confirmMessage = confirmMessageAfterConstraints(advisor = true) + val confirmMessage = confirmMessageAfterConstraints(ctx, advisor = true) OKDialog.showConfirmation(ctx, rh.gs(R.string.boluswizard), confirmMessage, { DetailedBolusInfo().apply { eventType = DetailedBolusInfo.EventType.CORRECTION_BOLUS @@ -417,7 +418,7 @@ class BolusWizard @Inject constructor( val profile = profileFunction.getProfile() ?: return val pump = activePlugin.activePump - val confirmMessage = confirmMessageAfterConstraints(advisor = false) + val confirmMessage = confirmMessageAfterConstraints(ctx, advisor = false) OKDialog.showConfirmation(ctx, rh.gs(R.string.boluswizard), confirmMessage, { if (insulinAfterConstraints > 0 || carbs > 0) { if (useSuperBolus) { diff --git a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt index ecb60ee2f5..2a174bf545 100644 --- a/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/core/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt @@ -206,20 +206,20 @@ class ProfileViewerDialog : DaggerDialogFragment() { } private fun formatColors(label: String, text1: String, text2: String, units: String): String { - var s = "$label" + var s = "$label" s += " " - s += "$text1" + s += "$text1" s += " " - s += "$text2" + s += "$text2" s += " " - s += "$units" + s += "$units" return s } private fun formatColors(text1: String, text2: String): String { - var s = "$text1" + var s = "$text1" s += "
" - s += "$text2" + s += "$text2" return s } diff --git a/core/src/main/java/info/nightscout/androidaps/extensions/HtmlString.kt b/core/src/main/java/info/nightscout/androidaps/extensions/HtmlString.kt index 56c6e6b46b..44b1f04c8a 100644 --- a/core/src/main/java/info/nightscout/androidaps/extensions/HtmlString.kt +++ b/core/src/main/java/info/nightscout/androidaps/extensions/HtmlString.kt @@ -1,5 +1,7 @@ package info.nightscout.androidaps.extensions +import android.content.Context +import androidx.annotation.AttrRes import androidx.annotation.ColorRes import info.nightscout.androidaps.utils.resources.ResourceHelper @@ -9,3 +11,6 @@ fun String.formatBold(): String = fun String.formatColor(rh: ResourceHelper, @ColorRes colorId: Int): String = "" + this + "" +fun String.formatColor(context: Context?, rh: ResourceHelper, @AttrRes attributeId: Int): String = + "" + this + "" + diff --git a/core/src/main/res/values-night/styles.xml b/core/src/main/res/values-night/styles.xml index 613af4dd46..65d6daa4fc 100644 --- a/core/src/main/res/values-night/styles.xml +++ b/core/src/main/res/values-night/styles.xml @@ -133,6 +133,15 @@ @color/ok_background @color/error_background + + @color/warning + + @color/white + + @color/tempbasal + @color/info + + @color/cobAlert