fix WizardInfoDialog crash
This commit is contained in:
parent
d9f68bca3f
commit
b2c12d233c
1 changed files with 22 additions and 3 deletions
|
@ -9,18 +9,23 @@ import android.view.WindowManager
|
||||||
import dagger.android.support.DaggerDialogFragment
|
import dagger.android.support.DaggerDialogFragment
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
|
||||||
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
import info.nightscout.androidaps.database.entities.BolusCalculatorResult
|
||||||
import info.nightscout.androidaps.databinding.DialogWizardinfoBinding
|
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.interfaces.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import org.json.JSONObject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class WizardInfoDialog : DaggerDialogFragment() {
|
class WizardInfoDialog : DaggerDialogFragment() {
|
||||||
|
|
||||||
@Inject lateinit var rh: ResourceHelper
|
@Inject lateinit var rh: ResourceHelper
|
||||||
@Inject lateinit var profileFunction: ProfileFunction
|
@Inject lateinit var profileFunction: ProfileFunction
|
||||||
|
@Inject lateinit var dateUtil: DateUtil
|
||||||
|
|
||||||
private lateinit var data: BolusCalculatorResult
|
private lateinit var data: BolusCalculatorResult
|
||||||
|
|
||||||
|
@ -34,8 +39,7 @@ class WizardInfoDialog : DaggerDialogFragment() {
|
||||||
// onDestroyView.
|
// onDestroyView.
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
savedInstanceState: Bundle?): View {
|
|
||||||
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||||
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||||
isCancelable = true
|
isCancelable = true
|
||||||
|
@ -44,6 +48,21 @@ class WizardInfoDialog : DaggerDialogFragment() {
|
||||||
return binding.root
|
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?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue