Fragments cleanup & Synchonized updateGui

This commit is contained in:
Milos Kozak 2019-08-26 16:15:16 +02:00
parent b04641e466
commit 1eff4697fa
10 changed files with 75 additions and 32 deletions

View file

@ -36,10 +36,9 @@ class LoopFragment : Fragment() {
loop_lastrun.text = MainApp.gs(R.string.executing)
Thread { LoopPlugin.getPlugin().invoke("Loop button", true) }.start()
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
disposable += RxBus
@ -60,14 +59,19 @@ class LoopFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
})
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
fun updateGUI() {
if (loop_request == null) return
LoopPlugin.lastRun?.let {
loop_request.text = it.request?.toSpanned() ?: ""
loop_constraintsprocessed.text = it.constraintsProcessed?.toSpanned() ?: ""
@ -92,7 +96,9 @@ class LoopFragment : Fragment() {
}
}
@Synchronized
private fun clearGUI() {
if (loop_request == null) return
loop_request.text = ""
loop_constraints.text = ""
loop_constraintsprocessed.text = ""

View file

@ -38,10 +38,9 @@ class OpenAPSAMAFragment : Fragment() {
openapsma_run.setOnClickListener {
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false)
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
@ -61,14 +60,19 @@ class OpenAPSAMAFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
})
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
private fun updateGUI() {
if (openapsma_result == null) return
OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned()

View file

@ -35,9 +35,9 @@ class OpenAPSMAFragment : Fragment() {
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false)
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
@ -57,14 +57,18 @@ class OpenAPSMAFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
})
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
fun updateGUI() {
@Synchronized
private fun updateGUI() {
if (openapsma_result == null) return
OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned()
@ -81,7 +85,9 @@ class OpenAPSMAFragment : Fragment() {
}
}
@Synchronized
private fun updateResultGUI(text: String) {
if (openapsma_result == null) return
openapsma_result.text = text
openapsma_glucosestatus.text = ""
openapsma_currenttemp.text = ""

View file

@ -39,10 +39,9 @@ class OpenAPSSMBFragment : Fragment() {
openapsma_run.setOnClickListener {
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false)
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
disposable += RxBus
@ -61,14 +60,19 @@ class OpenAPSSMBFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
})
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
fun updateGUI() {
if (openapsma_result == null) return
val plugin = OpenAPSSMBPlugin.getPlugin()
plugin.lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
@ -101,7 +105,9 @@ class OpenAPSSMBFragment : Fragment() {
}
}
@Synchronized
private fun updateResultGUI(text: String) {
if (openapsma_result == null) return
openapsma_result.text = text
openapsma_glucosestatus.text = ""
openapsma_currenttemp.text = ""

View file

@ -44,10 +44,9 @@ class ConfigBuilderFragment : Fragment() {
unlock.visibility = View.GONE
}, null)
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
disposable.add(RxBus
@ -58,13 +57,16 @@ class ConfigBuilderFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
}))
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
private fun updateGUI() {
createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE))
createViewsForPlugins(R.string.configbuilder_insulin, R.string.configbuilder_insulin_description, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface::class.java, PluginType.INSULIN))

View file

@ -44,19 +44,14 @@ class AutomationFragment : Fragment() {
}
@Synchronized
override fun onResume() {
super.onResume()
disposable += RxBus
.toObservable(EventAutomationUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
eventListAdapter?.notifyDataSetChanged()
val sb = StringBuilder()
for (l in AutomationPlugin.executionLog) {
sb.append(l)
sb.append("\n")
}
automation_logView.text = sb.toString()
updateGui()
}, {
FabricPrivacy.logException(it)
})
@ -68,11 +63,25 @@ class AutomationFragment : Fragment() {
}, {
FabricPrivacy.logException(it)
})
updateGui()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
private fun updateGui() {
if (eventListAdapter == null) return
eventListAdapter?.notifyDataSetChanged()
val sb = StringBuilder()
for (l in AutomationPlugin.executionLog) {
sb.append(l)
sb.append("\n")
}
automation_logView.text = sb.toString()
}
}

View file

