From dc1706fde774ef75ed089da5457c0f8f33560796 Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 17 Feb 2022 22:26:12 +0100 Subject: [PATCH] Add TT Icon + Improve IOB/COB --- .../androidaps/dialogs/WizardDialog.kt | 22 ++++++++++++++----- .../main/res/drawable/cb_background_tt.xml | 7 ++++++ .../main/res/drawable/checkbox_tt_icon.xml | 4 ++++ app/src/main/res/layout/dialog_wizard.xml | 14 ++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/cb_background_tt.xml create mode 100644 app/src/main/res/drawable/checkbox_tt_icon.xml diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 83aff0201f..d04d8c709a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -175,9 +175,10 @@ class WizardDialog : DaggerDialogFragment() { dismiss() } binding.bgCheckboxIcon.setOnClickListener { binding.bgCheckbox.isChecked = !binding.bgCheckbox.isChecked } + binding.ttCheckboxIcon.setOnClickListener { binding.ttCheckbox.isChecked = !binding.ttCheckbox.isChecked } binding.trendCheckboxIcon.setOnClickListener { binding.bgTrendCheckbox.isChecked = !binding.bgTrendCheckbox.isChecked } binding.cobCheckboxIcon.setOnClickListener { binding.cobCheckbox.isChecked = !binding.cobCheckbox.isChecked; processCobCheckBox(); } - binding.iobCheckboxIcon.setOnClickListener { if (!binding.cobCheckbox.isChecked) binding.iobCheckbox.isChecked = !binding.iobCheckbox.isChecked } + binding.iobCheckboxIcon.setOnClickListener { binding.iobCheckbox.isChecked = !binding.iobCheckbox.isChecked; processIobCheckBox(); } // cancel button binding.okcancel.cancel.setOnClickListener { aapsLogger.debug(LTag.APS, "Dialog canceled: ${this.javaClass.name}") @@ -265,35 +266,42 @@ class WizardDialog : DaggerDialogFragment() { private fun onCheckedChanged(buttonView: CompoundButton, @Suppress("UNUSED_PARAMETER") state: Boolean) { saveCheckedStates() binding.ttCheckbox.isEnabled = binding.bgCheckbox.isChecked && repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() is ValueWrapper.Existing + binding.ttCheckboxIcon.visibility = binding.ttCheckbox.isEnabled.toVisibility() if (buttonView.id == binding.cobCheckbox.id) processCobCheckBox() + if (buttonView.id == binding.iobCheckbox.id) + processIobCheckBox() processEnabledIcons() calculateInsulin() } private fun processCobCheckBox() { if (binding.cobCheckbox.isChecked) { - binding.iobCheckbox.isEnabled = false - binding.iobCheckboxIcon.isEnabled = false binding.iobCheckbox.isChecked = true - } else { - binding.iobCheckbox.isEnabled = true - binding.iobCheckboxIcon.isEnabled = true + } + } + + private fun processIobCheckBox() { + if (!binding.iobCheckbox.isChecked) { + binding.cobCheckbox.isChecked = false } } private fun processEnabledIcons() { binding.bgCheckboxIcon.isChecked = binding.bgCheckbox.isChecked + binding.ttCheckboxIcon.isChecked = binding.ttCheckbox.isChecked binding.trendCheckboxIcon.isChecked = binding.bgTrendCheckbox.isChecked binding.iobCheckboxIcon.isChecked = binding.iobCheckbox.isChecked binding.cobCheckboxIcon.isChecked = binding.cobCheckbox.isChecked binding.bgCheckboxIcon.alpha = if (binding.bgCheckbox.isChecked) 1.0f else 0.2f + binding.ttCheckboxIcon.alpha = if (binding.ttCheckbox.isChecked) 1.0f else 0.2f binding.trendCheckboxIcon.alpha = if (binding.bgTrendCheckbox.isChecked) 1.0f else 0.2f binding.iobCheckboxIcon.alpha = if (binding.iobCheckbox.isChecked) 1.0f else 0.2f binding.cobCheckboxIcon.alpha = if (binding.cobCheckbox.isChecked) 1.0f else 0.2f binding.bgCheckboxIcon.visibility = binding.calculationCheckbox.isChecked.not().toVisibility() + binding.ttCheckboxIcon.visibility = (binding.calculationCheckbox.isChecked.not() && binding.ttCheckbox.isEnabled).toVisibility() binding.trendCheckboxIcon.visibility = binding.calculationCheckbox.isChecked.not().toVisibility() binding.iobCheckboxIcon.visibility = binding.calculationCheckbox.isChecked.not().toVisibility() binding.cobCheckboxIcon.visibility = binding.calculationCheckbox.isChecked.not().toVisibility() @@ -345,7 +353,9 @@ class WizardDialog : DaggerDialogFragment() { // Set BG if not old binding.bgInput.value = iobCobCalculator.ads.actualBg()?.valueToUnits(units) ?: 0.0 + binding.ttCheckbox.isEnabled = repository.getTemporaryTargetActiveAt(dateUtil.now()).blockingGet() is ValueWrapper.Existing + binding.ttCheckboxIcon.visibility = binding.ttCheckbox.isEnabled.toVisibility() // IOB calculation val bolusIob = iobCobCalculator.calculateIobFromBolus().round() diff --git a/app/src/main/res/drawable/cb_background_tt.xml b/app/src/main/res/drawable/cb_background_tt.xml new file mode 100644 index 0000000000..291b9f535e --- /dev/null +++ b/app/src/main/res/drawable/cb_background_tt.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/drawable/checkbox_tt_icon.xml b/app/src/main/res/drawable/checkbox_tt_icon.xml new file mode 100644 index 0000000000..2c3522ae2b --- /dev/null +++ b/app/src/main/res/drawable/checkbox_tt_icon.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/layout/dialog_wizard.xml b/app/src/main/res/layout/dialog_wizard.xml index 108808e800..d228923681 100644 --- a/app/src/main/res/layout/dialog_wizard.xml +++ b/app/src/main/res/layout/dialog_wizard.xml @@ -263,6 +263,20 @@ android:checked="true" android:contentDescription="@string/treatments_wizard_bg_label" /> + +