2019-12-20 18:55:54 +01:00
|
|
|
package info.nightscout.androidaps.dialogs
|
2019-08-23 16:31:30 +02:00
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.text.Editable
|
|
|
|
import android.text.TextWatcher
|
2019-12-20 23:05:35 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.Window
|
|
|
|
import android.view.WindowManager
|
2019-08-23 16:31:30 +02:00
|
|
|
import android.widget.AdapterView
|
2019-10-10 23:02:35 +02:00
|
|
|
import android.widget.AdapterView.OnItemSelectedListener
|
2019-08-23 16:31:30 +02:00
|
|
|
import android.widget.ArrayAdapter
|
|
|
|
import android.widget.CompoundButton
|
|
|
|
import androidx.fragment.app.DialogFragment
|
|
|
|
import info.nightscout.androidaps.Constants
|
|
|
|
import info.nightscout.androidaps.MainApp
|
|
|
|
import info.nightscout.androidaps.R
|
|
|
|
import info.nightscout.androidaps.data.Profile
|
2019-10-10 23:02:35 +02:00
|
|
|
import info.nightscout.androidaps.db.BgReading
|
2019-08-23 16:31:30 +02:00
|
|
|
import info.nightscout.androidaps.db.DatabaseHelper
|
|
|
|
import info.nightscout.androidaps.interfaces.Constraint
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
|
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
|
|
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
|
|
|
import info.nightscout.androidaps.utils.*
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
|
import io.reactivex.disposables.CompositeDisposable
|
2019-12-20 18:55:54 +01:00
|
|
|
import kotlinx.android.synthetic.main.dialog_wizard.*
|
2019-08-23 16:31:30 +02:00
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
import java.text.DecimalFormat
|
|
|
|
import java.util.*
|
2019-10-24 11:34:22 +02:00
|
|
|
import kotlin.math.abs
|
2019-08-23 16:31:30 +02:00
|
|
|
|
|
|
|
class WizardDialog : DialogFragment() {
|
|
|
|
private val log = LoggerFactory.getLogger(WizardDialog::class.java)
|
|
|
|
|
|
|
|
private var wizard: BolusWizard? = null
|
|
|
|
|
|
|
|
//one shot guards
|
|
|
|
private var okClicked: Boolean = false
|
|
|
|
|
|
|
|
private val textWatcher = object : TextWatcher {
|
|
|
|
override fun afterTextChanged(s: Editable) {}
|
|
|
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
|
|
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
|
|
|
calculateInsulin()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
|
|
|
|
2019-10-10 23:02:35 +02:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
|
}
|
|
|
|
|
2019-08-23 16:31:30 +02:00
|
|
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
|
|
|
super.onSaveInstanceState(savedInstanceState)
|
2019-10-24 11:34:22 +02:00
|
|
|
savedInstanceState.putDouble("treatments_wizard_bg_input", treatments_wizard_bg_input.value)
|
|
|
|
savedInstanceState.putDouble("treatments_wizard_carbs_input", treatments_wizard_carbs_input.value)
|
|
|
|
savedInstanceState.putDouble("treatments_wizard_correction_input", treatments_wizard_correction_input.value)
|
|
|
|
savedInstanceState.putDouble("treatments_wizard_carb_time_input", treatments_wizard_carb_time_input.value)
|
2019-08-23 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?): View? {
|
2019-09-15 18:56:54 +02:00
|
|
|
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
|
|
|
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
2019-08-23 16:31:30 +02:00
|
|
|
isCancelable = true
|
2019-09-15 18:56:54 +02:00
|
|
|
dialog?.setCanceledOnTouchOutside(false)
|
2019-08-23 16:31:30 +02:00
|
|
|
|
2019-12-20 18:55:54 +01:00
|
|
|
return inflater.inflate(R.layout.dialog_wizard, container, false)
|
2019-08-23 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
loadCheckedStates()
|
|
|
|
processCobCheckBox()
|
2019-12-20 23:05:35 +01:00
|
|
|
treatments_wizard_sbcheckbox.visibility = SP.getBoolean(R.string.key_usesuperbolus, false).toVisibility()
|
|
|
|
treatments_wizard_notes_layout.visibility = SP.getBoolean(R.string.key_show_notes_entry_dialogs, false).toVisibility()
|
2019-08-23 16:31:30 +02:00
|
|
|
|
|
|
|
val maxCarbs = MainApp.getConstraintChecker().maxCarbsAllowed.value()
|
|
|
|
val maxCorrection = MainApp.getConstraintChecker().maxBolusAllowed.value()
|
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_bg_input.setParams(savedInstanceState?.getDouble("treatments_wizard_bg_input")
|
2019-12-20 23:05:35 +01:00
|
|
|
?: 0.0, 0.0, 500.0, 0.1, DecimalFormat("0.0"), false, ok, textWatcher)
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_carbs_input.setParams(savedInstanceState?.getDouble("treatments_wizard_carbs_input")
|
2019-12-20 23:05:35 +01:00
|
|
|
?: 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false, ok, textWatcher)
|
2019-10-24 11:34:22 +02:00
|
|
|
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription?.bolusStep
|
2019-12-20 23:05:35 +01:00
|
|
|
?: 0.1
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_correction_input.setParams(savedInstanceState?.getDouble("treatments_wizard_correction_input")
|
2019-12-20 23:05:35 +01:00
|
|
|
?: 0.0, -maxCorrection, maxCorrection, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), false, ok, textWatcher)
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_carb_time_input.setParams(savedInstanceState?.getDouble("treatments_wizard_carb_time_input")
|
2019-12-20 23:05:35 +01:00
|
|
|
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
2019-08-23 16:31:30 +02:00
|
|
|
initDialog()
|
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_percent_used.text = MainApp.gs(R.string.format_percent, SP.getInt(R.string.key_boluswizard_percentage, 100))
|
2019-08-23 16:31:30 +02:00
|
|
|
// ok button
|
|
|
|
ok.setOnClickListener {
|
|
|
|
if (okClicked) {
|
|
|
|
log.debug("guarding: ok already clicked")
|
|
|
|
} else {
|
|
|
|
okClicked = true
|
2019-11-07 12:46:55 +01:00
|
|
|
calculateInsulin()
|
2019-12-20 18:55:54 +01:00
|
|
|
context?.let { context ->
|
2019-08-23 16:31:30 +02:00
|
|
|
wizard?.confirmAndExecute(context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
// cancel button
|
|
|
|
cancel.setOnClickListener { dismiss() }
|
|
|
|
// checkboxes
|
2019-12-20 23:05:35 +01:00
|
|
|
treatments_wizard_bgcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_ttcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_cobcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_basaliobcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_bolusiobcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_bgtrendcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
|
|
|
treatments_wizard_sbcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
2019-10-10 23:02:35 +02:00
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
val showCalc = SP.getBoolean(MainApp.gs(R.string.key_wizard_calculation_visible), false)
|
2019-12-20 23:05:35 +01:00
|
|
|
treatments_wizard_delimiter.visibility = showCalc.toVisibility()
|
|
|
|
treatments_wizard_resulttable.visibility = showCalc.toVisibility()
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_calculationcheckbox.isChecked = showCalc
|
2019-10-10 23:02:35 +02:00
|
|
|
treatments_wizard_calculationcheckbox.setOnCheckedChangeListener { _, isChecked ->
|
|
|
|
run {
|
2019-10-24 11:34:22 +02:00
|
|
|
SP.putBoolean(MainApp.gs(R.string.key_wizard_calculation_visible), isChecked)
|
2019-12-20 23:05:35 +01:00
|
|
|
treatments_wizard_delimiter.visibility = isChecked.toVisibility()
|
|
|
|
treatments_wizard_resulttable.visibility = isChecked.toVisibility()
|
2019-10-10 23:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-23 16:31:30 +02:00
|
|
|
// profile spinner
|
|
|
|
treatments_wizard_profile.onItemSelectedListener = object : OnItemSelectedListener {
|
|
|
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
|
|
|
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.noprofileselected))
|
|
|
|
ok.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
|
|
|
calculateInsulin()
|
|
|
|
ok.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bus
|
|
|
|
disposable.add(RxBus
|
2019-12-20 23:05:35 +01:00
|
|
|
.toObservable(EventAutosensCalculationFinished::class.java)
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe({
|
|
|
|
activity?.runOnUiThread { calculateInsulin() }
|
|
|
|
}, {
|
|
|
|
FabricPrivacy.logException(it)
|
|
|
|
})
|
2019-08-23 16:31:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDestroyView() {
|
|
|
|
super.onDestroyView()
|
|
|
|
disposable.clear()
|
|
|
|
}
|
|
|
|
|
2019-12-20 23:05:35 +01:00
|
|
|
private fun onCheckedChanged(buttonView: CompoundButton, ignored: Boolean) {
|
2019-08-23 16:31:30 +02:00
|
|
|
saveCheckedStates()
|
|
|
|
treatments_wizard_ttcheckbox.isEnabled = treatments_wizard_bgcheckbox.isChecked && TreatmentsPlugin.getPlugin().tempTargetFromHistory != null
|
|
|
|
if (buttonView.id == treatments_wizard_cobcheckbox.id)
|
|
|
|
processCobCheckBox()
|
|
|
|
calculateInsulin()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun processCobCheckBox() {
|
|
|
|
if (treatments_wizard_cobcheckbox.isChecked) {
|
|
|
|
treatments_wizard_bolusiobcheckbox.isEnabled = false
|
|
|
|
treatments_wizard_basaliobcheckbox.isEnabled = false
|
|
|
|
treatments_wizard_bolusiobcheckbox.isChecked = true
|
|
|
|
treatments_wizard_basaliobcheckbox.isChecked = true
|
|
|
|
} else {
|
|
|
|
treatments_wizard_bolusiobcheckbox.isEnabled = true
|
|
|
|
treatments_wizard_basaliobcheckbox.isEnabled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun saveCheckedStates() {
|
|
|
|
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_cob), treatments_wizard_cobcheckbox.isChecked)
|
|
|
|
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_trend_bg), treatments_wizard_bgtrendcheckbox.isChecked)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun loadCheckedStates() {
|
|
|
|
treatments_wizard_bgtrendcheckbox.isChecked = SP.getBoolean(MainApp.gs(R.string.key_wizard_include_trend_bg), false)
|
|
|
|
treatments_wizard_cobcheckbox.isChecked = SP.getBoolean(MainApp.gs(R.string.key_wizard_include_cob), false)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun initDialog() {
|
|
|
|
val profile = ProfileFunctions.getInstance().profile
|
|
|
|
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile
|
|
|
|
|
|
|
|
if (profile == null || profileStore == null) {
|
|
|
|
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.noprofile))
|
|
|
|
dismiss()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
val profileList: ArrayList<CharSequence>
|
2019-11-19 23:17:14 +01:00
|
|
|
profileList = profileStore.getProfileList()
|
2019-08-23 16:31:30 +02:00
|
|
|
profileList.add(0, MainApp.gs(R.string.active))
|
|
|
|
context?.let { context ->
|
|
|
|
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
|
|
|
treatments_wizard_profile.adapter = adapter
|
|
|
|
} ?: return
|
|
|
|
|
2019-11-12 00:01:58 +01:00
|
|
|
val units = ProfileFunctions.getSystemUnits()
|
2019-08-23 16:31:30 +02:00
|
|
|
treatments_wizard_bgunits.text = units
|
|
|
|
if (units == Constants.MGDL)
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_bg_input.setStep(1.0)
|
2019-08-23 16:31:30 +02:00
|
|
|
else
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_bg_input.setStep(0.1)
|
2019-08-23 16:31:30 +02:00
|
|
|
|
|
|
|
// Set BG if not old
|
|
|
|
val lastBg = DatabaseHelper.actualBg()
|
|
|
|
|
|
|
|
if (lastBg != null) {
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_bg_input.value = lastBg.valueToUnits(units)
|
2019-08-23 16:31:30 +02:00
|
|
|
} else {
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_bg_input.value = 0.0
|
2019-08-23 16:31:30 +02:00
|
|
|
}
|
|
|
|
treatments_wizard_ttcheckbox.isEnabled = TreatmentsPlugin.getPlugin().tempTargetFromHistory != null
|
|
|
|
|
|
|
|
// IOB calculation
|
|
|
|
TreatmentsPlugin.getPlugin().updateTotalIOBTreatments()
|
|
|
|
val bolusIob = TreatmentsPlugin.getPlugin().lastCalculationTreatments.round()
|
|
|
|
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals()
|
|
|
|
val basalIob = TreatmentsPlugin.getPlugin().lastCalculationTempBasals.round()
|
|
|
|
|
|
|
|
treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(-bolusIob.iob)
|
|
|
|
treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(-basalIob.basaliob)
|
|
|
|
|
|
|
|
calculateInsulin()
|
|
|
|
|
2019-12-20 23:05:35 +01:00
|
|
|
treatments_wizard_percent_used.visibility = (SP.getInt(R.string.key_boluswizard_percentage, 100) != 100).toVisibility()
|
2019-08-23 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun calculateInsulin() {
|
|
|
|
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile
|
|
|
|
if (treatments_wizard_profile.selectedItem == null || profileStore == null)
|
|
|
|
return // not initialized yet
|
|
|
|
var profileName = treatments_wizard_profile.selectedItem.toString()
|
|
|
|
val specificProfile: Profile?
|
|
|
|
if (profileName == MainApp.gs(R.string.active)) {
|
|
|
|
specificProfile = ProfileFunctions.getInstance().profile
|
|
|
|
profileName = ProfileFunctions.getInstance().profileName
|
|
|
|
} else
|
|
|
|
specificProfile = profileStore.getSpecificProfile(profileName)
|
|
|
|
|
|
|
|
if (specificProfile == null) return
|
|
|
|
|
|
|
|
// Entered values
|
2019-10-24 11:34:22 +02:00
|
|
|
var bg = SafeParse.stringToDouble(treatments_wizard_bg_input.text)
|
|
|
|
val carbs = SafeParse.stringToInt(treatments_wizard_carbs_input.text)
|
|
|
|
val correction = SafeParse.stringToDouble(treatments_wizard_correction_input.text)
|
|
|
|
val carbsAfterConstraint = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
|
|
|
|
if (abs(carbs - carbsAfterConstraint) > 0.01) {
|
|
|
|
treatments_wizard_carbs_input.value = 0.0
|
2019-08-23 16:31:30 +02:00
|
|
|
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.carbsconstraintapplied))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
bg = if (treatments_wizard_bgcheckbox.isChecked) bg else 0.0
|
2019-08-23 16:31:30 +02:00
|
|
|
val tempTarget = if (treatments_wizard_ttcheckbox.isChecked) TreatmentsPlugin.getPlugin().tempTargetFromHistory else null
|
|
|
|
|
|
|
|
// COB
|
2019-10-24 11:34:22 +02:00
|
|
|
var cob = 0.0
|
2019-08-23 16:31:30 +02:00
|
|
|
if (treatments_wizard_cobcheckbox.isChecked) {
|
|
|
|
val cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Wizard COB")
|
2019-10-24 11:34:22 +02:00
|
|
|
cobInfo.displayCob?.let { cob = it }
|
2019-08-23 16:31:30 +02:00
|
|
|
}
|
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
val carbTime = SafeParse.stringToInt(treatments_wizard_carb_time_input.text)
|
2019-08-23 16:31:30 +02:00
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, cob, bg, correction,
|
2019-12-20 23:05:35 +01:00
|
|
|
SP.getInt(R.string.key_boluswizard_percentage, 100).toDouble(),
|
|
|
|
treatments_wizard_bgcheckbox.isChecked,
|
|
|
|
treatments_wizard_cobcheckbox.isChecked,
|
|
|
|
treatments_wizard_bolusiobcheckbox.isChecked,
|
|
|
|
treatments_wizard_basaliobcheckbox.isChecked,
|
|
|
|
treatments_wizard_sbcheckbox.isChecked,
|
|
|
|
treatments_wizard_ttcheckbox.isChecked,
|
|
|
|
treatments_wizard_bgtrendcheckbox.isChecked,
|
|
|
|
treatment_wizard_notes.text.toString(), carbTime)
|
2019-08-23 16:31:30 +02:00
|
|
|
|
|
|
|
wizard?.let { wizard ->
|
2019-11-12 00:01:58 +01:00
|
|
|
treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, ProfileFunctions.getSystemUnits())).valueToUnitsToString(ProfileFunctions.getSystemUnits()), wizard.sens)
|
2019-08-23 16:31:30 +02:00
|
|
|
treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG)
|
|
|
|
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic)
|
2019-08-23 16:31:30 +02:00
|
|
|
treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCarbs)
|
|
|
|
|
|
|
|
treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBolusIOB)
|
|
|
|
treatments_wizard_basaliobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBasalsIOB)
|
|
|
|
|
|
|
|
treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(wizard.insulinFromCorrection)
|
|
|
|
|
|
|
|
// Superbolus
|
|
|
|
treatments_wizard_sb.text = if (treatments_wizard_sbcheckbox.isChecked) MainApp.gs(R.string.twohours) else ""
|
|
|
|
treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(wizard.insulinFromSuperBolus)
|
|
|
|
|
|
|
|
// Trend
|
|
|
|
if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) {
|
|
|
|
treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "")
|
2019-12-20 23:05:35 +01:00
|
|
|
+ Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, ProfileFunctions.getSystemUnits())
|
|
|
|
+ " " + ProfileFunctions.getSystemUnits())
|
2019-08-23 16:31:30 +02:00
|
|
|
} else {
|
|
|
|
treatments_wizard_bgtrend.text = ""
|
|
|
|
}
|
|
|
|
treatments_wizard_bgtrendinsulin.text = StringUtils.formatInsulin(wizard.insulinFromTrend)
|
|
|
|
|
|
|
|
// COB
|
|
|
|
if (treatments_wizard_cobcheckbox.isChecked) {
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_cob.text = String.format(MainApp.gs(R.string.format_cob_ic), cob, wizard.ic)
|
2019-08-23 16:31:30 +02:00
|
|
|
treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCOB)
|
|
|
|
} else {
|
|
|
|
treatments_wizard_cob.text = ""
|
|
|
|
treatments_wizard_cobinsulin.text = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wizard.calculatedTotalInsulin > 0.0 || carbsAfterConstraint > 0.0) {
|
2019-10-24 11:34:22 +02:00
|
|
|
val insulinText = if (wizard.calculatedTotalInsulin > 0.0) MainApp.gs(R.string.formatinsulinunits, wizard.calculatedTotalInsulin) else ""
|
|
|
|
val carbsText = if (carbsAfterConstraint > 0.0) MainApp.gs(R.string.format_carbs, carbsAfterConstraint) else ""
|
|
|
|
treatments_wizard_total.text = MainApp.gs(R.string.result_insulin_carbs, insulinText, carbsText)
|
2019-08-23 16:31:30 +02:00
|
|
|
ok.visibility = View.VISIBLE
|
|
|
|
} else {
|
2019-10-24 11:34:22 +02:00
|
|
|
treatments_wizard_total.text = MainApp.gs(R.string.missing_carbs, wizard.carbsEquivalent.toInt())
|
2019-08-23 16:31:30 +02:00
|
|
|
ok.visibility = View.INVISIBLE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|