It is possible to watch the screen’s current state during server-driven requests in a BeagleActivity, including error states.
To display a server-driven screen, it is possible to overwrite the onServerDrivenContainerStateChange()
method to implement its handles to each screen state.
See below a BeagleActivity example with the overwritten onServerDrivenContainerStateChange()
method:
@BeagleComponent
class AppBeagleActivity : BeagleActivity() {
private val progressBar: ProgressBar by lazy { findViewById<ProgressBar>(R.id.progress_bar) }
private val mToolbar: Toolbar by lazy { findViewById<Toolbar>(R.id.custom_toolbar) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_app_beagle)
}
override fun getServerDrivenContainerId(): Int = R.id.server_driven_container
override fun getToolbar(): Toolbar = mToolbar
override fun onServerDrivenContainerStateChanged(state: ServerDrivenState) {
when (state) {
is ServerDrivenState.Started -> {
progressBar.visibility = View.VISIBLE
}
is ServerDrivenState.Finished -> {
progressBar.visibility = View.GONE
}
is ServerDrivenState.Error -> {
Toast.makeText(this, "Error", Toast.LENGTH_LONG).show()
}
}
}
}
On the loadView
, you can also see that these states shows the loadView implementation, it is possible to define when to show or to hide Load. And you can also define other action to the states ServerDrivenState
, that areStarted
, Success
, Finished
and Error
sealed class ServerDrivenState {
object Started : ServerDrivenState()
object Finished : ServerDrivenState()
object Success : ServerDrivenState()
open class Error(
val throwable: Throwable,
val retry: BeagleRetry
) : ServerDrivenState()
}
See more details about each state:
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.