This commit is contained in:
jbr7rr 2023-06-25 12:29:49 +02:00
parent ac8b5b4a05
commit 201fb5768a
19 changed files with 41 additions and 116 deletions

View file

@ -5,18 +5,17 @@ import android.view.View
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumActivateBinding
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumActivateCompleteBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class MedtrumActivateCompleteFragment : MedtrumBaseFragment<FragmentMedtrumActivateCompleteBinding>() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rh: ResourceHelper
companion object {
@ -36,13 +35,8 @@ class MedtrumActivateCompleteFragment : MedtrumBaseFragment<FragmentMedtrumActiv
MedtrumViewModel.SetupStep.PRIMED -> Unit // Nothing to do here, previous state
MedtrumViewModel.SetupStep.ACTIVATED -> btnPositive.visibility = View.VISIBLE
MedtrumViewModel.SetupStep.ERROR -> {
ToastUtils.errorToast(requireContext(), "Error Activating") // TODO: String resource and show error message
moveStep(PatchStep.CANCEL)
}
else -> {
ToastUtils.errorToast(requireContext(), "Unexpected state: $it") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
}
}

View file

@ -7,7 +7,6 @@ import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumActivateBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -1,27 +1,12 @@
package info.nightscout.pump.medtrum.ui
import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.media.MediaPlayer
import android.media.RingtoneManager
import android.os.Bundle
import android.view.MotionEvent
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider
import info.nightscout.pump.medtrum.ui.MedtrumActivateCompleteFragment
import info.nightscout.pump.medtrum.ui.MedtrumActivateFragment
import info.nightscout.pump.medtrum.ui.MedtrumAttachPatchFragment
import info.nightscout.pump.medtrum.ui.MedtrumDeactivatePatchFragment
import info.nightscout.pump.medtrum.ui.MedtrumDeactivationCompleteFragment
import info.nightscout.pump.medtrum.ui.MedtrumPreparePatchConnectFragment
import info.nightscout.pump.medtrum.ui.MedtrumPreparePatchFragment
import info.nightscout.pump.medtrum.ui.MedtrumPrimeCompleteFragment
import info.nightscout.pump.medtrum.ui.MedtrumPrimeFragment
import info.nightscout.pump.medtrum.ui.MedtrumPrimingFragment
import info.nightscout.pump.medtrum.ui.MedtrumStartDeactivationFragment
import info.nightscout.core.utils.extensions.safeGetSerializableExtra
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
@ -35,10 +20,6 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
override fun getLayoutId(): Int = R.layout.activity_medtrum
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_UP) {
// TODO
}
return super.dispatchTouchEvent(event)
}
@ -106,12 +87,11 @@ class MedtrumActivity : MedtrumBaseActivity<ActivityMedtrumBinding>() {
override fun onDestroy() {
super.onDestroy()
// TODO
}
override fun onBackPressed() {
binding.viewModel?.apply {
// TODO DEACTIVATION ?
// Do nothing
}
}

View file

@ -5,17 +5,17 @@ import android.view.View
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumAttachPatchBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class MedtrumAttachPatchFragment : MedtrumBaseFragment<FragmentMedtrumAttachPatchBinding>() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rh: ResourceHelper
companion object {
@ -34,13 +34,9 @@ class MedtrumAttachPatchFragment : MedtrumBaseFragment<FragmentMedtrumAttachPatc
when (it) {
MedtrumViewModel.SetupStep.INITIAL,
MedtrumViewModel.SetupStep.PRIMED -> Unit // Nothing to do here, previous state
MedtrumViewModel.SetupStep.ERROR -> {
ToastUtils.errorToast(requireContext(), "Error attach patch") // TODO: String resource and show error message
moveStep(PatchStep.CANCEL)
}
else -> {
ToastUtils.errorToast(requireContext(), "Unexpected state: $it") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
}
}

View file

@ -10,7 +10,6 @@ import androidx.lifecycle.ViewModelProvider
import dagger.android.support.DaggerAppCompatActivity
import info.nightscout.core.ui.R
import info.nightscout.pump.medtrum.di.MedtrumPluginQualifier
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
import info.nightscout.rx.AapsSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject

View file

@ -3,11 +3,9 @@ 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.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumDeactivatePatchBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -3,11 +3,8 @@ 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.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumDeactivationCompleteBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -1,10 +1,7 @@
package info.nightscout.pump.medtrum.ui
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.ViewModelProvider
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumOverviewBinding
@ -15,7 +12,6 @@ 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.rx.logging.LTag
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject
@ -24,8 +20,6 @@ class MedtrumOverviewFragment : MedtrumBaseFragment<FragmentMedtrumOverviewBindi
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var medtrumPump: MedtrumPump
private lateinit var resultLauncherForResume: ActivityResultLauncher<Intent>
private lateinit var resultLauncherForPause: ActivityResultLauncher<Intent>
private var disposable: CompositeDisposable = CompositeDisposable()
@ -55,29 +49,15 @@ class MedtrumOverviewFragment : MedtrumBaseFragment<FragmentMedtrumOverviewBindi
else -> Unit
}
}
resultLauncherForResume = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
when (it.resultCode) {
// TODO Handle events here, see eopatch eventhandler
}
}
resultLauncherForPause = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
when (it.resultCode) {
// TODO Handle events here, see eopatch eventhandler
}
}
}
}
}
override fun onPause() {
super.onPause()
// TODO
}
override fun onResume() {
super.onResume()
// TODO
}
}

