AndroidAPS/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt

102 lines
4.5 KiB
Kotlin
Raw Normal View History

2019-12-31 13:25:28 +01:00
package info.nightscout.androidaps.dialogs
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
2021-03-25 17:48:07 +01:00
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
2021-01-21 20:54:13 +01:00
import info.nightscout.androidaps.databinding.DialogWizardinfoBinding
2020-05-07 09:54:36 +02:00
import info.nightscout.androidaps.interfaces.ProfileFunction
2019-12-31 13:25:28 +01:00
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.resources.ResourceHelper
import javax.inject.Inject
class WizardInfoDialog : DaggerDialogFragment() {
2021-01-21 20:54:13 +01:00
2019-12-31 13:25:28 +01:00
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var profileFunction: ProfileFunction
2021-03-25 17:48:07 +01:00
private lateinit var data: BolusCalculatorResult
private lateinit var notes: String
2019-12-31 13:25:28 +01:00
2021-03-25 17:48:07 +01:00
fun setData(bolusCalculatorResult: BolusCalculatorResult, notes: String) {
this.data = bolusCalculatorResult
this.notes = notes
2019-12-31 13:25:28 +01:00
}
2021-01-21 20:54:13 +01:00
private var _binding: DialogWizardinfoBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
2019-12-31 13:25:28 +01:00
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
2021-01-21 20:54:13 +01:00
savedInstanceState: Bundle?): View {
2019-12-31 13:25:28 +01:00
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
isCancelable = true
dialog?.setCanceledOnTouchOutside(false)
2021-01-21 20:54:13 +01:00
_binding = DialogWizardinfoBinding.inflate(inflater, container, false)
return binding.root
2019-12-31 13:25:28 +01:00
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
2021-01-21 20:54:13 +01:00
binding.close.setOnClickListener { dismiss() }
2019-12-31 13:25:28 +01:00
val units = profileFunction.getUnits()
2021-03-25 17:48:07 +01:00
val bgString = Profile.toUnitsString(data.glucoseValue, data.glucoseValue * Constants.MGDL_TO_MMOLL, units)
2019-12-31 13:25:28 +01:00
// BG
2021-03-25 17:48:07 +01:00
binding.bg.text = resourceHelper.gs(R.string.format_bg_isf, bgString, data.isf)
binding.bginsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.glucoseInsulin)
binding.bgcheckbox.isChecked = data.wasGlucoseUsed
binding.ttcheckbox.isChecked = data.wasTempTargetUsed
2019-12-31 13:25:28 +01:00
// Trend
2021-03-25 17:48:07 +01:00
binding.bgtrend.text = DecimalFormatter.to1Decimal(data.glucoseTrend)
binding.bgtrendinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.trendInsulin)
binding.bgtrendcheckbox.isChecked = data.wasTrendUsed
2019-12-31 13:25:28 +01:00
// COB
2021-03-25 17:48:07 +01:00
binding.cob.text = resourceHelper.gs(R.string.format_cob_ic, data.cob, data.ic)
binding.cobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.cobInsulin)
binding.cobcheckbox.isChecked = data.wasCOBUsed
2019-12-31 13:25:28 +01:00
// Bolus IOB
2021-03-25 17:48:07 +01:00
binding.bolusiobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.bolusIOB)
binding.bolusiobcheckbox.isChecked = data.wasBolusIOBUsed
2019-12-31 13:25:28 +01:00
// Basal IOB
2021-03-25 17:48:07 +01:00
binding.basaliobinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.basalIOB)
binding.basaliobcheckbox.isChecked = data.wasBasalIOBUsed
2019-12-31 13:25:28 +01:00
// Superbolus
2021-03-25 17:48:07 +01:00
binding.sbinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.superbolusInsulin)
binding.sbcheckbox.isChecked = data.wasSuperbolusUsed
2019-12-31 13:25:28 +01:00
// Carbs
2021-03-25 17:48:07 +01:00
binding.carbs.text = resourceHelper.gs(R.string.format_carbs_ic, data.carbs, data.ic)
binding.carbsinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.carbsInsulin)
2019-12-31 13:25:28 +01:00
// Correction
2021-03-25 17:48:07 +01:00
binding.correctioninsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.otherCorrection)
2019-12-31 13:25:28 +01:00
// Profile
2021-03-25 17:48:07 +01:00
binding.profile.text = data.profileName
2019-12-31 13:25:28 +01:00
// Notes
2021-03-25 17:48:07 +01:00
binding.notes.text = notes
2019-12-31 13:25:28 +01:00
// Percentage
2021-03-25 17:48:07 +01:00
binding.percentUsed.text = resourceHelper.gs(R.string.format_percent, data.percentageCorrection)
2019-12-31 13:25:28 +01:00
// Total
2021-03-25 17:48:07 +01:00
binding.totalinsulin.text = resourceHelper.gs(R.string.formatinsulinunits, data.totalInsulin)
2019-12-31 13:25:28 +01:00
}
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
2021-01-21 20:54:13 +01:00
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
2019-12-31 13:25:28 +01:00
}