LoopFragment -> jetpack
This commit is contained in:
parent
ec281c24d2
commit
1294642feb
2 changed files with 541 additions and 534 deletions
|
@ -6,6 +6,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.databinding.LoopFragmentBinding
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
|
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
|
||||||
|
@ -19,7 +20,6 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.loop_fragment.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LoopFragment : DaggerFragment() {
|
class LoopFragment : DaggerFragment() {
|
||||||
|
@ -33,16 +33,23 @@ class LoopFragment : DaggerFragment() {
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
private var _binding: LoopFragmentBinding? = null
|
||||||
|
|
||||||
|
// This property is only valid between onCreateView and
|
||||||
|
// onDestroyView.
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?): View? {
|
savedInstanceState: Bundle?): View {
|
||||||
return inflater.inflate(R.layout.loop_fragment, container, false)
|
_binding = LoopFragmentBinding.inflate(inflater, container, false)
|
||||||
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
loop_run.setOnClickListener {
|
binding.run.setOnClickListener {
|
||||||
loop_lastrun.text = resourceHelper.gs(R.string.executing)
|
binding.lastrun.text = resourceHelper.gs(R.string.executing)
|
||||||
Thread { loopPlugin.invoke("Loop button", true) }.start()
|
Thread { loopPlugin.invoke("Loop button", true) }.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +69,7 @@ class LoopFragment : DaggerFragment() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({
|
.subscribe({
|
||||||
clearGUI()
|
clearGUI()
|
||||||
loop_lastrun?.text = it.text
|
binding.lastrun.text = it.text
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
|
|
||||||
updateGUI()
|
updateGUI()
|
||||||
|
@ -76,22 +83,28 @@ class LoopFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun updateGUI() {
|
override fun onDestroyView() {
|
||||||
if (loop_request == null) return
|
super.onDestroyView()
|
||||||
loopPlugin.lastRun?.let {
|
_binding = null
|
||||||
loop_request?.text = it.request?.toSpanned() ?: ""
|
}
|
||||||
loop_constraintsprocessed?.text = it.constraintsProcessed?.toSpanned() ?: ""
|
|
||||||
loop_source?.text = it.source ?: ""
|
|
||||||
loop_lastrun?.text = dateUtil.dateAndTimeString(it.lastAPSRun)
|
|
||||||
?: ""
|
|
||||||
loop_smbrequest_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBRequest)
|
|
||||||
loop_smbexecution_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBEnact)
|
|
||||||
loop_tbrrequest_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBRRequest)
|
|
||||||
loop_tbrexecution_time?.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBREnact)
|
|
||||||
|
|
||||||
loop_tbrsetbypump?.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) }
|
@Synchronized
|
||||||
|
fun updateGUI() {
|
||||||
|
if (_binding == null) return
|
||||||
|
loopPlugin.lastRun?.let {
|
||||||
|
binding.request.text = it.request?.toSpanned() ?: ""
|
||||||
|
binding.constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: ""
|
||||||
|
binding.source.text = it.source ?: ""
|
||||||
|
binding.lastrun.text = dateUtil.dateAndTimeString(it.lastAPSRun)
|
||||||
?: ""
|
?: ""
|
||||||
loop_smbsetbypump?.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) }
|
binding.smbrequestTime.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBRequest)
|
||||||
|
binding.smbexecutionTime.text = dateUtil.dateAndTimeAndSecondsString(it.lastSMBEnact)
|
||||||
|
binding.tbrrequestTime.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBRRequest)
|
||||||
|
binding.tbrexecutionTime.text = dateUtil.dateAndTimeAndSecondsString(it.lastTBREnact)
|
||||||
|
|
||||||
|
binding.tbrsetbypump.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) }
|
||||||
|
?: ""
|
||||||
|
binding.smbsetbypump.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) }
|
||||||
?: ""
|
?: ""
|
||||||
|
|
||||||
val constraints =
|
val constraints =
|
||||||
|
@ -101,22 +114,22 @@ class LoopFragment : DaggerFragment() {
|
||||||
constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) }
|
constraintsProcessed.smbConstraint?.let { smbConstraint -> allConstraints.copyReasons(smbConstraint) }
|
||||||
allConstraints.getMostLimitedReasons(aapsLogger)
|
allConstraints.getMostLimitedReasons(aapsLogger)
|
||||||
} ?: ""
|
} ?: ""
|
||||||
loop_constraints?.text = constraints
|
binding.constraints.text = constraints
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun clearGUI() {
|
private fun clearGUI() {
|
||||||
loop_request?.text = ""
|
binding.request.text = ""
|
||||||
loop_constraints?.text = ""
|
binding.constraints.text = ""
|
||||||
loop_constraintsprocessed?.text = ""
|
binding.constraintsprocessed.text = ""
|
||||||
loop_source?.text = ""
|
binding.source.text = ""
|
||||||
loop_lastrun?.text = ""
|
binding.lastrun.text = ""
|
||||||
loop_smbrequest_time?.text = ""
|
binding.smbrequestTime.text = ""
|
||||||
loop_smbexecution_time?.text = ""
|
binding.smbexecutionTime.text = ""
|
||||||
loop_tbrrequest_time?.text = ""
|
binding.tbrrequestTime.text = ""
|
||||||
loop_tbrexecution_time?.text = ""
|
binding.tbrexecutionTime.text = ""
|
||||||
loop_tbrsetbypump?.text = ""
|
binding.tbrsetbypump.text = ""
|
||||||
loop_smbsetbypump?.text = ""
|
binding.smbsetbypump.text = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue