2020-12-25 16:47:42 +01:00
|
|
|
package info.nightscout.androidaps.dialogs
|
|
|
|
|
2021-01-01 11:37:24 +01:00
|
|
|
import android.content.Context
|
2020-12-25 16:47:42 +01:00
|
|
|
import android.os.Bundle
|
2021-01-01 16:44:25 +01:00
|
|
|
import android.os.Handler
|
2021-11-25 20:19:27 +01:00
|
|
|
import android.os.HandlerThread
|
2020-12-27 15:32:12 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.Window
|
|
|
|
import android.view.WindowManager
|
2020-12-25 16:47:42 +01:00
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import dagger.android.support.DaggerDialogFragment
|
|
|
|
import info.nightscout.androidaps.R
|
2020-12-26 17:40:16 +01:00
|
|
|
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
2021-05-28 16:06:44 +02:00
|
|
|
import info.nightscout.androidaps.database.AppRepository
|
|
|
|
import info.nightscout.androidaps.database.entities.OfflineEvent
|
2021-03-31 00:18:55 +02:00
|
|
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
|
|
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
2021-05-28 16:06:44 +02:00
|
|
|
import info.nightscout.androidaps.database.transactions.CancelCurrentOfflineEventIfAnyTransaction
|
|
|
|
import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentOfflineEventTransaction
|
2020-12-27 16:20:32 +01:00
|
|
|
import info.nightscout.androidaps.databinding.DialogLoopBinding
|
2021-02-14 15:09:06 +01:00
|
|
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
|
|
|
import info.nightscout.androidaps.events.EventRefreshOverview
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.extensions.runOnUiThread
|
|
|
|
import info.nightscout.androidaps.extensions.toVisibility
|
2020-12-26 17:40:16 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.*
|
2020-12-25 16:47:42 +01:00
|
|
|
import info.nightscout.androidaps.logging.AAPSLogger
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.logging.LTag
|
2021-02-09 17:57:28 +01:00
|
|
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
2021-10-15 14:56:22 +02:00
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
2020-12-27 15:32:12 +01:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
|
2020-12-26 17:40:16 +01:00
|
|
|
import info.nightscout.androidaps.queue.Callback
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.utils.DateUtil
|
2020-12-27 15:32:12 +01:00
|
|
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
2021-11-25 20:19:27 +01:00
|
|
|
import info.nightscout.androidaps.utils.T
|
2020-12-27 15:32:12 +01:00
|
|
|
import info.nightscout.androidaps.utils.ToastUtils
|
2020-12-26 17:40:16 +01:00
|
|
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
2020-12-25 16:47:42 +01:00
|
|
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
2021-05-28 16:06:44 +02:00
|
|
|
import io.reactivex.disposables.CompositeDisposable
|
|
|
|
import io.reactivex.rxkotlin.plusAssign
|
2020-12-25 16:47:42 +01:00
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
class LoopDialog : DaggerDialogFragment() {
|
|
|
|
|
|
|
|
@Inject lateinit var aapsLogger: AAPSLogger
|
2021-01-01 11:37:24 +01:00
|
|
|
@Inject lateinit var ctx: Context
|
2020-12-25 16:47:42 +01:00
|
|
|
@Inject lateinit var sp: SP
|
2021-10-15 14:56:22 +02:00
|
|
|
@Inject lateinit var rxBus: RxBus
|
2020-12-25 16:47:42 +01:00
|
|
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
2021-11-04 10:56:12 +01:00
|
|
|
@Inject lateinit var rh: ResourceHelper
|
2020-12-25 16:47:42 +01:00
|
|
|
@Inject lateinit var profileFunction: ProfileFunction
|
2021-11-30 17:08:31 +01:00
|
|
|
@Inject lateinit var loop: Loop
|
2021-04-14 00:45:30 +02:00
|
|
|
@Inject lateinit var activePlugin: ActivePlugin
|
2020-12-27 15:32:12 +01:00
|
|
|
@Inject lateinit var constraintChecker: ConstraintChecker
|
2021-11-07 17:19:06 +01:00
|
|
|
@Inject lateinit var commandQueue: CommandQueue
|
2021-04-13 23:27:55 +02:00
|
|
|
@Inject lateinit var configBuilder: ConfigBuilder
|
2021-02-09 17:57:28 +01:00
|
|
|
@Inject lateinit var uel: UserEntryLogger
|
2021-05-28 16:06:44 +02:00
|
|
|
@Inject lateinit var dateUtil: DateUtil
|
|
|
|
@Inject lateinit var repository: AppRepository
|
2021-08-29 22:24:52 +02:00
|
|
|
@Inject lateinit var objectivePlugin: ObjectivesPlugin
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2020-12-26 17:40:16 +01:00
|
|
|
private var showOkCancel: Boolean = true
|
2020-12-27 16:20:32 +01:00
|
|
|
private var _binding: DialogLoopBinding? = null
|
2021-11-25 20:19:27 +01:00
|
|
|
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
2021-08-06 00:08:49 +02:00
|
|
|
private lateinit var refreshDialog: Runnable
|
2021-02-14 15:09:06 +01:00
|
|
|
|
2020-12-27 16:20:32 +01:00
|
|
|
// This property is only valid between onCreateView and
|
|
|
|
// onDestroyView.
|
|
|
|
private val binding get() = _binding!!
|
2020-12-26 17:40:16 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
val disposable = CompositeDisposable()
|
|
|
|
|
2020-12-25 16:47:42 +01:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
2021-08-28 20:58:27 +02:00
|
|
|
dialog?.window?.setLayout(
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
|
|
|
)
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
|
|
|
super.onSaveInstanceState(savedInstanceState)
|
2020-12-26 17:40:16 +01:00
|
|
|
savedInstanceState.putInt("showOkCancel", if (showOkCancel) 1 else 0)
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:19:27 +01:00
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View {
|
2020-12-26 17:40:16 +01:00
|
|
|
// load data from bundle
|
|
|
|
(savedInstanceState ?: arguments)?.let { bundle ->
|
|
|
|
showOkCancel = bundle.getInt("showOkCancel", 1) == 1
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
|
|
|
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
|
|
|
isCancelable = true
|
|
|
|
dialog?.setCanceledOnTouchOutside(false)
|
|
|
|
|
2020-12-27 16:20:32 +01:00
|
|
|
_binding = DialogLoopBinding.inflate(inflater, container, false)
|
|
|
|
return binding.root
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
2020-12-26 17:40:16 +01:00
|
|
|
updateGUI("LoopDialogOnViewCreated")
|
|
|
|
|
2020-12-28 12:21:31 +01:00
|
|
|
binding.overviewCloseloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewLgsloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewOpenloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisable.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewEnable.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewResume.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewReconnect.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewSuspend1h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewSuspend2h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewSuspend3h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewSuspend10h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisconnect15m.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisconnect30m.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisconnect1h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisconnect2h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
|
|
|
binding.overviewDisconnect3h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
|
2020-12-25 16:47:42 +01:00
|
|
|
|
|
|
|
// cancel button
|
2020-12-27 16:20:32 +01:00
|
|
|
binding.cancel.setOnClickListener { dismiss() }
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-01-01 16:44:25 +01:00
|
|
|
refreshDialog = Runnable {
|
2021-11-25 20:19:27 +01:00
|
|
|
runOnUiThread { updateGUI("refreshDialog") }
|
|
|
|
handler.postDelayed(refreshDialog, 15 * 1000L)
|
2021-01-01 16:44:25 +01:00
|
|
|
}
|
2021-11-25 20:19:27 +01:00
|
|
|
handler.postDelayed(refreshDialog, 15 * 1000L)
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
2020-12-28 12:21:31 +01:00
|
|
|
@Synchronized
|
2020-12-25 16:47:42 +01:00
|
|
|
override fun onDestroyView() {
|
|
|
|
super.onDestroyView()
|
2020-12-28 12:21:31 +01:00
|
|
|
_binding = null
|
2021-11-25 20:19:27 +01:00
|
|
|
handler.removeCallbacksAndMessages(null)
|
2021-05-28 16:06:44 +02:00
|
|
|
disposable.clear()
|
2021-01-01 16:44:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var task: Runnable? = null
|
|
|
|
|
2020-12-28 12:21:31 +01:00
|
|
|
@Synchronized
|
2020-12-26 17:40:16 +01:00
|
|
|
fun updateGUI(from: String) {
|
2020-12-28 12:21:31 +01:00
|
|
|
if (_binding == null) return
|
2020-12-26 17:40:16 +01:00
|
|
|
aapsLogger.debug("UpdateGUI from $from")
|
|
|
|
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
|
2021-02-16 11:46:34 +01:00
|
|
|
val closedLoopAllowed = constraintChecker.isClosedLoopAllowed(Constraint(true))
|
2021-08-29 22:24:52 +02:00
|
|
|
val closedLoopAllowed2 = objectivePlugin.objectives[ObjectivesPlugin.MAXIOB_OBJECTIVE].isCompleted
|
2021-02-16 11:46:34 +01:00
|
|
|
val lgsEnabled = constraintChecker.isLgsAllowed(Constraint(true))
|
2020-12-28 12:21:31 +01:00
|
|
|
val apsMode = sp.getString(R.string.key_aps_mode, "open")
|
2021-08-17 08:30:10 +02:00
|
|
|
val pump = activePlugin.activePump
|
2021-08-19 01:01:12 +02:00
|
|
|
|
2021-08-25 09:00:13 +02:00
|
|
|
binding.overviewDisconnect15m.visibility = pumpDescription.tempDurationStep15mAllowed.toVisibility()
|
|
|
|
binding.overviewDisconnect30m.visibility = pumpDescription.tempDurationStep30mAllowed.toVisibility()
|
2021-08-19 01:01:12 +02:00
|
|
|
when {
|
|
|
|
pump.isSuspended() -> {
|
|
|
|
binding.overviewLoop.visibility = View.GONE
|
|
|
|
binding.overviewSuspend.visibility = View.GONE
|
|
|
|
binding.overviewPump.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
|
|
|
!profileFunction.isProfileValid("LoopDialogUpdateGUI") -> {
|
|
|
|
binding.overviewLoop.visibility = View.GONE
|
|
|
|
binding.overviewSuspend.visibility = View.GONE
|
|
|
|
binding.overviewPump.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.isDisconnected -> {
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewLoop.visibility = View.GONE
|
|
|
|
binding.overviewSuspend.visibility = View.GONE
|
|
|
|
binding.overviewPump.visibility = View.VISIBLE
|
2021-11-04 10:56:12 +01:00
|
|
|
binding.overviewPumpHeader.text = rh.gs(R.string.reconnect)
|
2021-08-19 22:16:38 +02:00
|
|
|
binding.overviewDisconnectButtons.visibility = View.VISIBLE
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewReconnect.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:08:31 +01:00
|
|
|
!(loop as PluginBase).isEnabled() -> {
|
2021-08-29 22:24:52 +02:00
|
|
|
binding.overviewLoop.visibility = View.VISIBLE
|
|
|
|
binding.overviewEnable.visibility = View.VISIBLE
|
|
|
|
binding.overviewDisable.visibility = View.GONE
|
|
|
|
binding.overviewSuspend.visibility = View.GONE
|
|
|
|
binding.overviewPump.visibility = View.VISIBLE
|
|
|
|
binding.overviewReconnect.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.isSuspended -> {
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewLoop.visibility = View.GONE
|
|
|
|
binding.overviewSuspend.visibility = View.VISIBLE
|
2021-11-04 10:56:12 +01:00
|
|
|
binding.overviewSuspendHeader.text = rh.gs(R.string.resumeloop)
|
2021-08-19 22:16:38 +02:00
|
|
|
binding.overviewSuspendButtons.visibility = View.VISIBLE
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewResume.visibility = View.VISIBLE
|
2021-09-10 00:34:17 +02:00
|
|
|
binding.overviewPump.visibility = View.GONE
|
2021-08-25 09:00:13 +02:00
|
|
|
binding.overviewReconnect.visibility = View.GONE
|
2021-08-19 01:01:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
binding.overviewLoop.visibility = View.VISIBLE
|
|
|
|
binding.overviewEnable.visibility = View.GONE
|
|
|
|
when {
|
2021-08-29 22:24:52 +02:00
|
|
|
apsMode == "closed" -> {
|
|
|
|
binding.overviewCloseloop.visibility = View.GONE
|
|
|
|
binding.overviewLgsloop.visibility = View.VISIBLE
|
|
|
|
binding.overviewOpenloop.visibility = View.VISIBLE
|
2021-08-19 01:01:12 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:19:27 +01:00
|
|
|
apsMode == "lgs" -> {
|
2021-08-29 22:24:52 +02:00
|
|
|
binding.overviewCloseloop.visibility = closedLoopAllowed.value().toVisibility() //show Close loop button only if Close loop allowed
|
2021-08-28 20:58:27 +02:00
|
|
|
binding.overviewLgsloop.visibility = View.GONE
|
2021-08-29 22:24:52 +02:00
|
|
|
binding.overviewOpenloop.visibility = View.VISIBLE
|
2021-08-28 20:58:27 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:19:27 +01:00
|
|
|
apsMode == "open" -> {
|
|
|
|
binding.overviewCloseloop.visibility =
|
|
|
|
closedLoopAllowed2.toVisibility() //show CloseLoop button only if Objective 6 is completed (closedLoopAllowed always false in open loop mode)
|
2021-08-29 22:24:52 +02:00
|
|
|
binding.overviewLgsloop.visibility = lgsEnabled.value().toVisibility()
|
|
|
|
binding.overviewOpenloop.visibility = View.GONE
|
2021-08-19 01:01:12 +02:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:19:27 +01:00
|
|
|
else -> {
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewCloseloop.visibility = View.GONE
|
|
|
|
binding.overviewLgsloop.visibility = View.GONE
|
|
|
|
binding.overviewOpenloop.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.overviewSuspend.visibility = View.VISIBLE
|
2021-11-04 10:56:12 +01:00
|
|
|
binding.overviewSuspendHeader.text = rh.gs(R.string.suspendloop)
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewSuspendButtons.visibility = View.VISIBLE
|
|
|
|
binding.overviewResume.visibility = View.GONE
|
|
|
|
|
|
|
|
binding.overviewPump.visibility = View.VISIBLE
|
2021-11-04 10:56:12 +01:00
|
|
|
binding.overviewPumpHeader.text = rh.gs(R.string.disconnectpump)
|
2021-08-19 01:01:12 +02:00
|
|
|
binding.overviewDisconnectButtons.visibility = View.VISIBLE
|
|
|
|
binding.overviewReconnect.visibility = View.GONE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-01-01 11:37:24 +01:00
|
|
|
private fun onClickOkCancelEnabled(v: View): Boolean {
|
2020-12-26 17:40:16 +01:00
|
|
|
var description = ""
|
2020-12-28 12:21:31 +01:00
|
|
|
when (v.id) {
|
2021-11-04 10:56:12 +01:00
|
|
|
R.id.overview_closeloop -> description = rh.gs(R.string.closedloop)
|
|
|
|
R.id.overview_lgsloop -> description = rh.gs(R.string.lowglucosesuspend)
|
|
|
|
R.id.overview_openloop -> description = rh.gs(R.string.openloop)
|
|
|
|
R.id.overview_disable -> description = rh.gs(R.string.disableloop)
|
|
|
|
R.id.overview_enable -> description = rh.gs(R.string.enableloop)
|
|
|
|
R.id.overview_resume -> description = rh.gs(R.string.resume)
|
|
|
|
R.id.overview_reconnect -> description = rh.gs(R.string.reconnect)
|
|
|
|
R.id.overview_suspend_1h -> description = rh.gs(R.string.suspendloopfor1h)
|
|
|
|
R.id.overview_suspend_2h -> description = rh.gs(R.string.suspendloopfor2h)
|
|
|
|
R.id.overview_suspend_3h -> description = rh.gs(R.string.suspendloopfor3h)
|
|
|
|
R.id.overview_suspend_10h -> description = rh.gs(R.string.suspendloopfor10h)
|
|
|
|
R.id.overview_disconnect_15m -> description = rh.gs(R.string.disconnectpumpfor15m)
|
|
|
|
R.id.overview_disconnect_30m -> description = rh.gs(R.string.disconnectpumpfor30m)
|
|
|
|
R.id.overview_disconnect_1h -> description = rh.gs(R.string.disconnectpumpfor1h)
|
|
|
|
R.id.overview_disconnect_2h -> description = rh.gs(R.string.disconnectpumpfor2h)
|
|
|
|
R.id.overview_disconnect_3h -> description = rh.gs(R.string.disconnectpumpfor3h)
|
2020-12-26 17:40:16 +01:00
|
|
|
}
|
|
|
|
activity?.let { activity ->
|
2021-11-04 10:56:12 +01:00
|
|
|
OKDialog.showConfirmation(activity, rh.gs(R.string.confirm), description, Runnable {
|
2020-12-26 17:40:16 +01:00
|
|
|
onClick(v)
|
|
|
|
})
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2020-12-26 17:40:16 +01:00
|
|
|
fun onClick(v: View): Boolean {
|
|
|
|
when (v.id) {
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_closeloop -> {
|
2021-04-01 19:27:13 +02:00
|
|
|
uel.log(Action.CLOSED_LOOP_MODE, Sources.LoopDialog)
|
2020-12-27 15:32:12 +01:00
|
|
|
sp.putString(R.string.key_aps_mode, "closed")
|
2021-11-04 10:56:12 +01:00
|
|
|
rxBus.send(EventPreferenceChange(rh.gs(R.string.closedloop)))
|
2020-12-28 12:21:31 +01:00
|
|
|
return true
|
2020-12-27 15:32:12 +01:00
|
|
|
}
|
2020-12-28 12:21:31 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_lgsloop -> {
|
2021-04-01 19:27:13 +02:00
|
|
|
uel.log(Action.LGS_LOOP_MODE, Sources.LoopDialog)
|
2020-12-27 15:32:12 +01:00
|
|
|
sp.putString(R.string.key_aps_mode, "lgs")
|
2021-11-04 10:56:12 +01:00
|
|
|
rxBus.send(EventPreferenceChange(rh.gs(R.string.lowglucosesuspend)))
|
2020-12-28 12:21:31 +01:00
|
|
|
return true
|
2020-12-27 15:32:12 +01:00
|
|
|
}
|
2020-12-28 12:21:31 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_openloop -> {
|
2021-04-01 19:27:13 +02:00
|
|
|
uel.log(Action.OPEN_LOOP_MODE, Sources.LoopDialog)
|
2020-12-27 15:32:12 +01:00
|
|
|
sp.putString(R.string.key_aps_mode, "open")
|
2021-11-04 10:56:12 +01:00
|
|
|
rxBus.send(EventPreferenceChange(rh.gs(R.string.lowglucosesuspend)))
|
2020-12-28 12:21:31 +01:00
|
|
|
return true
|
2020-12-27 15:32:12 +01:00
|
|
|
}
|
2020-12-28 12:21:31 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disable -> {
|
2021-04-01 19:27:13 +02:00
|
|
|
uel.log(Action.LOOP_DISABLED, Sources.LoopDialog)
|
2021-11-30 17:08:31 +01:00
|
|
|
(loop as PluginBase).setPluginEnabled(PluginType.LOOP, false)
|
|
|
|
(loop as PluginBase).setFragmentVisible(PluginType.LOOP, false)
|
2021-04-13 23:27:55 +02:00
|
|
|
configBuilder.storeSettings("DisablingLoop")
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
commandQueue.cancelTempBasal(true, object : Callback() {
|
|
|
|
override fun run() {
|
|
|
|
if (!result.success) {
|
2021-11-04 10:56:12 +01:00
|
|
|
ToastUtils.showToastInUiThread(ctx, rh.gs(R.string.tempbasaldeliveryerror))
|
2020-12-26 17:40:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-05-28 16:06:44 +02:00
|
|
|
disposable += repository.runTransactionForResult(InsertAndCancelCurrentOfflineEventTransaction(dateUtil.now(), T.days(365).msecs(), OfflineEvent.Reason.DISABLE_LOOP))
|
|
|
|
.subscribe({ result ->
|
2021-11-25 20:19:27 +01:00
|
|
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated OfflineEvent $it") }
|
|
|
|
result.inserted.forEach { aapsLogger.debug(LTag.DATABASE, "Inserted OfflineEvent $it") }
|
|
|
|
}, {
|
|
|
|
aapsLogger.error(LTag.DATABASE, "Error while saving OfflineEvent", it)
|
|
|
|
})
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_enable -> {
|
2021-04-01 19:27:13 +02:00
|
|
|
uel.log(Action.LOOP_ENABLED, Sources.LoopDialog)
|
2021-11-30 17:08:31 +01:00
|
|
|
(loop as PluginBase).setPluginEnabled(PluginType.LOOP, true)
|
|
|
|
(loop as PluginBase).setFragmentVisible(PluginType.LOOP, true)
|
2021-04-13 23:27:55 +02:00
|
|
|
configBuilder.storeSettings("EnablingLoop")
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2021-05-28 16:06:44 +02:00
|
|
|
disposable += repository.runTransactionForResult(CancelCurrentOfflineEventIfAnyTransaction(dateUtil.now()))
|
|
|
|
.subscribe({ result ->
|
2021-11-25 20:19:27 +01:00
|
|
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated OfflineEvent $it") }
|
|
|
|
}, {
|
|
|
|
aapsLogger.error(LTag.DATABASE, "Error while saving OfflineEvent", it)
|
|
|
|
})
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2020-12-27 15:32:12 +01:00
|
|
|
R.id.overview_resume, R.id.overview_reconnect -> {
|
2021-05-28 16:06:44 +02:00
|
|
|
uel.log(if (v.id == R.id.overview_resume) Action.RESUME else Action.RECONNECT, Sources.LoopDialog)
|
|
|
|
disposable += repository.runTransactionForResult(CancelCurrentOfflineEventIfAnyTransaction(dateUtil.now()))
|
|
|
|
.subscribe({ result ->
|
2021-11-25 20:19:27 +01:00
|
|
|
result.updated.forEach { aapsLogger.debug(LTag.DATABASE, "Updated OfflineEvent $it") }
|
|
|
|
}, {
|
|
|
|
aapsLogger.error(LTag.DATABASE, "Error while saving OfflineEvent", it)
|
|
|
|
})
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
commandQueue.cancelTempBasal(true, object : Callback() {
|
|
|
|
override fun run() {
|
|
|
|
if (!result.success) {
|
2021-11-04 10:56:12 +01:00
|
|
|
ErrorHelperActivity.runAlarm(ctx, result.comment, rh.gs(R.string.tempbasaldeliveryerror), R.raw.boluserror)
|
2020-12-26 17:40:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
sp.putBoolean(R.string.key_objectiveusereconnect, true)
|
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_suspend_1h -> {
|
2021-04-03 21:29:26 +02:00
|
|
|
uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(1))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.suspendLoop(T.hours(1).mins().toInt())
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_suspend_2h -> {
|
2021-04-03 21:29:26 +02:00
|
|
|
uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(2))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.suspendLoop(T.hours(2).mins().toInt())
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_suspend_3h -> {
|
2021-04-03 21:29:26 +02:00
|
|
|
uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(3))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.suspendLoop(T.hours(3).mins().toInt())
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_suspend_10h -> {
|
2021-04-03 21:29:26 +02:00
|
|
|
uel.log(Action.SUSPEND, Sources.LoopDialog, ValueWithUnit.Hour(10))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.suspendLoop(T.hours(10).mins().toInt())
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disconnect_15m -> {
|
2021-06-01 22:34:18 +02:00
|
|
|
profileFunction.getProfile()?.let { profile ->
|
|
|
|
uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(15))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.goToZeroTemp(T.mins(15).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disconnect_30m -> {
|
2021-06-01 22:34:18 +02:00
|
|
|
profileFunction.getProfile()?.let { profile ->
|
|
|
|
uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Minute(30))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.goToZeroTemp(T.mins(30).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
|
|
|
}
|
2020-12-25 16:47:42 +01:00
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disconnect_1h -> {
|
2021-06-01 22:34:18 +02:00
|
|
|
profileFunction.getProfile()?.let { profile ->
|
|
|
|
uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(1))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.goToZeroTemp(T.hours(1).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
|
|
|
}
|
2021-10-18 20:10:18 +02:00
|
|
|
sp.putBoolean(R.string.key_objectiveusedisconnect, true)
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disconnect_2h -> {
|
2021-06-01 22:34:18 +02:00
|
|
|
profileFunction.getProfile()?.let { profile ->
|
|
|
|
uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(2))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.goToZeroTemp(T.hours(2).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-05-28 16:06:44 +02:00
|
|
|
R.id.overview_disconnect_3h -> {
|
2021-06-01 22:34:18 +02:00
|
|
|
profileFunction.getProfile()?.let { profile ->
|
|
|
|
uel.log(Action.DISCONNECT, Sources.LoopDialog, ValueWithUnit.Hour(3))
|
2021-11-30 17:08:31 +01:00
|
|
|
loop.goToZeroTemp(T.hours(3).mins().toInt(), profile, OfflineEvent.Reason.DISCONNECT_PUMP)
|
2021-06-01 22:34:18 +02:00
|
|
|
rxBus.send(EventRefreshOverview("suspend_menu"))
|
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return true
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-26 17:40:16 +01:00
|
|
|
return false
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun show(manager: FragmentManager, tag: String?) {
|
|
|
|
try {
|
|
|
|
manager.beginTransaction().let {
|
|
|
|
it.add(this, tag)
|
|
|
|
it.commitAllowingStateLoss()
|
|
|
|
}
|
|
|
|
} catch (e: IllegalStateException) {
|
2021-08-06 00:08:49 +02:00
|
|
|
aapsLogger.debug(e.localizedMessage ?: e.toString())
|
2020-12-25 16:47:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|