[EOPATCH2]

1. Use ToastUtil
2. Restore invalid basal rate check
3. Fixed some bugs
This commit is contained in:
Alex Jung 2022-10-13 19:33:10 +09:00
parent 3db34f119c
commit 9e557fe623
18 changed files with 44 additions and 88 deletions

Binary file not shown.

View file

@ -22,7 +22,6 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import org.json.JSONArray
import org.json.JSONObject
import java.text.DecimalFormat
@ -99,7 +98,6 @@ sealed class ProfileSealed(
override fun isValid(from: String, pump: Pump, config: Config, rh: ResourceHelper, rxBus: RxBus, hardLimits: HardLimits, sendNotifications: Boolean): Profile.ValidityCheck {
val validityCheck = Profile.ValidityCheck()
val description = pump.pumpDescription
val notSupportedBasalRate = StringBuffer()
for (basal in basalBlocks) {
val basalAmount = basal.amount * percentage / 100.0
@ -144,20 +142,6 @@ sealed class ProfileSealed(
validityCheck.reasons.add(rh.gs(R.string.maximumbasalvaluereplaced, from))
break
}
if(pump.model() == PumpType.EOFLOW_EOPATCH2 && pct == 100){
val mod = (basalAmount * 1000) % (PumpType.EOFLOW_EOPATCH2.baseBasalStep * 1000)
if(!mod.nearlyEqual(0.0, 0.00000001)){
notSupportedBasalRate.append(
if(notSupportedBasalRate.isEmpty()) String.format("%.2f", basalAmount) else String.format(", %.2f", basalAmount)
)
}
}
}
if(notSupportedBasalRate.isNotEmpty()){
validityCheck.isValid = false
validityCheck.reasons.add(rh.gs(R.string.unsupportedBasalRate, "$notSupportedBasalRate U/h"))
}
if (!hardLimits.isInRange(dia, hardLimits.minDia(), hardLimits.maxDia())) {

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.utils.JsonHelper
import info.nightscout.androidaps.utils.T
import org.json.JSONObject
import java.util.*
import kotlin.math.abs
fun List<ProfileSwitch>.isPSEvent5minBack(time: Long): Boolean {
for (event in this) {
@ -159,16 +158,3 @@ fun ProfileSwitch.getCustomizedName(): String {
fun ProfileSwitch.GlucoseUnit.Companion.fromConstant(units: GlucoseUnit): ProfileSwitch.GlucoseUnit =
if (units == GlucoseUnit.MGDL) ProfileSwitch.GlucoseUnit.MGDL
else ProfileSwitch.GlucoseUnit.MMOL
fun Double.nearlyEqual(b: Double, epsilon: Double): Boolean {
val absA = abs(this)
val absB = abs(b)
val diff = abs(this - b)
return if (this == b) {
true
} else if (this == 0.0 || b == 0.0 || absA + absB < java.lang.Float.MIN_NORMAL) {
diff < epsilon * java.lang.Double.MIN_NORMAL
} else {
diff / (absA + absB).coerceAtMost(Double.MAX_VALUE) < epsilon
}
}

View file

@ -146,7 +146,6 @@
<string name="nochangerequested">변경사항 없음</string>
<!-- ProfileSwitch-->
<string name="zerovalueinprofile">유효하지 않은 프로파일: %1$s</string>
<string name="unsupportedBasalRate">지원하지 않는 베이젤 속도: %1$s</string>
<!-- Temptarget-->
<string name="mins">%1$d 분</string>

View file

@ -241,7 +241,6 @@
<!-- ProfileSwitch-->
<string name="zerovalueinprofile">Invalid profile: %1$s</string>
<string name="unsupportedBasalRate">Unsupported basal rate: %1$s</string>
<!-- Temptarget-->
<string name="mins">%1$d min</string>

Binary file not shown.

View file

@ -29,8 +29,9 @@ public class ActivateTask extends TaskBase {
.concatMapSingle(v -> SET_KEY.setKey())
.doOnNext(this::checkResponse)
.firstOrError()
.observeOn(Schedulers.io()).doOnSuccess(this::onActivated)
.observeOn(Schedulers.io())
.flatMap(v -> startBasalTask.start(enabled))
.doOnSuccess(this::onActivated)
.map(BaseResponse::isSuccess)
.doOnError(e -> aapsLogger.error(LTag.PUMPCOMM, (e.getMessage() != null) ? e.getMessage() : "ActivateTask error"));
}

View file

@ -6,7 +6,6 @@ enum class EventType {
SUSPEND_CLICKED,
RESUME_CLICKED,
INVALID_BASAL_RATE,
UNSUPPORTED_BASAL_RATE,
PROFILE_NOT_SET,
SHOW_PATCH_COMM_DIALOG,
DISMISS_PATCH_COMM_DIALOG,
@ -15,7 +14,9 @@ enum class EventType {
SHOW_CHANGE_PATCH_DIALOG,
FINISH_ACTIVITY,
SHOW_DISCARD_DIALOG,
PAUSE_BASAL_SUCCESS,
PAUSE_BASAL_FAILED,
RESUME_BASAL_SUCCESS,
RESUME_BASAL_FAILED
;
}

View file

@ -2,10 +2,8 @@ package info.nightscout.androidaps.plugins.pump.eopatch.ui
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
@ -41,14 +39,6 @@ abstract class EoBaseActivity<B : ViewDataBinding> : NoSplashAppCompatActivity()
}
override fun toast(message: String) {
Toast.makeText(this@EoBaseActivity, message, Toast.LENGTH_SHORT).show()
}
override fun toast(@StringRes message: Int) {
Toast.makeText(this@EoBaseActivity, message, Toast.LENGTH_SHORT).show()
}
override fun back() {
if(supportFragmentManager.backStackEntryCount == 0) {
finish()

View file

@ -56,14 +56,6 @@ abstract class EoBaseFragment<B : ViewDataBinding> : DaggerFragment(), EoBaseNav
baseActivity = null
}
override fun toast(message: String) {
baseActivity?.toast(message)
}
override fun toast(message: Int) {
baseActivity?.toast(message)
}
override fun back() {
baseActivity?.back()
}

View file

@ -1,12 +1,6 @@
package info.nightscout.androidaps.plugins.pump.eopatch.ui
import androidx.annotation.StringRes
interface EoBaseNavigator {
fun toast(message: String)
fun toast(@StringRes message: Int)
fun back()
fun finish(finishAffinity: Boolean = false)

View file

@ -2,13 +2,13 @@ package info.nightscout.androidaps.plugins.pump.eopatch.ui
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchViewModel.SetupStep.*
import info.nightscout.androidaps.plugins.pump.eopatch.R
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchStep
import info.nightscout.androidaps.plugins.pump.eopatch.databinding.FragmentEopatchConnectNewBinding
import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchViewModel
import info.nightscout.androidaps.utils.ToastUtils
class EopatchConnectNewFragment : EoBaseFragment<FragmentEopatchConnectNewBinding>() {
@ -29,7 +29,7 @@ class EopatchConnectNewFragment : EoBaseFragment<FragmentEopatchConnectNewBindin
BONDING_FAILED -> checkCommunication({ retryScan() }, { moveStep(PatchStep.WAKE_UP) })
GET_PATCH_INFO_FAILED -> checkCommunication({ getPatchInfo() }, { moveStep(PatchStep.WAKE_UP) })
SELF_TEST_FAILED -> checkCommunication({ selfTest() }, { moveStep(PatchStep.WAKE_UP) })
ACTIVATION_FAILED -> Toast.makeText(requireContext(), "Activation failed!", Toast.LENGTH_LONG).show()
ACTIVATION_FAILED -> ToastUtils.errorToast(requireContext(), "Activation failed!")
else -> Unit
}
}

View file

@ -3,10 +3,8 @@ package info.nightscout.androidaps.plugins.pump.eopatch.ui
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
import androidx.lifecycle.ViewModelProvider
import dagger.android.support.DaggerAppCompatActivity
import info.nightscout.androidaps.plugins.bus.RxBus
@ -17,6 +15,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.code.EventType
import info.nightscout.androidaps.plugins.pump.eopatch.databinding.FragmentEopatchOverviewBinding
import info.nightscout.androidaps.plugins.pump.eopatch.extension.takeOne
import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchOverviewViewModel
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.AlertDialogHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
@ -52,11 +51,12 @@ class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>()
EventType.DEACTIVATION_CLICKED -> requireContext().apply { startActivity(EopatchActivity.createIntentForChangePatch(this)) }
EventType.SUSPEND_CLICKED -> suspend()
EventType.RESUME_CLICKED -> resume()
EventType.INVALID_BASAL_RATE -> showToast(R.string.invalid_basal_rate)
EventType.UNSUPPORTED_BASAL_RATE -> showToast(R.string.unsupported_basal_rate, evt.value)
EventType.PROFILE_NOT_SET -> showToast(R.string.no_profile_selected)
EventType.PAUSE_BASAL_FAILED -> showToast(R.string.string_pause_failed)
EventType.RESUME_BASAL_FAILED -> showToast(R.string.string_resume_failed)
EventType.INVALID_BASAL_RATE -> ToastUtils.infoToast(requireContext(), R.string.invalid_basal_rate)
EventType.PROFILE_NOT_SET -> ToastUtils.infoToast(requireContext(), R.string.no_profile_selected)
EventType.PAUSE_BASAL_SUCCESS -> ToastUtils.infoToast(requireContext(), R.string.string_suspended_insulin_delivery_message)
EventType.PAUSE_BASAL_FAILED -> ToastUtils.errorToast(requireContext(), R.string.string_pause_failed)
EventType.RESUME_BASAL_SUCCESS -> ToastUtils.infoToast(requireContext(), R.string.string_resumed_insulin_delivery_message)
EventType.RESUME_BASAL_FAILED -> ToastUtils.errorToast(requireContext(), R.string.string_resume_failed)
else -> Unit
}
}
@ -64,7 +64,7 @@ class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>()
resultLauncherForResume = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
when (it.resultCode) {
DaggerAppCompatActivity.RESULT_OK -> resumeBasal()
DaggerAppCompatActivity.RESULT_CANCELED -> showToast(R.string.string_resume_failed)
DaggerAppCompatActivity.RESULT_CANCELED -> ToastUtils.errorToast(requireContext(), R.string.string_resume_failed)
}
}
@ -74,7 +74,7 @@ class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>()
pauseBasal(pauseDuration)
pauseDuration = 0.5f
}
DaggerAppCompatActivity.RESULT_CANCELED -> showToast(R.string.string_pause_failed)
DaggerAppCompatActivity.RESULT_CANCELED -> ToastUtils.errorToast(requireContext(), R.string.string_pause_failed)
}
}
}
@ -91,13 +91,6 @@ class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>()
binding.viewmodel?.startBasalRateUpdate()
}
private fun showToast(@StringRes strId: Int, value: Any? = null){
if(value == null)
Toast.makeText(requireContext(), strId, Toast.LENGTH_SHORT).show()
else
Toast.makeText(requireContext(), getString(strId, value.toString()), Toast.LENGTH_SHORT).show()
}
private fun suspend() {
binding.viewmodel?.apply {
activity?.let {

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.R
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchStep
import info.nightscout.androidaps.plugins.pump.eopatch.databinding.FragmentEopatchRotateKnobBinding
import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchViewModel
import info.nightscout.androidaps.utils.ToastUtils
class EopatchRotateKnobFragment : EoBaseFragment<FragmentEopatchRotateKnobBinding>() {
@ -33,10 +34,11 @@ class EopatchRotateKnobFragment : EoBaseFragment<FragmentEopatchRotateKnobBindin
updateLayoutParams<ViewGroup.MarginLayoutParams> { leftMargin = 3 }
text = getString(R.string.retry)
}
textPatchRotateKnobDesc.visibility = View.VISIBLE
layoutNeedleInsertionError.visibility = View.VISIBLE
textRotateKnobDesc2.visibility = View.GONE
textRotateKnobDesc2NeedleInsertionError.visibility = View.VISIBLE
textActivationErrorDesc.visibility = View.GONE
}
setupStep.observe(viewLifecycleOwner) {
@ -44,6 +46,20 @@ class EopatchRotateKnobFragment : EoBaseFragment<FragmentEopatchRotateKnobBindin
EopatchViewModel.SetupStep.NEEDLE_SENSING_FAILED -> {
checkCommunication({ startNeedleSensing() })
}
EopatchViewModel.SetupStep.ACTIVATION_FAILED -> {
btnNegative.visibility = View.VISIBLE
guidelineButton.setGuidelinePercent(0.4f)
btnPositive.apply {
updateLayoutParams<ViewGroup.MarginLayoutParams> { leftMargin = 3 }
text = getString(R.string.retry)
}
textPatchRotateKnobDesc.visibility = View.GONE
textRotateKnobDesc2.visibility = View.GONE
textRotateKnobDesc2NeedleInsertionError.visibility = View.VISIBLE
textActivationErrorDesc.visibility = View.VISIBLE
ToastUtils.errorToast(requireContext(), "Activation failed!")
}
else -> Unit
}
}

View file

@ -16,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.pump.eopatch.extension.nearlyEqual
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
@ -180,12 +179,6 @@ class EopatchOverviewViewModel @Inject constructor(
isValid = false
break
}
val mod = (basalRate.value * 1000) % (0.05 * 1000)
if(!mod.nearlyEqual(0.0, 0.00000001)){
_eventHandler.postValue(UIEvent(EventType.UNSUPPORTED_BASAL_RATE).apply { value = basalRate.value })
isValid = false
break
}
}
if(isValid) {
@ -215,7 +208,7 @@ class EopatchOverviewViewModel @Inject constructor(
.observeOn(aapsSchedulers.main)
.subscribe({ response ->
if (response.isSuccess) {
navigator?.toast(R.string.string_suspended_insulin_delivery_message)
UIEvent(EventType.PAUSE_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
startPauseTimeUpdate()
} else {
UIEvent(EventType.PAUSE_BASAL_FAILED).apply { value = pauseDurationHour }.let { _eventHandler.postValue(it) }
@ -231,7 +224,7 @@ class EopatchOverviewViewModel @Inject constructor(
.observeOn(aapsSchedulers.main)
.subscribe({
if (it.isSuccess) {
navigator?.toast(R.string.string_resumed_insulin_delivery_message)
UIEvent(EventType.RESUME_BASAL_SUCCESS).let { _eventHandler.postValue(it) }
stopPauseTimeUpdate()
} else {
_eventHandler.postValue(UIEvent(EventType.RESUME_BASAL_FAILED))

View file

@ -140,6 +140,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_needle_insertion_error" />
<TextView
android:id="@+id/text_activation_error_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/needle_insertion_error_3"
android:textSize="16sp"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_needle_insertion_error" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout

View file

@ -23,7 +23,6 @@
<string name="invalid_basal_rate">프로파일에 설정된 베이젤 속도가 0.05 U/hr 보다 작습니다. 이오패치는 최소 주입 단위가 0.05U 입니다. 최소 주입 단위 이상으로 프로파일 설정 후 다시 시도해 주세요.</string>
<string name="no_profile_selected">프로파일이 선택되지 않았습니다. 프로파일 선택 후 다시 시도해 주세요.</string>
<string name="unsupported_basal_rate">베이젤 속도 %1$s U/hr는 이오패치에서 지원되지 않습니다.</string>
<string name="symbol_day">day</string>
<string name="symbol_plus">+</string>

View file

@ -34,7 +34,6 @@
<string name="invalid_basal_rate">The basal of the profile is less than 0.05 U/hr. EOPatch has a minimum injection unit of 0.05U. Please try again after setting the profile to more than the minimum injection unit.</string>
<string name="no_profile_selected">No profile selected. Please select a profile and try again.</string>
<string name="unsupported_basal_rate">Basal rate %1$s U/hr is not supported by EOPatch.</string>
<string name="symbol_day">day</string>
<string name="symbol_plus">+</string>