From b3483aaeccf39cf8696908e2f3d10ee7ab1f4f5e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 28 Dec 2022 11:51:10 +0100 Subject: [PATCH] WizardInfoDialog cleanup --- .../sdk/localmodel/treatment/NSBolusWizard.kt | 2 +- .../BolusCalculatorResultExtension.kt | 2 +- .../workers/NSClientAddUpdateWorker.kt | 4 +-- .../fragments/TreatmentsBolusCarbsFragment.kt | 5 +++- .../nightscout/ui/dialogs/WizardInfoDialog.kt | 25 ++++++------------- 5 files changed, 14 insertions(+), 24 deletions(-) rename {core/main/src/main/java/info/nightscout/core => plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient}/extensions/BolusCalculatorResultExtension.kt (97%) diff --git a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt index 5418175fe1..45de036331 100644 --- a/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt +++ b/core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/treatment/NSBolusWizard.kt @@ -21,5 +21,5 @@ data class NSBolusWizard( override val pumpSerial: String?, override var app: String? = null, val bolusCalculatorResult: String?, - val glucose: Double?, + val glucose: Double? ) : NSTreatment \ No newline at end of file diff --git a/core/main/src/main/java/info/nightscout/core/extensions/BolusCalculatorResultExtension.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/BolusCalculatorResultExtension.kt similarity index 97% rename from core/main/src/main/java/info/nightscout/core/extensions/BolusCalculatorResultExtension.kt rename to plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/BolusCalculatorResultExtension.kt index 94519e19d2..038731df7c 100644 --- a/core/main/src/main/java/info/nightscout/core/extensions/BolusCalculatorResultExtension.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/extensions/BolusCalculatorResultExtension.kt @@ -1,4 +1,4 @@ -package info.nightscout.core.extensions +package info.nightscout.plugins.sync.nsclient.extensions import com.google.gson.Gson import com.google.gson.JsonSyntaxException diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt index ee941fab59..41f9f82342 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt @@ -3,19 +3,18 @@ package info.nightscout.plugins.sync.nsclient.workers import android.content.Context import androidx.work.WorkerParameters import androidx.work.workDataOf -import info.nightscout.core.extensions.bolusCalculatorResultFromJson import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.XDripBroadcast -import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.nsclient.StoreDataForDb import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.pump.VirtualPump import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.plugins.sync.R +import info.nightscout.plugins.sync.nsclient.extensions.bolusCalculatorResultFromJson import info.nightscout.plugins.sync.nsclient.extensions.bolusFromJson import info.nightscout.plugins.sync.nsclient.extensions.carbsFromJson import info.nightscout.plugins.sync.nsclient.extensions.effectiveProfileSwitchFromJson @@ -44,7 +43,6 @@ class NSClientAddUpdateWorker( @Inject lateinit var repository: AppRepository @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var rxBus: RxBus - @Inject lateinit var uel: UserEntryLogger @Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var storeDataForDb: StoreDataForDb diff --git a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsBolusCarbsFragment.kt b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsBolusCarbsFragment.kt index dec38f85cc..fbf769c577 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsBolusCarbsFragment.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsBolusCarbsFragment.kt @@ -15,6 +15,7 @@ import androidx.core.view.MenuProvider import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.google.gson.Gson import dagger.android.support.DaggerFragment import info.nightscout.core.extensions.iobCalc import info.nightscout.core.ui.dialogs.OKDialog @@ -292,7 +293,9 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider { val mealLinkLoaded = it.tag as MealLink? ?: return@setOnClickListener mealLinkLoaded.bolusCalculatorResult?.let { bolusCalculatorResult -> WizardInfoDialog().also { wizardDialog -> - wizardDialog.setData(bolusCalculatorResult) + wizardDialog.arguments = Bundle().also { bundle -> + bundle.putString("data", Gson().toJson(bolusCalculatorResult).toString()) + } wizardDialog.show(childFragmentManager, "WizardInfoDialog") } } diff --git a/ui/src/main/java/info/nightscout/ui/dialogs/WizardInfoDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/WizardInfoDialog.kt index b28da71b9a..98169731ee 100644 --- a/ui/src/main/java/info/nightscout/ui/dialogs/WizardInfoDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/WizardInfoDialog.kt @@ -6,9 +6,8 @@ import android.view.View import android.view.ViewGroup import android.view.Window import android.view.WindowManager +import com.google.gson.Gson import dagger.android.support.DaggerDialogFragment -import info.nightscout.core.extensions.bolusCalculatorResultFromJson -import info.nightscout.core.extensions.toJson import info.nightscout.database.entities.BolusCalculatorResult import info.nightscout.interfaces.Constants import info.nightscout.interfaces.profile.Profile @@ -17,7 +16,6 @@ import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil import info.nightscout.ui.R import info.nightscout.ui.databinding.DialogWizardinfoBinding -import org.json.JSONObject import javax.inject.Inject class WizardInfoDialog : DaggerDialogFragment() { @@ -28,10 +26,6 @@ class WizardInfoDialog : DaggerDialogFragment() { private lateinit var data: BolusCalculatorResult - fun setData(bolusCalculatorResult: BolusCalculatorResult) { - this.data = bolusCalculatorResult - } - private var _binding: DialogWizardinfoBinding? = null // This property is only valid between onCreateView and @@ -39,6 +33,11 @@ class WizardInfoDialog : DaggerDialogFragment() { private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + (savedInstanceState ?: arguments)?.let { + it.getString("data")?.let { str -> + data = Gson().fromJson(str, BolusCalculatorResult::class.java) + } + } dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE) dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) isCancelable = true @@ -47,19 +46,9 @@ 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, profileFunction).toString()) + outState.putString("data", Gson().toJson(data).toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) {