From 1d1359dfd4adbd20a1d9c6118fa0e41ed24191c7 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sun, 20 Dec 2020 19:54:54 +0100 Subject: [PATCH 1/7] TT Dialog Add 5 buttons for quick selection of TempTarget --- .../androidaps/dialogs/TempTargetDialog.kt | 44 +++++++++++++++---- .../main/res/drawable/ic_target_activity.xml | 18 ++++++++ .../main/res/drawable/ic_target_cancel.xml | 15 +++++++ .../res/drawable/ic_target_eatingsoon.xml | 21 +++++++++ app/src/main/res/drawable/ic_target_hypo.xml | 21 +++++++++ .../main/res/drawable/ic_target_manual.xml | 15 +++++++ app/src/main/res/layout/dialog_temptarget.xml | 42 ++++++++++++++++++ app/src/main/res/values/colors.xml | 1 + icons/target_activity.svg | 43 ++++++++++++++++++ icons/target_cancel.svg | 28 ++++++++++++ icons/target_eatingsoon.svg | 38 ++++++++++++++++ icons/target_hypo.svg | 34 ++++++++++++++ icons/target_manual.svg | 37 ++++++++++++++++ 13 files changed, 348 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/drawable/ic_target_activity.xml create mode 100644 app/src/main/res/drawable/ic_target_cancel.xml create mode 100644 app/src/main/res/drawable/ic_target_eatingsoon.xml create mode 100644 app/src/main/res/drawable/ic_target_hypo.xml create mode 100644 app/src/main/res/drawable/ic_target_manual.xml create mode 100644 icons/target_activity.svg create mode 100644 icons/target_cancel.svg create mode 100644 icons/target_eatingsoon.svg create mode 100644 icons/target_hypo.svg create mode 100644 icons/target_manual.svg diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index 9bdf58287f..fc3b910602 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -65,14 +65,14 @@ class TempTargetDialog : DialogFragmentWithDate() { val units = profileFunction.getUnits() overview_temptarget_units.text = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) // temp target + val reasonList: List = Lists.newArrayList( + resourceHelper.gs(R.string.manual), + resourceHelper.gs(R.string.cancel), + resourceHelper.gs(R.string.eatingsoon), + resourceHelper.gs(R.string.activity), + resourceHelper.gs(R.string.hypo) + ) context?.let { context -> - val reasonList: List = Lists.newArrayList( - resourceHelper.gs(R.string.manual), - resourceHelper.gs(R.string.cancel), - resourceHelper.gs(R.string.eatingsoon), - resourceHelper.gs(R.string.activity), - resourceHelper.gs(R.string.hypo) - ) val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList) overview_temptarget_reason.adapter = adapterReason overview_temptarget_reason.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { @@ -101,8 +101,8 @@ class TempTargetDialog : DialogFragmentWithDate() { } else -> { - defaultDuration = overview_temptarget_duration.value - defaultTarget = overview_temptarget_temptarget.value + defaultDuration = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 + defaultTarget = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL } } overview_temptarget_temptarget.value = defaultTarget @@ -112,6 +112,32 @@ class TempTargetDialog : DialogFragmentWithDate() { override fun onNothingSelected(parent: AdapterView<*>?) {} } } + + overview_temptarget_custom?.setOnClickListener { + overview_temptarget_temptarget.value = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL + overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.manual))); + } + overview_temptarget_cancel?.setOnClickListener { + overview_temptarget_temptarget.value = 0.0 + overview_temptarget_duration.value = 0.0 + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.cancel))); + } + overview_temptarget_eating_soon?.setOnClickListener { + overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT() + overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble() + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.eatingsoon))); + } + overview_temptarget_activity?.setOnClickListener { + overview_temptarget_temptarget.value = defaultValueHelper.determineActivityTT() + overview_temptarget_duration.value = defaultValueHelper.determineActivityTTDuration().toDouble() + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.activity))); + } + overview_temptarget_hypo?.setOnClickListener { + overview_temptarget_temptarget.value = defaultValueHelper.determineHypoTT() + overview_temptarget_duration.value = defaultValueHelper.determineHypoTTDuration().toDouble() + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.hypo))); + } } override fun submit(): Boolean { diff --git a/app/src/main/res/drawable/ic_target_activity.xml b/app/src/main/res/drawable/ic_target_activity.xml new file mode 100644 index 0000000000..4439597b75 --- /dev/null +++ b/app/src/main/res/drawable/ic_target_activity.xml @@ -0,0 +1,18 @@ + + + + + + diff --git a/app/src/main/res/drawable/ic_target_cancel.xml b/app/src/main/res/drawable/ic_target_cancel.xml new file mode 100644 index 0000000000..50d7304662 --- /dev/null +++ b/app/src/main/res/drawable/ic_target_cancel.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_target_eatingsoon.xml b/app/src/main/res/drawable/ic_target_eatingsoon.xml new file mode 100644 index 0000000000..54b6162546 --- /dev/null +++ b/app/src/main/res/drawable/ic_target_eatingsoon.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_target_hypo.xml b/app/src/main/res/drawable/ic_target_hypo.xml new file mode 100644 index 0000000000..30721cbf14 --- /dev/null +++ b/app/src/main/res/drawable/ic_target_hypo.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/drawable/ic_target_manual.xml b/app/src/main/res/drawable/ic_target_manual.xml new file mode 100644 index 0000000000..fc41c52757 --- /dev/null +++ b/app/src/main/res/drawable/ic_target_manual.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index f770f8ba98..9db270caad 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -71,6 +71,48 @@ + + + + + + + + + + + + + + #77dd77 #77dd77 + #67DFE8 #779ECB diff --git a/icons/target_activity.svg b/icons/target_activity.svg new file mode 100644 index 0000000000..2fb2409888 --- /dev/null +++ b/icons/target_activity.svg @@ -0,0 +1,43 @@ + + + + + + + + + diff --git a/icons/target_cancel.svg b/icons/target_cancel.svg new file mode 100644 index 0000000000..894110a14c --- /dev/null +++ b/icons/target_cancel.svg @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/icons/target_eatingsoon.svg b/icons/target_eatingsoon.svg new file mode 100644 index 0000000000..3ef25775bf --- /dev/null +++ b/icons/target_eatingsoon.svg @@ -0,0 +1,38 @@ + + + + + + + + + + diff --git a/icons/target_hypo.svg b/icons/target_hypo.svg new file mode 100644 index 0000000000..cc9585c5ba --- /dev/null +++ b/icons/target_hypo.svg @@ -0,0 +1,34 @@ + + + + + + + + + + diff --git a/icons/target_manual.svg b/icons/target_manual.svg new file mode 100644 index 0000000000..08b51538b3 --- /dev/null +++ b/icons/target_manual.svg @@ -0,0 +1,37 @@ + + + + + + + + From 43386055715e41e5d1e93052079b7d4dee70e7cb Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 21 Dec 2020 15:20:35 +0100 Subject: [PATCH 2/7] Add label below icons --- app/src/main/res/layout/dialog_temptarget.xml | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index 9db270caad..06b6513a14 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -76,40 +76,70 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - + android:drawableTop="@drawable/ic_target_manual" + android:text="@string/manual" + android:textColor="@color/tempTargetConfirmation" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:textSize="12sp" /> - + android:drawableTop="@drawable/ic_target_cancel" + android:text="@string/cancel" + android:textColor="@color/tempTargetConfirmation" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:textSize="12sp" /> - + android:drawableTop="@drawable/ic_target_eatingsoon" + android:text="@string/eatingsoon" + android:textColor="@color/carbs" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:textSize="12sp" /> - + android:drawableTop="@drawable/ic_target_activity" + android:text="@string/activity" + android:textColor="@color/exercise" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:textSize="12sp" /> - + android:drawableTop="@drawable/ic_target_hypo" + android:text="@string/hypo" + android:textColor="@color/low" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:textSize="12sp" /> From ffb5a7cd4a52cd777b1f4b1e5fcf937923ed3f8f Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 21 Dec 2020 21:03:30 +0100 Subject: [PATCH 3/7] Spinner removed and Confirm dialog if click on Cancel to Hypo buttons --- .../androidaps/dialogs/TempTargetDialog.kt | 65 ++++--------------- app/src/main/res/layout/dialog_temptarget.xml | 23 ------- 2 files changed, 12 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index fc3b910602..83d140fde0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -33,6 +33,8 @@ class TempTargetDialog : DialogFragmentWithDate() { @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + var reason = "" + override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) savedInstanceState.putDouble("overview_temptarget_duration", overview_temptarget_duration.value) @@ -64,85 +66,42 @@ class TempTargetDialog : DialogFragmentWithDate() { val units = profileFunction.getUnits() overview_temptarget_units.text = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) - // temp target - val reasonList: List = Lists.newArrayList( - resourceHelper.gs(R.string.manual), - resourceHelper.gs(R.string.cancel), - resourceHelper.gs(R.string.eatingsoon), - resourceHelper.gs(R.string.activity), - resourceHelper.gs(R.string.hypo) - ) - context?.let { context -> - val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList) - overview_temptarget_reason.adapter = adapterReason - overview_temptarget_reason.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - val defaultDuration: Double - val defaultTarget: Double - when (reasonList[position]) { - resourceHelper.gs(R.string.eatingsoon) -> { - defaultDuration = defaultValueHelper.determineEatingSoonTTDuration().toDouble() - defaultTarget = defaultValueHelper.determineEatingSoonTT() - } - resourceHelper.gs(R.string.activity) -> { - defaultDuration = defaultValueHelper.determineActivityTTDuration().toDouble() - defaultTarget = defaultValueHelper.determineActivityTT() - } - - resourceHelper.gs(R.string.hypo) -> { - defaultDuration = defaultValueHelper.determineHypoTTDuration().toDouble() - defaultTarget = defaultValueHelper.determineHypoTT() - } - - resourceHelper.gs(R.string.cancel) -> { - defaultDuration = 0.0 - defaultTarget = 0.0 - } - - else -> { - defaultDuration = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 - defaultTarget = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL - } - } - overview_temptarget_temptarget.value = defaultTarget - overview_temptarget_duration.value = defaultDuration - } - - override fun onNothingSelected(parent: AdapterView<*>?) {} - } - } + reason = resourceHelper.gs(R.string.manual) overview_temptarget_custom?.setOnClickListener { overview_temptarget_temptarget.value = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 - overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.manual))); + reason = resourceHelper.gs(R.string.manual) } overview_temptarget_cancel?.setOnClickListener { overview_temptarget_temptarget.value = 0.0 overview_temptarget_duration.value = 0.0 - overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.cancel))); + reason = resourceHelper.gs(R.string.cancel) + if (submit()) dismiss() } overview_temptarget_eating_soon?.setOnClickListener { overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT() overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble() - overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.eatingsoon))); + reason = resourceHelper.gs(R.string.eatingsoon) + if (submit()) dismiss() } overview_temptarget_activity?.setOnClickListener { overview_temptarget_temptarget.value = defaultValueHelper.determineActivityTT() overview_temptarget_duration.value = defaultValueHelper.determineActivityTTDuration().toDouble() - overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.activity))); + reason = resourceHelper.gs(R.string.activity) + if (submit()) dismiss() } overview_temptarget_hypo?.setOnClickListener { overview_temptarget_temptarget.value = defaultValueHelper.determineHypoTT() overview_temptarget_duration.value = defaultValueHelper.determineHypoTTDuration().toDouble() - overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.hypo))); + reason = resourceHelper.gs(R.string.hypo) + if (submit()) dismiss() } } override fun submit(): Boolean { val actions: LinkedList = LinkedList() - val reason = overview_temptarget_reason?.selectedItem?.toString() ?: return false val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol val target = overview_temptarget_temptarget.value val duration = overview_temptarget_duration.value.toInt() diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index 06b6513a14..357121213c 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -48,29 +48,6 @@ android:orientation="horizontal" android:padding="5dp" /> - - - - - - - - Date: Tue, 22 Dec 2020 10:27:38 +0100 Subject: [PATCH 4/7] Improve buttons size, padding and text size for long words --- app/src/main/res/layout/dialog_temptarget.xml | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index 357121213c..147a172b05 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -56,67 +56,76 @@ + android:textSize="11sp" /> + android:textSize="11sp" /> + android:textSize="11sp" /> + android:textSize="11sp" /> + android:textSize="11sp" /> From ef1fa6b7d1d3d341c30b4860e8ba5c6579f23e3d Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 22 Dec 2020 11:15:31 +0100 Subject: [PATCH 5/7] Long Click to fill parameters Not sure code is optimum but it works... --- .../androidaps/dialogs/TempTargetDialog.kt | 68 +++++++++++++------ 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index 83d140fde0..fcaf42cffa 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -74,29 +74,57 @@ class TempTargetDialog : DialogFragmentWithDate() { overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 reason = resourceHelper.gs(R.string.manual) } - overview_temptarget_cancel?.setOnClickListener { - overview_temptarget_temptarget.value = 0.0 - overview_temptarget_duration.value = 0.0 - reason = resourceHelper.gs(R.string.cancel) - if (submit()) dismiss() + + overview_temptarget_cancel?.setOnClickListener { shortClick(it) } + overview_temptarget_eating_soon?.setOnClickListener { shortClick(it) } + overview_temptarget_activity?.setOnClickListener { shortClick(it) } + overview_temptarget_hypo?.setOnClickListener { shortClick(it) } + + overview_temptarget_cancel?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true } - overview_temptarget_eating_soon?.setOnClickListener { - overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT() - overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble() - reason = resourceHelper.gs(R.string.eatingsoon) - if (submit()) dismiss() + overview_temptarget_eating_soon?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true } - overview_temptarget_activity?.setOnClickListener { - overview_temptarget_temptarget.value = defaultValueHelper.determineActivityTT() - overview_temptarget_duration.value = defaultValueHelper.determineActivityTTDuration().toDouble() - reason = resourceHelper.gs(R.string.activity) - if (submit()) dismiss() + overview_temptarget_activity?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true } - overview_temptarget_hypo?.setOnClickListener { - overview_temptarget_temptarget.value = defaultValueHelper.determineHypoTT() - overview_temptarget_duration.value = defaultValueHelper.determineHypoTTDuration().toDouble() - reason = resourceHelper.gs(R.string.hypo) - if (submit()) dismiss() + overview_temptarget_hypo?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true + } + } + + private fun shortClick(v:View){ + v.performLongClick() + if (submit()) dismiss() + } + + private fun longClick(v:View) { + when (v.id) { + R.id.overview_temptarget_cancel -> { + overview_temptarget_temptarget.value = 0.0 + overview_temptarget_duration.value = 0.0 + reason = resourceHelper.gs(R.string.cancel) + } + R.id.overview_temptarget_eating_soon -> { + overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT() + overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble() + reason = resourceHelper.gs(R.string.eatingsoon) + } + R.id.overview_temptarget_activity -> { + overview_temptarget_temptarget.value = defaultValueHelper.determineActivityTT() + overview_temptarget_duration.value = defaultValueHelper.determineActivityTTDuration().toDouble() + reason = resourceHelper.gs(R.string.activity) + } + R.id.overview_temptarget_hypo -> { + overview_temptarget_temptarget.value = defaultValueHelper.determineHypoTT() + overview_temptarget_duration.value = defaultValueHelper.determineHypoTTDuration().toDouble() + reason = resourceHelper.gs(R.string.hypo) + } } } From c6e8f277c0f63e78dedd43f4063af9bfcc295d15 Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 23 Dec 2020 19:28:50 +0100 Subject: [PATCH 6/7] Manual button hidden, Cancel only if TT running, Spinner added Long Click removed for Cancel and Spinner don't update values --- .../androidaps/dialogs/TempTargetDialog.kt | 80 ++++++++++++------- app/src/main/res/layout/dialog_temptarget.xml | 24 ++++++ 2 files changed, 74 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index fcaf42cffa..b11d256efd 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -13,6 +13,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.db.Source import info.nightscout.androidaps.db.TempTarget +import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin @@ -32,8 +33,9 @@ class TempTargetDialog : DialogFragmentWithDate() { @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var treatmentsPlugin: TreatmentsPlugin + @Inject lateinit var activePlugin: ActivePluginProvider - var reason = "" + lateinit var reasonList: List override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) @@ -67,34 +69,51 @@ class TempTargetDialog : DialogFragmentWithDate() { val units = profileFunction.getUnits() overview_temptarget_units.text = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) - reason = resourceHelper.gs(R.string.manual) + // temp target + context?.let { context -> + if (activePlugin.activeTreatments.tempTargetFromHistory != null) + overview_temptarget_cancel?.visibility = View.VISIBLE + else + overview_temptarget_cancel?.visibility = View.GONE - overview_temptarget_custom?.setOnClickListener { - overview_temptarget_temptarget.value = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL - overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 - reason = resourceHelper.gs(R.string.manual) - } + reasonList = Lists.newArrayList( + resourceHelper.gs(R.string.manual), + resourceHelper.gs(R.string.eatingsoon), + resourceHelper.gs(R.string.activity), + resourceHelper.gs(R.string.hypo) + ) + val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList) + overview_temptarget_reason.adapter = adapterReason - overview_temptarget_cancel?.setOnClickListener { shortClick(it) } - overview_temptarget_eating_soon?.setOnClickListener { shortClick(it) } - overview_temptarget_activity?.setOnClickListener { shortClick(it) } - overview_temptarget_hypo?.setOnClickListener { shortClick(it) } + overview_temptarget_custom?.setOnClickListener { + overview_temptarget_temptarget.value = savedInstanceState?.getDouble("overview_temptarget_temptarget") ?: if (profileFunction.getUnits() == Constants.MMOL) Constants.MIN_TT_MMOL else Constants.MIN_TT_MGDL + overview_temptarget_duration.value = savedInstanceState?.getDouble("overview_temptarget_duration") ?: 0.0 + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.manual))); + } - overview_temptarget_cancel?.setOnLongClickListener { - longClick(it) - return@setOnLongClickListener true - } - overview_temptarget_eating_soon?.setOnLongClickListener { - longClick(it) - return@setOnLongClickListener true - } - overview_temptarget_activity?.setOnLongClickListener { - longClick(it) - return@setOnLongClickListener true - } - overview_temptarget_hypo?.setOnLongClickListener { - longClick(it) - return@setOnLongClickListener true + overview_temptarget_cancel?.setOnClickListener { shortClick(it) } + overview_temptarget_eating_soon?.setOnClickListener { shortClick(it) } + overview_temptarget_activity?.setOnClickListener { shortClick(it) } + overview_temptarget_hypo?.setOnClickListener { shortClick(it) } + /* + overview_temptarget_cancel?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true + } + + */ + overview_temptarget_eating_soon?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true + } + overview_temptarget_activity?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true + } + overview_temptarget_hypo?.setOnLongClickListener { + longClick(it) + return@setOnLongClickListener true + } } } @@ -108,28 +127,29 @@ class TempTargetDialog : DialogFragmentWithDate() { R.id.overview_temptarget_cancel -> { overview_temptarget_temptarget.value = 0.0 overview_temptarget_duration.value = 0.0 - reason = resourceHelper.gs(R.string.cancel) + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.cancel))) } R.id.overview_temptarget_eating_soon -> { overview_temptarget_temptarget.value = defaultValueHelper.determineEatingSoonTT() overview_temptarget_duration.value = defaultValueHelper.determineEatingSoonTTDuration().toDouble() - reason = resourceHelper.gs(R.string.eatingsoon) + overview_temptarget_reason.setSelection(reasonList.indexOf( resourceHelper.gs(R.string.eatingsoon))) } R.id.overview_temptarget_activity -> { overview_temptarget_temptarget.value = defaultValueHelper.determineActivityTT() overview_temptarget_duration.value = defaultValueHelper.determineActivityTTDuration().toDouble() - reason = resourceHelper.gs(R.string.activity) + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.activity))) } R.id.overview_temptarget_hypo -> { overview_temptarget_temptarget.value = defaultValueHelper.determineHypoTT() overview_temptarget_duration.value = defaultValueHelper.determineHypoTTDuration().toDouble() - reason = resourceHelper.gs(R.string.hypo) + overview_temptarget_reason.setSelection(reasonList.indexOf(resourceHelper.gs(R.string.hypo))) } } } override fun submit(): Boolean { val actions: LinkedList = LinkedList() + val reason = overview_temptarget_reason?.selectedItem?.toString() ?: return false val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol val target = overview_temptarget_temptarget.value val duration = overview_temptarget_duration.value.toInt() diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index 147a172b05..a31c587feb 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -66,6 +66,7 @@ android:text="@string/manual" android:textColor="@color/tempTargetConfirmation" android:textAppearance="@style/TextAppearance.AppCompat.Medium" + android:visibility="gone" android:textSize="11sp" /> + + + + + + + + From 87961430a2d2aa670277d27db4a07f7df8cb426f Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 23 Dec 2020 19:55:35 +0100 Subject: [PATCH 7/7] Move buttons below Time (best place I think) --- app/src/main/res/layout/dialog_temptarget.xml | 165 +++++++++--------- 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/app/src/main/res/layout/dialog_temptarget.xml b/app/src/main/res/layout/dialog_temptarget.xml index a31c587feb..1c723e1fd8 100644 --- a/app/src/main/res/layout/dialog_temptarget.xml +++ b/app/src/main/res/layout/dialog_temptarget.xml @@ -48,88 +48,6 @@ android:orientation="horizontal" android:padding="5dp" /> - - - - - - - - - - - - - - + + + + + + + + + + + + +