From b2c12d233cb06313797a4e948552787eeb71740f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 17 Nov 2021 21:44:08 +0100 Subject: [PATCH] fix WizardInfoDialog crash --- .../androidaps/dialogs/WizardInfoDialog.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt index d5ec4736bf..9353503f35 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardInfoDialog.kt @@ -9,18 +9,23 @@ import android.view.WindowManager import dagger.android.support.DaggerDialogFragment import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.database.entities.BolusCalculatorResult import info.nightscout.androidaps.databinding.DialogWizardinfoBinding +import info.nightscout.androidaps.extensions.bolusCalculatorResultFromJson +import info.nightscout.androidaps.extensions.toJson +import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.json.JSONObject import javax.inject.Inject class WizardInfoDialog : DaggerDialogFragment() { @Inject lateinit var rh: ResourceHelper @Inject lateinit var profileFunction: ProfileFunction + @Inject lateinit var dateUtil: DateUtil private lateinit var data: BolusCalculatorResult @@ -34,8 +39,7 @@ class WizardInfoDialog : DaggerDialogFragment() { // onDestroyView. private val binding get() = _binding!! - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE) dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) isCancelable = true @@ -44,6 +48,21 @@ class WizardInfoDialog : DaggerDialogFragment() { return binding.root } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + savedInstanceState?.getString("data")?.let { str -> + val json = JSONObject(str).apply { + put("mills", dateUtil.now()) // fake NS response + } + data = bolusCalculatorResultFromJson(json) ?: return + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + outState.putString("data", data.toJson(true, dateUtil).toString()) + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState)