From f2021c7baacae82cf95b2b3426ca3a212e12e0e1 Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Sat, 23 Sep 2023 12:05:17 +0200 Subject: [PATCH] Medtrum: Prevent activation when no serial number is entered --- .../info/nightscout/pump/medtrum/code/EventType.kt | 1 + .../pump/medtrum/ui/MedtrumOverviewFragment.kt | 12 ++++++++++-- .../medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt | 2 ++ pump/medtrum/src/main/res/values/strings.xml | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/code/EventType.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/code/EventType.kt index bd8f902afd..ac24d3e1a4 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/code/EventType.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/code/EventType.kt @@ -3,5 +3,6 @@ package info.nightscout.pump.medtrum.code enum class EventType { CHANGE_PATCH_CLICKED, PROFILE_NOT_SET, + SERIAL_NOT_SET ; } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/MedtrumOverviewFragment.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/MedtrumOverviewFragment.kt index 26d08dab02..7f9d0d2962 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/MedtrumOverviewFragment.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/MedtrumOverviewFragment.kt @@ -3,7 +3,7 @@ package info.nightscout.pump.medtrum.ui import android.os.Bundle import android.view.View import androidx.lifecycle.ViewModelProvider -import info.nightscout.core.ui.toast.ToastUtils +import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.interfaces.protection.ProtectionCheck import info.nightscout.pump.medtrum.MedtrumPump import info.nightscout.pump.medtrum.databinding.FragmentMedtrumOverviewBinding @@ -14,6 +14,7 @@ import info.nightscout.pump.medtrum.code.PatchStep import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.shared.interfaces.ResourceHelper import io.reactivex.rxjava3.disposables.CompositeDisposable import javax.inject.Inject @@ -23,6 +24,7 @@ class MedtrumOverviewFragment : MedtrumBaseFragment ToastUtils.infoToast(requireContext(), R.string.no_profile_selected) + EventType.PROFILE_NOT_SET -> { + OKDialog.show(requireActivity(), rh.gs(info.nightscout.core.ui.R.string.message), rh.gs(R.string.no_profile_selected)) + } + + EventType.SERIAL_NOT_SET -> { + OKDialog.show(requireActivity(), rh.gs(info.nightscout.core.ui.R.string.message), rh.gs(R.string.no_sn_in_settings)) + } } } } diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt index dcc15dc074..13a6085b42 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/ui/viewmodel/MedtrumOverviewViewModel.kt @@ -167,6 +167,8 @@ class MedtrumOverviewViewModel @Inject constructor( val profile = profileFunction.getProfile() if (profile == null) { _eventHandler.postValue(UIEvent(EventType.PROFILE_NOT_SET)) + } else if (medtrumPump.pumpSN == 0L){ + _eventHandler.postValue(UIEvent(EventType.SERIAL_NOT_SET)) } else { _eventHandler.postValue(UIEvent(EventType.CHANGE_PATCH_CLICKED)) } diff --git a/pump/medtrum/src/main/res/values/strings.xml b/pump/medtrum/src/main/res/values/strings.xml index 734d741160..147c018513 100644 --- a/pump/medtrum/src/main/res/values/strings.xml +++ b/pump/medtrum/src/main/res/values/strings.xml @@ -98,6 +98,7 @@ Activation in progress Unexpected state: %1$s No profile selected. Please select a profile and try again. + No serial number known. Please enter pumpbase serial number in settings and try again. Pump Base Serial: %1$X No active patch. Press Next to begin the activation process.