From eed8aa8441acad74023cd2d7f7570de935b5cdbc Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 29 Oct 2021 17:35:40 +0200 Subject: [PATCH] fix NumberPicker in automation --- .../plugins/general/automation/elements/InputBg.kt | 8 ++++---- .../plugins/general/automation/elements/InputDelta.kt | 8 ++++---- .../plugins/general/automation/elements/InputDouble.kt | 8 ++++---- .../plugins/general/automation/elements/InputInsulin.kt | 9 ++++----- .../plugins/general/automation/elements/InputPercent.kt | 9 ++++----- .../general/automation/elements/InputTempTarget.kt | 8 ++++---- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt index 072149a64d..f54cd4aefe 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.kt @@ -28,10 +28,10 @@ class InputBg(profileFunction: ProfileFunction) : Element() { override fun addToLayout(root: LinearLayout) { root.addView( - NumberPicker(root.context, null).apply { - setParams(value, minValue, maxValue, step, decimalFormat, false, root.findViewById(R.id.ok)) - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + NumberPicker(root.context, null).also { + it.setParams(value, minValue, maxValue, step, decimalFormat, false, root.findViewById(R.id.ok)) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL }) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt index 8ce6f6de09..e6b4484f44 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDelta.kt @@ -81,10 +81,10 @@ class InputDelta(private val resourceHelper: ResourceHelper) : Element() { gravity = Gravity.CENTER_HORIZONTAL }) root.addView( - NumberPicker(root.context, null).apply { - setParams(value, minValue, maxValue, step, decimalFormat, true, null, null) - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + NumberPicker(root.context, null).also { + it.setParams(value, minValue, maxValue, step, decimalFormat, true, null, null) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL }) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt index 44fe1091b7..9d3e3f45c2 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.kt @@ -32,10 +32,10 @@ class InputDouble() : Element() { } override fun addToLayout(root: LinearLayout) { - numberPicker = NumberPicker(root.context, null).apply { - setParams(value, minValue, maxValue, step, decimalFormat, true, root.findViewById(R.id.ok)) - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + numberPicker = NumberPicker(root.context, null).also { + it.setParams(value, minValue, maxValue, step, decimalFormat, true, root.findViewById(R.id.ok)) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL } root.addView(numberPicker) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt index 94941ffa8d..4b394fdcfc 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulin.kt @@ -16,11 +16,10 @@ class InputInsulin() : Element() { override fun addToLayout(root: LinearLayout) { root.addView( - NumberPicker(root.context, null).apply { - setParams(0.0, -20.0, 20.0, 0.1, DecimalFormat("0.0"), true, root.findViewById(R.id.ok)) - value = value - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + NumberPicker(root.context, null).also { + it.setParams(value, -20.0, 20.0, 0.1, DecimalFormat("0.0"), true, root.findViewById(R.id.ok)) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL }) } } \ No newline at end of file diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt index d7077692b4..61cfd2b550 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercent.kt @@ -16,11 +16,10 @@ class InputPercent() : Element() { override fun addToLayout(root: LinearLayout) { root.addView( - NumberPicker(root.context, null).apply { - setParams(100.0, MIN, MAX, 5.0, DecimalFormat("0"), true, root.findViewById(R.id.ok)) - value = value - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + NumberPicker(root.context, null).also { + it.setParams(value, MIN, MAX, 5.0, DecimalFormat("0"), true, root.findViewById(R.id.ok)) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL }) } diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt index 444d92ba8a..474dda7c9c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.kt @@ -41,10 +41,10 @@ class InputTempTarget(profileFunction: ProfileFunction) : Element() { decimalFormat = DecimalFormat("0") } root.addView( - NumberPicker(root.context, null).apply { - setParams(value, minValue, maxValue, step, decimalFormat, true, root.findViewById(R.id.ok)) - setOnValueChangedListener { value: Double -> this.value = value } - gravity = Gravity.CENTER_HORIZONTAL + NumberPicker(root.context, null).also { + it.setParams(value, minValue, maxValue, step, decimalFormat, true, root.findViewById(R.id.ok)) + it.setOnValueChangedListener { v: Double -> value = v } + it.gravity = Gravity.CENTER_HORIZONTAL }) }