Modified so that the basal rate of the EOPATCH2 overview screen is updated immediately when the basal profile is changed
This commit is contained in:
parent
2fe8b0ff84
commit
ad60009a1c
|
@ -80,6 +80,16 @@ class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
binding.viewmodel?.stopBasalRateUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
binding.viewmodel?.startBasalRateUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
private fun showToast(@StringRes strId: Int){
|
private fun showToast(@StringRes strId: Int){
|
||||||
Toast.makeText(requireContext(), strId, Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), strId, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
@ -69,7 +70,8 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
|
|
||||||
private val _patchRemainingInsulin = MutableLiveData(0f)
|
private val _patchRemainingInsulin = MutableLiveData(0f)
|
||||||
|
|
||||||
private var mDisposable: Disposable? = null
|
private var mPauseTimeDisposable: Disposable? = null
|
||||||
|
private var mBasalRateDisposable: Disposable? = null
|
||||||
|
|
||||||
val patchRemainingInsulin: LiveData<String>
|
val patchRemainingInsulin: LiveData<String>
|
||||||
get() = Transformations.map(_patchRemainingInsulin) { insulin ->
|
get() = Transformations.map(_patchRemainingInsulin) { insulin ->
|
||||||
|
@ -125,7 +127,7 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
.addTo()
|
.addTo()
|
||||||
|
|
||||||
if(preferenceManager.getPatchState().isNormalBasalPaused){
|
if(preferenceManager.getPatchState().isNormalBasalPaused){
|
||||||
startPeriodicallyUpdate()
|
startPauseTimeUpdate()
|
||||||
}else {
|
}else {
|
||||||
updateBasalInfo()
|
updateBasalInfo()
|
||||||
}
|
}
|
||||||
|
@ -198,7 +200,7 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
.subscribe({ response ->
|
.subscribe({ response ->
|
||||||
if (response.isSuccess) {
|
if (response.isSuccess) {
|
||||||
navigator?.toast(R.string.string_suspended_insulin_delivery_message)
|
navigator?.toast(R.string.string_suspended_insulin_delivery_message)
|
||||||
startPeriodicallyUpdate()
|
startPauseTimeUpdate()
|
||||||
} else {
|
} else {
|
||||||
UIEvent(EventType.PAUSE_BASAL_FAILED).apply { value = pauseDurationHour }.let { _eventHandler.postValue(it) }
|
UIEvent(EventType.PAUSE_BASAL_FAILED).apply { value = pauseDurationHour }.let { _eventHandler.postValue(it) }
|
||||||
}
|
}
|
||||||
|
@ -214,7 +216,7 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
.subscribe({
|
.subscribe({
|
||||||
if (it.isSuccess) {
|
if (it.isSuccess) {
|
||||||
navigator?.toast(R.string.string_resumed_insulin_delivery_message)
|
navigator?.toast(R.string.string_resumed_insulin_delivery_message)
|
||||||
stopPeriodicallyUpdate()
|
stopPauseTimeUpdate()
|
||||||
} else {
|
} else {
|
||||||
_eventHandler.postValue(UIEvent(EventType.RESUME_BASAL_FAILED))
|
_eventHandler.postValue(UIEvent(EventType.RESUME_BASAL_FAILED))
|
||||||
}
|
}
|
||||||
|
@ -223,16 +225,33 @@ class EopatchOverviewViewModel @Inject constructor(
|
||||||
}).addTo()
|
}).addTo()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startPeriodicallyUpdate(){
|
private fun startPauseTimeUpdate(){
|
||||||
if(mDisposable == null) {
|
if(mPauseTimeDisposable == null) {
|
||||||
mDisposable = Observable.interval(30, TimeUnit.SECONDS)
|
mPauseTimeDisposable = Observable.interval(30, TimeUnit.SECONDS)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe { updatePatchStatus() }
|
.subscribe { updatePatchStatus() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopPeriodicallyUpdate(){
|
private fun stopPauseTimeUpdate(){
|
||||||
mDisposable?.dispose()
|
mPauseTimeDisposable?.dispose()
|
||||||
mDisposable = null
|
mPauseTimeDisposable = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startBasalRateUpdate(){
|
||||||
|
val initialDelaySecs = Calendar.getInstance().let { c ->
|
||||||
|
(60 - c.get(Calendar.MINUTE) - 1) * 60 + (60 - c.get(Calendar.SECOND))
|
||||||
|
}
|
||||||
|
if(mBasalRateDisposable == null) {
|
||||||
|
mBasalRateDisposable = Observable.interval(initialDelaySecs.toLong(), 3600L, TimeUnit.SECONDS)
|
||||||
|
.observeOn(aapsSchedulers.main)
|
||||||
|
.subscribe { updateBasalInfo() }
|
||||||
|
}
|
||||||
|
updateBasalInfo()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopBasalRateUpdate(){
|
||||||
|
mBasalRateDisposable?.dispose()
|
||||||
|
mBasalRateDisposable = null
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue