Merge pull request #1888 from Andries-Smit/wear/fix-ecarb-input

Wear fix ecarb default input
This commit is contained in:
Milos Kozak 2022-07-06 22:02:43 +02:00 committed by GitHub
commit f4288ec0e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 83 deletions

View file

@ -3,12 +3,12 @@ package info.nightscout.shared
object SafeParse { object SafeParse {
// private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class); // private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class);
fun stringToDouble(inputString: String?): Double { fun stringToDouble(inputString: String?, defaultValue: Double = 0.0): Double {
var input = inputString ?: return 0.0 var input = inputString ?: return defaultValue
var result = 0.0 var result = defaultValue
input = input.replace(",", ".") input = input.replace(",", ".")
input = input.replace("", "-") input = input.replace("", "-")
if (input == "") return 0.0 if (input == "") return defaultValue
try { try {
result = input.toDouble() result = input.toDouble()
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -42,7 +42,7 @@ class BolusActivity : ViewSelectorActivity() {
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) { override fun instantiateItem(container: ViewGroup, row: Int, col: Int): View = when (col) {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val initValue = if (editInsulin != null) SafeParse.stringToDouble(editInsulin?.editText?.text.toString()) else 0.0 val initValue = SafeParse.stringToDouble(editInsulin?.editText?.text.toString(), 0.0)
val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0) val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0)
val title = getString(R.string.action_insulin) val title = getString(R.string.action_insulin)
editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, maxBolus, stepValues, DecimalFormat("#0.0"), false, title) editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, maxBolus, stepValues, DecimalFormat("#0.0"), false, title)

View file

@ -42,12 +42,9 @@ class CarbActivity : ViewSelectorActivity() {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = SafeParse.stringToDouble(editCarbs?.editText?.text.toString(), 0.0)
if (editCarbs != null) { val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48).toDouble()
def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString()) editCarbs = PlusMinusEditText(viewAdapter, initValue, 0.0, maxCarbs, stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
}
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view

View file

@ -45,12 +45,9 @@ class ECarbActivity : ViewSelectorActivity() {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = stringToDouble(editCarbs?.editText?.text.toString(), 0.0)
if (editCarbs != null) { val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48).toDouble()
def = stringToDouble(editCarbs?.editText?.text.toString()) editCarbs = PlusMinusEditText(viewAdapter, initValue, 0.0, maxCarbs, stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
}
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), true, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
@ -59,11 +56,8 @@ class ECarbActivity : ViewSelectorActivity() {
1 -> { 1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = stringToDouble(editStartTime?.editText?.text.toString(), 0.0)
if (editStartTime != null) { editStartTime = PlusMinusEditText(viewAdapter, initValue, -60.0, 300.0, 15.0, DecimalFormat("0"), false, getString(R.string.action_start_min))
def = stringToDouble(editStartTime?.editText?.text.toString())
}
editStartTime = PlusMinusEditText(viewAdapter, 15.0, def, -60.0, 300.0, DecimalFormat("0"), false, getString(R.string.action_start_min))
container.addView(view) container.addView(view)
view view
} }
@ -71,11 +65,8 @@ class ECarbActivity : ViewSelectorActivity() {
2 -> { 2 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = stringToDouble(editDuration?.editText?.text.toString(), 0.0)
if (editDuration != null) { editDuration = PlusMinusEditText(viewAdapter, initValue, 0.0, 8.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_duration_h))
def = stringToDouble(editDuration?.editText?.text.toString())
}
editDuration = PlusMinusEditText(viewAdapter, 1.0, def, 0.0, 8.0, DecimalFormat("0"), false, getString(R.string.action_duration_h))
container.addView(view) container.addView(view)
view view
} }

View file

@ -38,11 +38,8 @@ class FillActivity : ViewSelectorActivity() {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = stringToDouble(editInsulin?.editText?.text.toString(), 0.0)
if (editInsulin != null) { editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_insulin))
def = stringToDouble(editInsulin?.editText?.text.toString())
}
editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_insulin))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view

View file

