WizardInfoDialog cleanup

This commit is contained in:
Milos Kozak 2022-12-28 11:51:10 +01:00
parent 4ac47a7d82
commit b3483aaecc
5 changed files with 14 additions and 24 deletions

View file

@ -21,5 +21,5 @@ data class NSBolusWizard(
override val pumpSerial: String?, override val pumpSerial: String?,
override var app: String? = null, override var app: String? = null,
val bolusCalculatorResult: String?, val bolusCalculatorResult: String?,
val glucose: Double?, val glucose: Double?
) : NSTreatment ) : NSTreatment

View file

@ -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.Gson
import com.google.gson.JsonSyntaxException import com.google.gson.JsonSyntaxException

View file

@ -3,19 +3,18 @@ package info.nightscout.plugins.sync.nsclient.workers
import android.content.Context import android.content.Context
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import androidx.work.workDataOf import androidx.work.workDataOf
import info.nightscout.core.extensions.bolusCalculatorResultFromJson
import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.core.utils.receivers.DataWorkerStorage
import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.utils.worker.LoggingWorker
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.XDripBroadcast import info.nightscout.interfaces.XDripBroadcast
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.nsclient.StoreDataForDb import info.nightscout.interfaces.nsclient.StoreDataForDb
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.VirtualPump import info.nightscout.interfaces.pump.VirtualPump
import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.plugins.sync.R 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.bolusFromJson
import info.nightscout.plugins.sync.nsclient.extensions.carbsFromJson import info.nightscout.plugins.sync.nsclient.extensions.carbsFromJson
import info.nightscout.plugins.sync.nsclient.extensions.effectiveProfileSwitchFromJson import info.nightscout.plugins.sync.nsclient.extensions.effectiveProfileSwitchFromJson
@ -44,7 +43,6 @@ class NSClientAddUpdateWorker(
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var uel: UserEntryLogger
@Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var xDripBroadcast: XDripBroadcast
@Inject lateinit var storeDataForDb: StoreDataForDb @Inject lateinit var storeDataForDb: StoreDataForDb

View file

@ -15,6 +15,7 @@ import androidx.core.view.MenuProvider
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.gson.Gson
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.core.extensions.iobCalc import info.nightscout.core.extensions.iobCalc
import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.dialogs.OKDialog
@ -292,7 +293,9 @@ class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider {
val mealLinkLoaded = it.tag as MealLink? ?: return@setOnClickListener val mealLinkLoaded = it.tag as MealLink? ?: return@setOnClickListener
mealLinkLoaded.bolusCalculatorResult?.let { bolusCalculatorResult -> mealLinkLoaded.bolusCalculatorResult?.let { bolusCalculatorResult ->
WizardInfoDialog().also { wizardDialog -> WizardInfoDialog().also { wizardDialog ->
wizardDialog.setData(bolusCalculatorResult) wizardDialog.arguments = Bundle().also { bundle ->
bundle.putString("data", Gson().toJson(bolusCalculatorResult).toString())
}
wizardDialog.show(childFragmentManager, "WizardInfoDialog") wizardDialog.show(childFragmentManager, "WizardInfoDialog")
} }
} }

View file

@ -6,9 +6,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.Window import android.view.Window
import android.view.WindowManager import android.view.WindowManager
import com.google.gson.Gson
import dagger.android.support.DaggerDialogFragment 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.database.entities.BolusCalculatorResult
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.profile.Profile 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.shared.utils.DateUtil
import info.nightscout.ui.R import info.nightscout.ui.R
import info.nightscout.ui.databinding.DialogWizardinfoBinding import info.nightscout.ui.databinding.DialogWizardinfoBinding
import org.json.JSONObject
import javax.inject.Inject import javax.inject.Inject
class WizardInfoDialog : DaggerDialogFragment() { class WizardInfoDialog : DaggerDialogFragment() {
@ -28,10 +26,6 @@ class WizardInfoDialog : DaggerDialogFragment() {
private lateinit var data: BolusCalculatorResult private lateinit var data: BolusCalculatorResult
fun setData(bolusCalculatorResult: BolusCalculatorResult) {
this.data = bolusCalculatorResult
}
private var _binding: DialogWizardinfoBinding? = null private var _binding: DialogWizardinfoBinding? = null
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
@ -39,6 +33,11 @@ class WizardInfoDialog : DaggerDialogFragment() {
private val binding get() = _binding!! 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 {
(savedInstanceState ?: arguments)?.let {
it.getString("data")?.let { str ->
data = Gson().fromJson(str, BolusCalculatorResult::class.java)
}
}
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
@ -47,19 +46,9 @@ 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) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) 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?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {