Automation: catch instantiation errors
This commit is contained in:
parent
dc0b6ac9f7
commit
6b6ba15852
2 changed files with 57 additions and 53 deletions
|
@ -72,7 +72,7 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
private var wizard: BolusWizard? = null
|
private var wizard: BolusWizard? = null
|
||||||
private var calculatedPercentage = 100.0
|
private var calculatedPercentage = 100.0
|
||||||
private var calculatedCorrection = 0.0
|
private var calculatedCorrection = 0.0
|
||||||
private var correctionPercent = false
|
private var usePercentage = false
|
||||||
private var carbsPassedIntoWizard = 0.0
|
private var carbsPassedIntoWizard = 0.0
|
||||||
private var notesPassedIntoWizard = ""
|
private var notesPassedIntoWizard = ""
|
||||||
private var okClicked: Boolean = false // one shot guards
|
private var okClicked: Boolean = false // one shot guards
|
||||||
|
@ -157,7 +157,7 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
?: 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher
|
?: 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher
|
||||||
)
|
)
|
||||||
|
|
||||||
if (correctionPercent) {
|
if (usePercentage) {
|
||||||
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
||||||
binding.correctionInput.setParams(calculatedPercentage, 10.0, 200.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
binding.correctionInput.setParams(calculatedPercentage, 10.0, 200.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
||||||
binding.correctionInput.value = calculatedPercentage
|
binding.correctionInput.value = calculatedPercentage
|
||||||
|
@ -176,6 +176,7 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
handler.post { initDialog() }
|
handler.post { initDialog() }
|
||||||
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
calculatedPercentage = sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble()
|
||||||
binding.percentUsed.text = rh.gs(R.string.format_percent, sp.getInt(R.string.key_boluswizard_percentage, 100))
|
binding.percentUsed.text = rh.gs(R.string.format_percent, sp.getInt(R.string.key_boluswizard_percentage, 100))
|
||||||
|
binding.percentUsed.visibility = (sp.getInt(R.string.key_boluswizard_percentage, 100) != 100 || usePercentage).toVisibility()
|
||||||
// ok button
|
// ok button
|
||||||
binding.okcancel.ok.setOnClickListener {
|
binding.okcancel.ok.setOnClickListener {
|
||||||
if (okClicked) {
|
if (okClicked) {
|
||||||
|
@ -227,8 +228,8 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
run {
|
run {
|
||||||
sp.putBoolean(rh.gs(R.string.key_wizard_correction_percent), isChecked)
|
sp.putBoolean(rh.gs(R.string.key_wizard_correction_percent), isChecked)
|
||||||
binding.correctionUnit.text = if (isChecked) "%" else rh.gs(R.string.insulin_unit_shortname)
|
binding.correctionUnit.text = if (isChecked) "%" else rh.gs(R.string.insulin_unit_shortname)
|
||||||
correctionPercent = binding.correctionPercent.isChecked
|
usePercentage = binding.correctionPercent.isChecked
|
||||||
if (correctionPercent) {
|
if (usePercentage) {
|
||||||
binding.correctionInput.setParams(calculatedPercentage, 10.0, 200.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
binding.correctionInput.setParams(calculatedPercentage, 10.0, 200.0, 5.0, DecimalFormat("0"), false, binding.okcancel.ok, textWatcher)
|
||||||
binding.correctionInput.customContentDescription = rh.gs(R.string.a11_correction_percentage)
|
binding.correctionInput.customContentDescription = rh.gs(R.string.a11_correction_percentage)
|
||||||
} else {
|
} else {
|
||||||
|
@ -239,7 +240,7 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
binding.correctionInput.customContentDescription = rh.gs(R.string.a11_correction_units)
|
binding.correctionInput.customContentDescription = rh.gs(R.string.a11_correction_units)
|
||||||
}
|
}
|
||||||
binding.correctionInput.updateA11yDescription()
|
binding.correctionInput.updateA11yDescription()
|
||||||
binding.correctionInput.value = if (correctionPercent) calculatedPercentage else Round.roundTo(calculatedCorrection, bolusStep)
|
binding.correctionInput.value = if (usePercentage) calculatedPercentage else Round.roundTo(calculatedCorrection, bolusStep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// profile
|
// profile
|
||||||
|
@ -320,8 +321,8 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
private fun loadCheckedStates() {
|
private fun loadCheckedStates() {
|
||||||
binding.bgTrendCheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_trend_bg, false)
|
binding.bgTrendCheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_trend_bg, false)
|
||||||
binding.cobCheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_cob, false)
|
binding.cobCheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_cob, false)
|
||||||
correctionPercent = sp.getBoolean(R.string.key_wizard_correction_percent, false)
|
usePercentage = sp.getBoolean(R.string.key_wizard_correction_percent, false)
|
||||||
binding.correctionPercent.isChecked = correctionPercent
|
binding.correctionPercent.isChecked = usePercentage
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun valueToUnitsToString(value: Double, units: String): String =
|
private fun valueToUnitsToString(value: Double, units: String): String =
|
||||||
|
@ -370,8 +371,6 @@ class WizardDialog : DaggerDialogFragment() {
|
||||||
binding.iobInsulin.text = rh.gs(R.string.formatinsulinunits, -bolusIob.iob - basalIob.basaliob)
|
binding.iobInsulin.text = rh.gs(R.string.formatinsulinunits, -bolusIob.iob - basalIob.basaliob)
|
||||||
|
|
||||||
calculateInsulin()
|
calculateInsulin()
|
||||||
|
|
||||||
binding.percentUsed.visibility = (sp.getInt(R.string.key_boluswizard_percentage, 100) != 100 || correctionPercent).toVisibility()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProv
|
||||||
import info.nightscout.androidaps.services.LastLocationDataContainer
|
import info.nightscout.androidaps.services.LastLocationDataContainer
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||||
|
import info.nightscout.shared.logging.LTag
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -78,6 +79,7 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
fun instantiate(obj: JSONObject): Trigger {
|
fun instantiate(obj: JSONObject): Trigger {
|
||||||
|
try {
|
||||||
val type = obj.getString("type")
|
val type = obj.getString("type")
|
||||||
val data = obj.getJSONObject("data")
|
val data = obj.getJSONObject("data")
|
||||||
//val clazz = Class.forName(type).kotlin
|
//val clazz = Class.forName(type).kotlin
|
||||||
|
@ -123,6 +125,9 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
||||||
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(data.toString())
|
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(data.toString())
|
||||||
else -> TriggerConnector(injector)
|
else -> TriggerConnector(injector)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
aapsLogger.error(LTag.AUTOMATION, "Error parsing $obj")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createAddButton(context: Context, trigger: TriggerConnector): ImageButton =
|
fun createAddButton(context: Context, trigger: TriggerConnector): ImageButton =
|
||||||
|
|
Loading…
Reference in a new issue