fix Fragment Rx lifecycle
This commit is contained in:
parent
858759873a
commit
20859e9662
|
@ -41,6 +41,11 @@ class LoopFragment : Fragment() {
|
|||
Thread { LoopPlugin.getPlugin().invoke("Loop button", true) }.start()
|
||||
}
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable += RxBus
|
||||
.toObservable(EventLoopUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -59,11 +64,10 @@ class LoopFragment : Fragment() {
|
|||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,10 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
}
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
|
@ -63,6 +67,11 @@ class OpenAPSAMAFragment : Fragment() {
|
|||
})
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
private fun updateGUI() {
|
||||
OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
|
||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
||||
|
|
|
@ -40,6 +40,10 @@ class OpenAPSMAFragment : Fragment() {
|
|||
}
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
|
@ -59,6 +63,11 @@ class OpenAPSMAFragment : Fragment() {
|
|||
})
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
fun updateGUI() {
|
||||
OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
|
||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
||||
|
|
|
@ -44,7 +44,10 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
}
|
||||
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable += RxBus
|
||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -63,6 +66,11 @@ class OpenAPSSMBFragment : Fragment() {
|
|||
})
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
fun updateGUI() {
|
||||
val plugin = OpenAPSSMBPlugin.getPlugin()
|
||||
plugin.lastAPSResult?.let { lastAPSResult ->
|
||||
|
|
|
@ -45,8 +45,11 @@ class ConfigBuilderFragment : Fragment() {
|
|||
}, null)
|
||||
}
|
||||
|
||||
createViews()
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventConfigBuilderUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -57,7 +60,12 @@ class ConfigBuilderFragment : Fragment() {
|
|||
}))
|
||||
}
|
||||
|
||||
private fun createViews() {
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
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))
|
||||
createViewsForPlugins(R.string.configbuilder_bgsource, R.string.configbuilder_bgsource_description, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface::class.java, PluginType.BGSOURCE))
|
||||
|
|
|
@ -46,6 +46,10 @@ class AutomationFragment : Fragment() {
|
|||
fragmentManager?.let { dialog.show(it, "EditEventDialog") }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable += RxBus
|
||||
.toObservable(EventAutomationUpdateGui::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -70,8 +74,8 @@ class AutomationFragment : Fragment() {
|
|||
})
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,10 @@ class TidepoolFragment : Fragment() {
|
|||
tidepool_uploadnow.setOnClickListener { RxBus.send(EventTidepoolDoUpload()) }
|
||||
tidepool_removeall.setOnClickListener { RxBus.send(EventTidepoolResetData()) }
|
||||
tidepool_resertstart.setOnClickListener { SP.putLong(R.string.key_tidepool_last_end, 0) }
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventTidepoolUpdateGUI::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -53,8 +56,8 @@ class TidepoolFragment : Fragment() {
|
|||
)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ class NSProfileFragment : Fragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
close.visibility = View.GONE // not needed for fragment
|
||||
updateGUI()
|
||||
|
||||
nsprofile_profileswitch.setOnClickListener {
|
||||
val name = nsprofile_spinner.selectedItem?.toString() ?: ""
|
||||
|
@ -91,7 +90,11 @@ class NSProfileFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
}
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable.add(RxBus
|
||||
.toObservable(EventNSProfileUpdateGUI::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -103,6 +106,11 @@ class NSProfileFragment : Fragment() {
|
|||
)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
fun updateGUI() {
|
||||
profileview_noprofile.visibility = View.VISIBLE
|
||||
|
||||
|
|
|
@ -84,29 +84,24 @@ class DanaRFragment : Fragment() {
|
|||
DanaRPump.getInstance().lastConnection = 0
|
||||
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked connect to pump", null)
|
||||
}
|
||||
|
||||
disposable += RxBus
|
||||
.toObservable(EventDanaRNewStatus::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
MainApp.bus().unregister(this)
|
||||
loopHandler.removeCallbacks(refreshLoop)
|
||||
updateGUI()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
MainApp.bus().register(this)
|
||||
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||
activity?.runOnUiThread { updateGUI() }
|
||||
disposable += RxBus
|
||||
.toObservable(EventDanaRNewStatus::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
MainApp.bus().unregister(this)
|
||||
loopHandler.removeCallbacks(refreshLoop)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
Loading…
Reference in a new issue