@ -34,6 +34,7 @@ class TidepoolFragment : Fragment() {
tidepool_resertstart.setOnClickListener { SP.putLong(R.string.key_tidepool_last_end, 0) }
}
@Synchronized
override fun onResume() {
super.onResume()
disposable.add(RxBus
@ -41,16 +42,17 @@ class TidepoolFragment : Fragment() {
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
TidepoolPlugin.updateLog()
tidepool_log.text = TidepoolPlugin.textLog
tidepool_status.text = TidepoolUploader.connectionStatus.name
tidepool_log.text = TidepoolPlugin.textLog
tidepool_logscrollview.fullScroll(ScrollView.FOCUS_DOWN)
tidepool_log?.text = TidepoolPlugin.textLog
tidepool_status?.text = TidepoolUploader.connectionStatus.name
tidepool_log?.text = TidepoolPlugin.textLog
tidepool_logscrollview?.fullScroll(ScrollView.FOCUS_DOWN)
}, {
FabricPrivacy.logException(it)
})
)
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()

View file

@ -90,9 +90,9 @@ class NSProfileFragment : Fragment() {
}
}
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
disposable.add(RxBus
@ -104,14 +104,18 @@ class NSProfileFragment : Fragment() {
FabricPrivacy.logException(it)
})
)
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
}
@Synchronized
fun updateGUI() {
if (profileview_noprofile == null) return
profileview_noprofile.visibility = View.VISIBLE
NSProfilePlugin.getPlugin().profile?.let { profileStore ->

View file

@ -76,9 +76,9 @@ class DanaRFragment : Fragment() {
DanaRPump.getInstance().lastConnection = 0
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked connect to pump", null)
}
updateGUI()
}
@Synchronized
override fun onResume() {
super.onResume()
MainApp.bus().register(this)
@ -87,8 +87,10 @@ class DanaRFragment : Fragment() {
.toObservable(EventDanaRNewStatus::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
updateGUI()
}
@Synchronized
override fun onPause() {
super.onPause()
disposable.clear()
@ -97,12 +99,12 @@ class DanaRFragment : Fragment() {
}
@Subscribe
public fun onStatusEvent(c: EventPumpStatusChanged) {
fun onStatusEvent(c: EventPumpStatusChanged) {
activity?.runOnUiThread {
when {
c.sStatus == EventPumpStatusChanged.CONNECTING -> danar_btconnection.text = "{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"
c.sStatus == EventPumpStatusChanged.CONNECTED -> danar_btconnection.text = "{fa-bluetooth}"
c.sStatus == EventPumpStatusChanged.DISCONNECTED -> danar_btconnection.text = "{fa-bluetooth-b}"
c.sStatus == EventPumpStatusChanged.CONNECTING -> danar_btconnection?.text = "{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"
c.sStatus == EventPumpStatusChanged.CONNECTED -> danar_btconnection?.text = "{fa-bluetooth}"
c.sStatus == EventPumpStatusChanged.DISCONNECTED -> danar_btconnection?.text = "{fa-bluetooth-b}"
}
if (c.textStatus() != "") {
dana_pumpstatus.text = c.textStatus()
@ -115,20 +117,22 @@ class DanaRFragment : Fragment() {
}
@Subscribe
public fun onStatusEvent(s: EventTempBasalChange) =
fun onStatusEvent(s: EventTempBasalChange) =
activity?.runOnUiThread { updateGUI() }
@Subscribe
public fun onStatusEvent(s: EventExtendedBolusChange) =
fun onStatusEvent(s: EventExtendedBolusChange) =
activity?.runOnUiThread { updateGUI() }
@Subscribe
public fun onStatusEvent(s: EventQueueChanged) =
fun onStatusEvent(s: EventQueueChanged) =
activity?.runOnUiThread { updateGUI() }
// GUI functions
@Synchronized
internal fun updateGUI() {
if (danar_dailyunits == null) return
val pump = DanaRPump.getInstance()
val plugin: PumpInterface = ConfigBuilderPlugin.getPlugin().activePump ?: return
if (pump.lastConnection != 0L) {

View file

@ -99,8 +99,6 @@ class MedtronicFragment : Fragment() {
MedtronicUtil.displayNotConfiguredDialog(context)
}
}
updateGUI()
}
@Synchronized
@ -133,6 +131,8 @@ class MedtronicFragment : Fragment() {
MedtronicUtil.getPumpStatus().verifyConfiguration()
updateGUI()
}, { FabricPrivacy.logException(it) })
updateGUI()
}
@Synchronized