fix carbs limit
This commit is contained in:
parent
608fe446c3
commit
f7f7ba3a2b
|
@ -14,6 +14,7 @@ abstract class WizardModule {
|
||||||
@ContributesAndroidInjector abstract fun swButtonInjector(): SWButton
|
@ContributesAndroidInjector abstract fun swButtonInjector(): SWButton
|
||||||
@ContributesAndroidInjector abstract fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits
|
@ContributesAndroidInjector abstract fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits
|
||||||
@ContributesAndroidInjector abstract fun swEditNumberInjector(): SWEditNumber
|
@ContributesAndroidInjector abstract fun swEditNumberInjector(): SWEditNumber
|
||||||
|
@ContributesAndroidInjector abstract fun swEditIntNumberInjector(): SWEditIntNumber
|
||||||
@ContributesAndroidInjector abstract fun swEditStringInjector(): SWEditString
|
@ContributesAndroidInjector abstract fun swEditStringInjector(): SWEditString
|
||||||
@ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword
|
@ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword
|
||||||
@ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl
|
@ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl
|
||||||
|
|
|
@ -227,7 +227,7 @@ class SWDefinition @Inject constructor(
|
||||||
.updateDelay(5)
|
.updateDelay(5)
|
||||||
.label(R.string.treatmentssafety_maxbolus_title)
|
.label(R.string.treatmentssafety_maxbolus_title)
|
||||||
.comment(R.string.common_values))
|
.comment(R.string.common_values))
|
||||||
.add(SWEditNumber(injector, 48.0, 1.0, 100.0)
|
.add(SWEditIntNumber(injector, 48, 1, 100)
|
||||||
.preferenceId(R.string.key_treatmentssafety_maxcarbs)
|
.preferenceId(R.string.key_treatmentssafety_maxcarbs)
|
||||||
.updateDelay(5)
|
.updateDelay(5)
|
||||||
.label(R.string.treatmentssafety_maxcarbs_title)
|
.label(R.string.treatmentssafety_maxcarbs_title)
|
||||||
|
@ -235,7 +235,7 @@ class SWDefinition @Inject constructor(
|
||||||
.validator {
|
.validator {
|
||||||
sp.contains(R.string.key_age)
|
sp.contains(R.string.key_age)
|
||||||
&& sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0
|
&& sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0
|
||||||
&& sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0
|
&& sp.getInt(R.string.key_treatmentssafety_maxcarbs, 0) > 0
|
||||||
}
|
}
|
||||||
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.nightscout.androidaps.setupwizard;
|
||||||
|
|
||||||
|
// keep in java, it's easier
|
||||||
|
public interface SWIntNumberValidator {
|
||||||
|
boolean isValid(int value);
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package info.nightscout.androidaps.setupwizard.elements
|
||||||
|
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.nightscout.androidaps.setupwizard.SWIntNumberValidator
|
||||||
|
import info.nightscout.androidaps.utils.SafeParse
|
||||||
|
import info.nightscout.androidaps.utils.ui.NumberPicker
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
|
class SWEditIntNumber(injector: HasAndroidInjector, private val init: Int, private val min: Int, private val max: Int) : SWItem(injector, Type.NUMBER) {
|
||||||
|
|
||||||
|
private val validator: SWIntNumberValidator = SWIntNumberValidator { value -> value in min..max }
|
||||||
|
private var updateDelay = 0
|
||||||
|
|
||||||
|
override fun generateDialog(layout: LinearLayout) {
|
||||||
|
val context = layout.context
|
||||||
|
val watcher: TextWatcher = object : TextWatcher {
|
||||||
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||||
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||||
|
if (validator.isValid(SafeParse.stringToInt(s.toString())))
|
||||||
|
save(s.toString(), updateDelay.toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun afterTextChanged(s: Editable) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val l = TextView(context)
|
||||||
|
l.id = View.generateViewId()
|
||||||
|
label?.let { l.setText(it) }
|
||||||
|
l.setTypeface(l.typeface, Typeface.BOLD)
|
||||||
|
layout.addView(l)
|
||||||
|
val initValue = sp.getInt(preferenceId, init)
|
||||||
|
val numberPicker = NumberPicker(context)
|
||||||
|
numberPicker.setParams(initValue.toDouble(), min.toDouble(), max.toDouble(), 1.0, DecimalFormat("0"), false, null, watcher)
|
||||||
|
|
||||||
|
layout.addView(numberPicker)
|
||||||
|
val c = TextView(context)
|
||||||
|
c.id = View.generateViewId()
|
||||||
|
comment?.let { c.setText(it) }
|
||||||
|
c.setTypeface(c.typeface, Typeface.ITALIC)
|
||||||
|
layout.addView(c)
|
||||||
|
super.generateDialog(layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun preferenceId(preferenceId: Int): SWEditIntNumber {
|
||||||
|
this.preferenceId = preferenceId
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateDelay(updateDelay: Int): SWEditIntNumber {
|
||||||
|
this.updateDelay = updateDelay
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue