Merge pull request #1769 from Philoul/Fix/FixAutotuneCrashFragment

Fix Autotune Fragment Crash (#1764)
This commit is contained in:
Milos Kozak 2022-05-26 10:30:48 +02:00 committed by GitHub
commit 92c4072241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -381,8 +381,9 @@ class AutotuneFragment : DaggerFragment() {
} }
private fun showResults() { private fun showResults() {
Thread { context?.let { context ->
runOnUiThread { runOnUiThread {
_binding?.let {
binding.autotuneResults.removeAllViews() binding.autotuneResults.removeAllViews()
if (autotunePlugin.result.isNotBlank()) { if (autotunePlugin.result.isNotBlank()) {
var toMgDl = 1.0 var toMgDl = 1.0
@ -401,10 +402,31 @@ class AutotuneFragment : DaggerFragment() {
layout.addView(toTableRowHeader()) layout.addView(toTableRowHeader())
val tuneInsulin = sp.getBoolean(R.string.key_autotune_tune_insulin_curve, false) val tuneInsulin = sp.getBoolean(R.string.key_autotune_tune_insulin_curve, false)
if (tuneInsulin) { if (tuneInsulin) {
layout.addView(toTableRowValue(rh.gs(R.string.insulin_peak), autotunePlugin.pumpProfile.localInsulin.peak.toDouble(), tuned.localInsulin.peak.toDouble(), "%.0f")) layout.addView(
layout.addView(toTableRowValue(rh.gs(R.string.dia), Round.roundTo(autotunePlugin.pumpProfile.localInsulin.dia, 0.1), Round.roundTo(tuned.localInsulin.dia, 0.1),"%.1f")) toTableRowValue(
rh.gs(R.string.insulin_peak),
autotunePlugin.pumpProfile.localInsulin.peak.toDouble(),
tuned.localInsulin.peak.toDouble(),
"%.0f"
)
)
layout.addView(
toTableRowValue(
rh.gs(R.string.dia),
Round.roundTo(autotunePlugin.pumpProfile.localInsulin.dia, 0.1),
Round.roundTo(tuned.localInsulin.dia, 0.1),
"%.1f"
)
)
} }
layout.addView(toTableRowValue(rh.gs(R.string.isf_short), Round.roundTo(autotunePlugin.pumpProfile.isf / toMgDl, 0.001), Round.roundTo(tuned.isf / toMgDl, 0.001), isfFormat)) layout.addView(
toTableRowValue(
rh.gs(R.string.isf_short),
Round.roundTo(autotunePlugin.pumpProfile.isf / toMgDl, 0.001),
Round.roundTo(tuned.isf / toMgDl, 0.001),
isfFormat
)
)
layout.addView(toTableRowValue(rh.gs(R.string.ic_short), Round.roundTo(autotunePlugin.pumpProfile.ic, 0.001), Round.roundTo(tuned.ic, 0.001), "%.2f")) layout.addView(toTableRowValue(rh.gs(R.string.ic_short), Round.roundTo(autotunePlugin.pumpProfile.ic, 0.001), Round.roundTo(tuned.ic, 0.001), "%.2f"))
layout.addView( layout.addView(
TextView(context).apply { TextView(context).apply {
@ -431,7 +453,8 @@ class AutotuneFragment : DaggerFragment() {
} }
binding.autotuneResultsCard.visibility = if (autotunePlugin.calculationRunning && autotunePlugin.result.isEmpty()) View.GONE else View.VISIBLE binding.autotuneResultsCard.visibility = if (autotunePlugin.calculationRunning && autotunePlugin.result.isEmpty()) View.GONE else View.VISIBLE
} }
}.start() }
}
} }
private fun toTableRowHeader(basal:Boolean = false): TableRow = private fun toTableRowHeader(basal:Boolean = false): TableRow =