code style

This commit is contained in:
Milos Kozak 2020-12-28 12:21:31 +01:00
parent ce8fbc5580
commit b2047b7810
4 changed files with 92 additions and 74 deletions

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper 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
@ -53,6 +54,7 @@ class LoopDialog : DaggerDialogFragment() {
private var showOkCancel: Boolean = true private var showOkCancel: Boolean = true
private var _binding: DialogLoopBinding? = null private var _binding: DialogLoopBinding? = null
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
@ -68,7 +70,7 @@ class LoopDialog : DaggerDialogFragment() {
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View {
// load data from bundle // load data from bundle
(savedInstanceState ?: arguments)?.let { bundle -> (savedInstanceState ?: arguments)?.let { bundle ->
showOkCancel = bundle.getInt("showOkCancel", 1) == 1 showOkCancel = bundle.getInt("showOkCancel", 1) == 1
@ -85,22 +87,22 @@ class LoopDialog : DaggerDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
updateGUI("LoopDialogOnViewCreated") updateGUI("LoopDialogOnViewCreated")
binding.overviewCloseloop.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewCloseloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewLgsloop.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewLgsloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewOpenloop.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewOpenloop.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisable.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisable.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewEnable.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewEnable.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewResume.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewResume.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewReconnect.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewReconnect.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewSuspend1h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewSuspend1h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewSuspend2h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewSuspend2h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewSuspend3h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewSuspend3h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewSuspend10h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewSuspend10h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisconnect15m.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisconnect15m.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisconnect30m.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisconnect30m.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisconnect1h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisconnect1h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisconnect2h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisconnect2h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
binding.overviewDisconnect3h.setOnClickListener { if(showOkCancel) onClick_OkCancelEnabled(it) else onClick(it); dismiss() } binding.overviewDisconnect3h.setOnClickListener { if (showOkCancel) onClickOkCancelEnabled(it) else onClick(it); dismiss() }
// cancel button // cancel button
binding.cancel.setOnClickListener { dismiss() } binding.cancel.setOnClickListener { dismiss() }
@ -111,37 +113,47 @@ class LoopDialog : DaggerDialogFragment() {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
activity?.runOnUiThread { updateGUI("EventNewOpenLoopNotification") } activity?.runOnUiThread { updateGUI("EventNewOpenLoopNotification") }
}, { fabricPrivacy.logException(it) }) }, fabricPrivacy::logException)
) )
} }
@Synchronized
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
disposable.clear() disposable.clear()
_binding = null
} }
@Synchronized
fun updateGUI(from: String) { fun updateGUI(from: String) {
if (_binding == null) return
aapsLogger.debug("UpdateGUI from $from") aapsLogger.debug("UpdateGUI from $from")
val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription val pumpDescription: PumpDescription = activePlugin.activePump.pumpDescription
val closedLoopAllowed = objectivesPlugin.isClosedLoopAllowed(Constraint(true)) val closedLoopAllowed = objectivesPlugin.isClosedLoopAllowed(Constraint(true))
val lgsEnabled = objectivesPlugin.isLgsAllowed(Constraint(true)) val lgsEnabled = objectivesPlugin.isLgsAllowed(Constraint(true))
var APSmode = sp.getString(R.string.key_aps_mode, "open") val apsMode = sp.getString(R.string.key_aps_mode, "open")
if (profileFunction.isProfileValid("LoopDialogUpdateGUI")) { if (profileFunction.isProfileValid("LoopDialogUpdateGUI")) {
if (loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (closedLoopAllowed.value()) { when {
binding.overviewCloseloop.visibility = if (APSmode == "closed") View.GONE else View.VISIBLE closedLoopAllowed.value() -> {
binding.overviewLgsloop.visibility = if (APSmode == "lgs") View.GONE else View.VISIBLE binding.overviewCloseloop.visibility = (apsMode != "closed").toVisibility()
binding.overviewOpenloop.visibility = if (APSmode == "open") View.GONE else View.VISIBLE binding.overviewLgsloop.visibility = (apsMode != "lgs").toVisibility()
} else if (lgsEnabled.value() ) { binding.overviewOpenloop.visibility = (apsMode != "open").toVisibility()
}
lgsEnabled.value() -> {
binding.overviewCloseloop.visibility = View.GONE binding.overviewCloseloop.visibility = View.GONE
binding.overviewLgsloop.visibility = if (APSmode == "lgs") View.GONE else View.VISIBLE binding.overviewLgsloop.visibility = (apsMode != "lgs").toVisibility()
binding.overviewOpenloop.visibility = if (APSmode == "open") View.GONE else View.VISIBLE binding.overviewOpenloop.visibility = (apsMode != "open").toVisibility()
} else { }
else -> {
binding.overviewCloseloop.visibility = View.GONE binding.overviewCloseloop.visibility = View.GONE
binding.overviewLgsloop.visibility = View.GONE binding.overviewLgsloop.visibility = View.GONE
binding.overviewOpenloop.visibility = View.GONE binding.overviewOpenloop.visibility = View.GONE
} }
binding.overviewEnable.visibility = View.GONE //sp.getBoolean(R.string.key_usesuperbolus, false).toVisibility() }
binding.overviewEnable.visibility = View.GONE
binding.overviewDisable.visibility = View.VISIBLE binding.overviewDisable.visibility = View.VISIBLE
if (!loopPlugin.isSuspended) { if (!loopPlugin.isSuspended) {
binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.suspendloop) binding.overviewSuspendHeader.text = resourceHelper.gs(R.string.suspendloop)
@ -164,8 +176,8 @@ class LoopDialog : DaggerDialogFragment() {
} }
if (!loopPlugin.isDisconnected) { if (!loopPlugin.isDisconnected) {
binding.overviewPumpHeader.text = resourceHelper.gs(R.string.disconnectpump) binding.overviewPumpHeader.text = resourceHelper.gs(R.string.disconnectpump)
binding.overviewDisconnect15m.visibility = if (pumpDescription.tempDurationStep15mAllowed) View.VISIBLE else View.GONE binding.overviewDisconnect15m.visibility = pumpDescription.tempDurationStep15mAllowed.toVisibility()
binding.overviewDisconnect30m.visibility = if (pumpDescription.tempDurationStep30mAllowed) View.VISIBLE else View.GONE binding.overviewDisconnect30m.visibility = pumpDescription.tempDurationStep30mAllowed.toVisibility()
binding.overviewDisconnectButtons.visibility = View.VISIBLE binding.overviewDisconnectButtons.visibility = View.VISIBLE
binding.overviewReconnect.visibility = View.GONE binding.overviewReconnect.visibility = View.GONE
} else { } else {
@ -185,7 +197,7 @@ class LoopDialog : DaggerDialogFragment() {
} }
fun onClick_OkCancelEnabled(v: View): Boolean { fun onClickOkCancelEnabled(v: View): Boolean {
var description = "" var description = ""
when (v.id) { when (v.id) {
R.id.overview_closeloop -> description = resourceHelper.gs(R.string.closedloop) R.id.overview_closeloop -> description = resourceHelper.gs(R.string.closedloop)
@ -219,15 +231,21 @@ class LoopDialog : DaggerDialogFragment() {
R.id.overview_closeloop -> { R.id.overview_closeloop -> {
sp.putString(R.string.key_aps_mode, "closed") sp.putString(R.string.key_aps_mode, "closed")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.closedloop)))
return true
} }
R.id.overview_lgsloop -> { R.id.overview_lgsloop -> {
sp.putString(R.string.key_aps_mode, "lgs") sp.putString(R.string.key_aps_mode, "lgs")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
return true
} }
R.id.overview_openloop -> { R.id.overview_openloop -> {
sp.putString(R.string.key_aps_mode, "open") sp.putString(R.string.key_aps_mode, "open")
rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend))) rxBus.send(EventPreferenceChange(resourceHelper.gs(R.string.lowglucosesuspend)))
return true
} }
R.id.overview_disable -> { R.id.overview_disable -> {
aapsLogger.debug("USER ENTRY: LOOP DISABLED") aapsLogger.debug("USER ENTRY: LOOP DISABLED")
loopPlugin.setPluginEnabled(PluginType.LOOP, false) loopPlugin.setPluginEnabled(PluginType.LOOP, false)

View file

@ -112,6 +112,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
disposable.clear() disposable.clear()
} }
@Synchronized
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
@ -119,6 +120,7 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
@Synchronized @Synchronized
private fun updateGui() { private fun updateGui() {
if (_binding == null) return
eventListAdapter.notifyDataSetChanged() eventListAdapter.notifyDataSetChanged()
val sb = StringBuilder() val sb = StringBuilder()
for (l in automationPlugin.executionLog.reversed()) for (l in automationPlugin.executionLog.reversed())

View file

@ -92,31 +92,28 @@ class EditEventDialog : DialogFragmentWithDate() {
.subscribe({ .subscribe({
actionListAdapter?.notifyDataSetChanged() actionListAdapter?.notifyDataSetChanged()
showPreconditions() showPreconditions()
}, { fabricPrivacy.logException(it) } }, fabricPrivacy::logException)
)
disposable += rxBus disposable += rxBus
.toObservable(EventAutomationAddAction::class.java) .toObservable(EventAutomationAddAction::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
event.addAction(it.action) event.addAction(it.action)
actionListAdapter?.notifyDataSetChanged() actionListAdapter?.notifyDataSetChanged()
}, { fabricPrivacy.logException(it) } }, fabricPrivacy::logException)
)
disposable += rxBus disposable += rxBus
.toObservable(EventAutomationUpdateTrigger::class.java) .toObservable(EventAutomationUpdateTrigger::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
event.trigger = it.trigger event.trigger = it.trigger
binding.triggerDescription.text = event.trigger.friendlyDescription() binding.triggerDescription.text = event.trigger.friendlyDescription()
}, { fabricPrivacy.logException(it) } }, fabricPrivacy::logException)
)
disposable += rxBus disposable += rxBus
.toObservable(EventAutomationUpdateAction::class.java) .toObservable(EventAutomationUpdateAction::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ .subscribe({
event.actions[it.position] = it.action event.actions[it.position] = it.action
actionListAdapter?.notifyDataSetChanged() actionListAdapter?.notifyDataSetChanged()
}, { fabricPrivacy.logException(it) }) }, fabricPrivacy::logException)
} }
override fun submit(): Boolean { override fun submit(): Boolean {

View file

@ -103,10 +103,10 @@ class DanaFragment : DaggerFragment() {
if (activePlugin.activePump.pumpDescription.pumpType == PumpType.DanaRS) if (activePlugin.activePump.pumpDescription.pumpType == PumpType.DanaRS)
binding.btconnection.setOnLongClickListener { binding.btconnection.setOnLongClickListener {
activity?.let { activity?.let {
OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing), { OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing)) {
aapsLogger.error("USER ENTRY: Clearing pairing keys !!!") aapsLogger.error("USER ENTRY: Clearing pairing keys !!!")
(activePlugin.activePump as DanaPumpInterface).clearPairing() (activePlugin.activePump as DanaPumpInterface).clearPairing()
}) }
} }
true true
} }
@ -119,23 +119,23 @@ class DanaFragment : DaggerFragment() {
disposable += rxBus disposable += rxBus
.toObservable(EventInitializationChanged::class.java) .toObservable(EventInitializationChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(info.nightscout.androidaps.dana.events.EventDanaRNewStatus::class.java) .toObservable(info.nightscout.androidaps.dana.events.EventDanaRNewStatus::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java) .toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventTempBasalChange::class.java) .toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventQueueChanged::class.java) .toObservable(EventQueueChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) }) .subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventPumpStatusChanged::class.java) .toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -157,7 +157,7 @@ class DanaFragment : DaggerFragment() {
} else { } else {
binding.danaPumpstatuslayout.visibility = View.GONE binding.danaPumpstatuslayout.visibility = View.GONE
} }
}, { fabricPrivacy.logException(it) }) }, fabricPrivacy::logException)
updateGUI() updateGUI()
} }
@ -168,14 +168,15 @@ class DanaFragment : DaggerFragment() {
loopHandler.removeCallbacks(refreshLoop) loopHandler.removeCallbacks(refreshLoop)
} }
@Synchronized
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
} }
// GUI functions
@Synchronized @Synchronized
fun updateGUI() { fun updateGUI() {
if (_binding == null) return
val pump = danaPump val pump = danaPump
val plugin: PumpInterface = activePlugin.activePump val plugin: PumpInterface = activePlugin.activePump
if (pump.lastConnection != 0L) { if (pump.lastConnection != 0L) {