diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt index b7549fcfed..e7dbacb891 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopFragment.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.plugins.aps.loop - import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -12,7 +11,11 @@ import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.utils.* +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.HtmlHelper +import info.nightscout.androidaps.utils.SP +import info.nightscout.androidaps.utils.plusAssign import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.loop_fragment.* @@ -39,23 +42,21 @@ class LoopFragment : Fragment() { override fun onResume() { super.onResume() disposable += RxBus - .toObservable(EventLoopUpdateGui::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ - updateGUI() - }, { - FabricPrivacy.logException(it) - }) + .toObservable(EventLoopUpdateGui::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + updateGUI() + }, { + FabricPrivacy.logException(it) + }) disposable += RxBus - .toObservable(EventLoopSetLastRunGui::class.java) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ - clearGUI() - loop_lastrun.text = it.text - }, { - FabricPrivacy.logException(it) - }) + .toObservable(EventLoopSetLastRunGui::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + clearGUI() + loop_lastrun?.text = it.text + }, { FabricPrivacy.logException(it) }) updateGUI() SP.putBoolean(R.string.key_objectiveuseloop, true) @@ -71,39 +72,38 @@ class LoopFragment : Fragment() { fun updateGUI() { if (loop_request == null) return LoopPlugin.lastRun?.let { - loop_request.text = it.request?.toSpanned() ?: "" - loop_constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: "" - loop_source.text = it.source ?: "" - loop_lastrun.text = it.lastAPSRun?.let { lastRun -> DateUtil.dateAndTimeString(lastRun.time) } - ?: "" - loop_lastenact.text = it.lastAPSRun?.let { lastEnact -> DateUtil.dateAndTimeString(lastEnact.time) } - ?: "" - loop_tbrsetbypump.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) } - ?: "" - loop_smbsetbypump.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) } - ?: "" + loop_request?.text = it.request?.toSpanned() ?: "" + loop_constraintsprocessed?.text = it.constraintsProcessed?.toSpanned() ?: "" + loop_source?.text = it.source ?: "" + loop_lastrun?.text = it.lastAPSRun?.let { lastRun -> DateUtil.dateAndTimeString(lastRun.time) } + ?: "" + loop_lastenact?.text = it.lastAPSRun?.let { lastEnact -> DateUtil.dateAndTimeString(lastEnact.time) } + ?: "" + loop_tbrsetbypump?.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) } + ?: "" + loop_smbsetbypump?.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) } + ?: "" val constraints = - it.constraintsProcessed?.let { constraintsProcessed -> - val allConstraints = Constraint(0.0) - constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) } - constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) } - allConstraints.mostLimitedReasons - } ?: "" - loop_constraints.text = constraints + it.constraintsProcessed?.let { constraintsProcessed -> + val allConstraints = Constraint(0.0) + constraintsProcessed.rateConstraint?.let { rateConstraint -> allConstraints.copyReasons(rateConstraint) } + constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) } + allConstraints.mostLimitedReasons + } ?: "" + loop_constraints?.text = constraints } } @Synchronized private fun clearGUI() { - if (loop_request == null) return - loop_request.text = "" - loop_constraints.text = "" - loop_constraintsprocessed.text = "" - loop_source.text = "" - loop_lastrun.text = "" - loop_lastenact.text = "" - loop_tbrsetbypump.text = "" - loop_smbsetbypump.text = "" + loop_request?.text = "" + loop_constraints?.text = "" + loop_constraintsprocessed?.text = "" + loop_source?.text = "" + loop_lastrun?.text = "" + loop_lastenact?.text = "" + loop_tbrsetbypump?.text = "" + loop_smbsetbypump?.text = "" } }