@ -48,11 +48,8 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
var def = timeshift.toDouble() var initValue = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString(), timeshift.toDouble())
if (editTimeshift != null) { editTimeshift = PlusMinusEditText(viewAdapter, initValue, 0.0, 23.0, 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true)
def = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString())
}
editTimeshift = PlusMinusEditText(viewAdapter, def, 0.0, 23.0, 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true)
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
@ -61,12 +58,8 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
1 -> { 1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
var def = percentage.toDouble() var initValue = SafeParse.stringToDouble(editPercentage?.editText?.text.toString(), percentage.toDouble())
if (editPercentage != null) { editPercentage = PlusMinusEditText(viewAdapter, initValue, 30.0, 250.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
}
editPercentage = PlusMinusEditText(viewAdapter, def, 30.0, 250.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
container.addView(view) container.addView(view)
view view
} }

View file

@ -50,12 +50,8 @@ class TempTargetActivity : ViewSelectorActivity() {
col == 0 -> { col == 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
time = if (time == null) { val initValue = SafeParse.stringToDouble(time?.editText?.text.toString(), 60.0)
PlusMinusEditText(viewAdapter, 60.0, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_duration)) time = PlusMinusEditText(viewAdapter, initValue, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_duration))
} else {
val def = SafeParse.stringToDouble(time?.editText?.text.toString())
PlusMinusEditText(viewAdapter, def, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_duration))
}
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
@ -66,13 +62,11 @@ class TempTargetActivity : ViewSelectorActivity() {
val view = viewAdapter.root val view = viewAdapter.root
val title = if (isSingleTarget) getString(R.string.action_target) else getString(R.string.action_low) val title = if (isSingleTarget) getString(R.string.action_target) else getString(R.string.action_low)
if (isMGDL) { if (isMGDL) {
var def = 100.0 var initValue = SafeParse.stringToDouble(lowRange?.editText?.text.toString(), 100.0)
if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) lowRange = PlusMinusEditText(viewAdapter, initValue, 72.0, 180.0, 1.0, DecimalFormat("0"), false, title)
lowRange = PlusMinusEditText(viewAdapter, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false, title)
} else { } else {
var def = 5.5 var initValue = SafeParse.stringToDouble(lowRange?.editText?.text.toString(), 5.5)
if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) lowRange = PlusMinusEditText(viewAdapter, initValue, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, title)
lowRange = PlusMinusEditText(viewAdapter, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, title)
} }
container.addView(view) container.addView(view)
view view
@ -82,13 +76,11 @@ class TempTargetActivity : ViewSelectorActivity() {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
if (isMGDL) { if (isMGDL) {
var def = 100.0 var initValue = SafeParse.stringToDouble(highRange?.editText?.text.toString(), 100.0)
if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) highRange = PlusMinusEditText(viewAdapter, initValue, 72.0, 180.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_high))
highRange = PlusMinusEditText(viewAdapter, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_high))
} else { } else {
var def = 5.5 var initValue = SafeParse.stringToDouble(highRange?.editText?.text.toString(), 5.5)
if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) highRange = PlusMinusEditText(viewAdapter, initValue, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_high))
highRange = PlusMinusEditText(viewAdapter, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false, getString(R.string.action_high))
} }
container.addView(view) container.addView(view)
view view

View file

@ -48,10 +48,9 @@ class TreatmentActivity : ViewSelectorActivity() {
0 -> { 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 var initValue = stringToDouble(editInsulin?.editText?.text.toString(), 0.0)
if (editInsulin != null) def = stringToDouble(editInsulin?.editText?.text.toString())
val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0) val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0)
editInsulin = PlusMinusEditText(viewAdapter, def, 0.0, maxBolus, stepValuesInsulin, DecimalFormat("#0.0"), false, getString(R.string.action_insulin)) editInsulin = PlusMinusEditText(viewAdapter, initValue, 0.0, maxBolus, stepValuesInsulin, DecimalFormat("#0.0"), false, getString(R.string.action_insulin))
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
@ -60,11 +59,9 @@ class TreatmentActivity : ViewSelectorActivity() {
1 -> { 1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root val view = viewAdapter.root
var def = 0.0 val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48).toDouble()
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) var initValue = stringToDouble(editCarbs?.editText?.text.toString(), 0.0)
if (editCarbs != null) def = stringToDouble(editCarbs?.editText?.text.toString()) editCarbs = PlusMinusEditText(viewAdapter, initValue, 0.0, maxCarbs, stepValuesCarbs, DecimalFormat("0"), false, getString(R.string.action_carbs))
editCarbs = PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), stepValuesCarbs, DecimalFormat("0"), false, getString(R.string.action_carbs))
container.addView(view) container.addView(view)
view view
} }

View file

@ -44,13 +44,9 @@ class WizardActivity : ViewSelectorActivity() {
col == 0 -> { col == 0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, true)
val view = viewAdapter.root val view = viewAdapter.root
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48).toDouble()
editCarbs = if (editCarbs == null) { val initValue = SafeParse.stringToDouble(editCarbs?.editText?.text.toString(), 0.0)
PlusMinusEditText(viewAdapter, 0.0, 0.0, maxCarbs.toDouble(), stepValues, DecimalFormat("0"), false, getString(R.string.action_carbs)) editCarbs = PlusMinusEditText(viewAdapter, initValue, 0.0, maxCarbs, stepValues, DecimalFormat("0"), false, getString(R.string.action_carbs))
} else {
val def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString())
PlusMinusEditText(viewAdapter, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, getString(R.string.action_carbs))
}
container.addView(view) container.addView(view)
view.requestFocus() view.requestFocus()
view view
@ -59,13 +55,9 @@ class WizardActivity : ViewSelectorActivity() {
col == 1 && hasPercentage -> { col == 1 && hasPercentage -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false) val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root val view = viewAdapter.root
val percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100) val percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100).toDouble()
editPercentage = if (editPercentage == null) { val initValue = SafeParse.stringToDouble(editPercentage?.editText?.text.toString(), percentage)
PlusMinusEditText(viewAdapter, percentage.toDouble(), 50.0, 150.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage)) editPercentage = PlusMinusEditText(viewAdapter, initValue, 50.0, 150.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
} else {
val def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
PlusMinusEditText(viewAdapter, def, 50.0, 150.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
}
container.addView(view) container.addView(view)
view view
} }