View file

@ -7,15 +7,16 @@ import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPreparePatchConnectBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class MedtrumPreparePatchConnectFragment : MedtrumBaseFragment<FragmentMedtrumPreparePatchConnectBinding>() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rh: ResourceHelper
companion object {
@ -33,11 +34,10 @@ class MedtrumPreparePatchConnectFragment : MedtrumBaseFragment<FragmentMedtrumPr
setupStep.observe(viewLifecycleOwner) {
when (it) {
MedtrumViewModel.SetupStep.INITIAL -> btnPositive.visibility = View.GONE
// TODO: Confirmation dialog
MedtrumViewModel.SetupStep.FILLED -> btnPositive.visibility = View.VISIBLE
MedtrumViewModel.SetupStep.ERROR -> {
ToastUtils.errorToast(requireContext(), "Error preparing patch") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
moveStep(PatchStep.CANCEL)
}

View file

@ -3,9 +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.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPreparePatchBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel

View file

@ -5,17 +5,18 @@ import android.view.View
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeCompleteBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class MedtrumPrimeCompleteFragment : MedtrumBaseFragment<FragmentMedtrumPrimeCompleteBinding>() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rh: ResourceHelper
companion object {
@ -33,13 +34,9 @@ class MedtrumPrimeCompleteFragment : MedtrumBaseFragment<FragmentMedtrumPrimeCom
when (it) {
MedtrumViewModel.SetupStep.INITIAL,
MedtrumViewModel.SetupStep.PRIMED -> Unit // Nothing to do here, previous state
MedtrumViewModel.SetupStep.ERROR -> {
ToastUtils.errorToast(requireContext(), "Error priming") // TODO: String resource and show error message
moveStep(PatchStep.CANCEL)
}
else -> {
ToastUtils.errorToast(requireContext(), "Unexpected state: $it") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
}
}

View file

@ -5,17 +5,18 @@ import android.view.View
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumPrimeBinding
import info.nightscout.pump.medtrum.ui.MedtrumBaseFragment
import info.nightscout.pump.medtrum.ui.viewmodel.MedtrumViewModel
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject
class MedtrumPrimeFragment : MedtrumBaseFragment<FragmentMedtrumPrimeBinding>() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rh: ResourceHelper
companion object {
@ -33,13 +34,9 @@ class MedtrumPrimeFragment : MedtrumBaseFragment<FragmentMedtrumPrimeBinding>()
when (it) {
MedtrumViewModel.SetupStep.INITIAL,
MedtrumViewModel.SetupStep.FILLED -> Unit // Nothing to do here, previous state
MedtrumViewModel.SetupStep.ERROR -> {
ToastUtils.errorToast(requireContext(), "Error priming") // TODO: String resource and show error message
moveStep(PatchStep.CANCEL)
}
else -> {
ToastUtils.errorToast(requireContext(), "Unexpected state: $it") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
}
}

View file

@ -41,11 +41,12 @@ class MedtrumPrimingFragment : MedtrumBaseFragment<FragmentMedtrumPrimingBinding
moveStep(PatchStep.ERROR)
updateSetupStep(MedtrumViewModel.SetupStep.FILLED) // Reset setup step
binding.textWaitForPriming.text = rh.gs(R.string.priming_error)
binding.btnNegative.visibility = View.VISIBLE
binding.btnPositive.visibility = View.VISIBLE
}
else -> {
ToastUtils.errorToast(requireContext(), "Unexpected state: $it") // TODO: String resource and show error message
ToastUtils.errorToast(requireContext(), rh.gs(R.string.unexpected_state, it.toString()))
aapsLogger.error(LTag.PUMP, "Unexpected state: $it")
}
}

View file

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.databinding.FragmentMedtrumStartDeactivationBinding

View file

@ -1,8 +1,6 @@
package info.nightscout.pump.medtrum.ui.viewmodel
import androidx.lifecycle.ViewModel
import info.nightscout.pump.medtrum.code.PatchStep
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.Disposable

View file

@ -10,7 +10,6 @@ import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.R
import info.nightscout.pump.medtrum.code.ConnectionState
import info.nightscout.pump.medtrum.comm.enums.AlarmState
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag

View file

@ -2,7 +2,6 @@ package info.nightscout.pump.medtrum.ui.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.queue.Callback
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.pump.medtrum.MedtrumPlugin
@ -17,13 +16,8 @@ import info.nightscout.pump.medtrum.encryption.Crypt
import info.nightscout.pump.medtrum.ui.MedtrumBaseNavigator
import info.nightscout.pump.medtrum.ui.event.SingleLiveEvent
import info.nightscout.pump.medtrum.ui.event.UIEvent
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventPumpStatusChanged
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
@ -31,15 +25,10 @@ import kotlinx.coroutines.launch
import javax.inject.Inject
class MedtrumViewModel @Inject constructor(
private val rh: ResourceHelper,
private val aapsLogger: AAPSLogger,
private val rxBus: RxBus,
private val aapsSchedulers: AapsSchedulers,
private val fabricPrivacy: FabricPrivacy,
private val medtrumPlugin: MedtrumPlugin,
private val commandQueue: CommandQueue,
val medtrumPump: MedtrumPump,
private val sp: SP
val medtrumPump: MedtrumPump
) : BaseViewModel<MedtrumBaseNavigator>() {
val patchStep = MutableLiveData<PatchStep>()
@ -70,16 +59,14 @@ class MedtrumViewModel @Inject constructor(
medtrumPump.lastConnection = System.currentTimeMillis()
}
ConnectionState.DISCONNECTED -> { // TODO: This is getting ridiciolous, refactor
if (patchStep.value != PatchStep.START_DEACTIVATION
&& patchStep.value != PatchStep.DEACTIVATE
&& patchStep.value != PatchStep.FORCE_DEACTIVATION
&& patchStep.value != PatchStep.DEACTIVATION_COMPLETE
&& patchStep.value != PatchStep.ACTIVATE_COMPLETE
&& patchStep.value != PatchStep.CANCEL
&& patchStep.value != PatchStep.ERROR
&& patchStep.value != PatchStep.PREPARE_PATCH
&& patchStep.value != PatchStep.PREPARE_PATCH_CONNECT
ConnectionState.DISCONNECTED -> {
if (patchStep.value in listOf(
PatchStep.PRIME,
PatchStep.PRIMING,
PatchStep.PRIME_COMPLETE,
PatchStep.ATTACH_PATCH,
PatchStep.ACTIVATE
)
) {
medtrumService?.connect("Try reconnect from viewModel")
}
@ -117,8 +104,7 @@ class MedtrumViewModel @Inject constructor(
}
MedtrumPumpState.PRIMING -> {
// updateSetupStep(SetupStep.PRIMING)
// TODO: What to do here? start prime counter?
// Do Nothing, wait for priming to complete
}
MedtrumPumpState.PRIMED, MedtrumPumpState.EJECTED -> {
@ -153,8 +139,15 @@ class MedtrumViewModel @Inject constructor(
if (oldPatchStep != newPatchStep) {
when (newPatchStep) {
PatchStep.CANCEL -> {
// TODO: Are you sure?
// TODO: Dont disconnect when deactivating
if (oldPatchStep !in listOf(
PatchStep.START_DEACTIVATION,
PatchStep.DEACTIVATE,
PatchStep.FORCE_DEACTIVATION,
PatchStep.DEACTIVATION_COMPLETE
)
) {
medtrumService?.disconnect("Cancel")
}
medtrumService?.disconnect("Cancel")
}
@ -173,7 +166,6 @@ class MedtrumViewModel @Inject constructor(
PatchStep.PREPARE_PATCH_CONNECT -> {
// Make sure we are disconnected, else dont move step
if (medtrumService?.isConnected == true) {
// TODO, replace with error message
aapsLogger.info(LTag.PUMP, "moveStep: connected, not moving step")
return
} else {

View file

@ -65,8 +65,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:contentDescription="@string/next"
android:text="@string/next"
android:contentDescription="@string/discard"
android:text="@string/discard"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_negative"

View file

@ -90,6 +90,7 @@
<string name ="step_deactivate">Deactivate Patch</string>
<string name ="step_deactivating">Deactivating...</string>
<string name ="step_deactivate_complete">Patch deactivated</string>
<string name ="unexpected_state">Unexpected state: %1$s</string>
<string name="base_serial">Pump Base Serial: %1$X</string>
<string name="patch_begin_activation">No active patch. Press <b>Next</b> to begin the activation process.</string>
@ -112,7 +113,7 @@
<string name="medtrum_deactivate_pump_confirm">Are you sure? This action cannot be reversed!!</string>
<string name="press_next_or_cancel">Press <b>Next</b> to deactivate or <b>Cancel</b> to return to main screen.</string>
<string name="deactivating_pump">Deactivating patch. Please Wait.</string>
<string name="deactivating_error">Failed to deactivate, press <b>Next</b> to forget patch.</string>
<string name="deactivating_error">Failed to deactivate, press <b>Discard</b> to forget patch.</string>
<string name="retract_needle">Retract needle. Remove patch from body.</string>
<string name="remove_base_discard_patch">Remove pump base and dispose of used patch appropriately.</string>
<string name="press_next_or_OK">Press <b>OK</b> to return to main screen. Press <b>Next</b> to start activation of new patch.</string>